shithub: libopusenc

Download patch

ref: d4a2911f07a2007df5f6448a52134579640b90cf
parent: 781c80da9c9691c7877208b1a20568aadf82c97c
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Wed May 3 14:41:09 EDT 2017

Implement ope_continue_new_file()

--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -533,9 +533,20 @@
 
 /* Ends the stream and create a new file. */
 int ope_continue_new_file(OggOpusEnc *enc, const char *path) {
-  (void)enc;
-  (void)path;
-  return OPE_UNIMPLEMENTED;
+  int ret;
+  struct StdioObject *obj;
+  if (!(obj = malloc(sizeof(*obj)))) return OPE_INTERNAL_ERROR;
+  obj->file = fopen(path, "wb");
+  if (!obj->file) {
+    free(obj);
+    /* By trying to open the file first, we can recover if we can't open it. */
+    return OPE_CANNOT_OPEN;
+  }
+  ret = ope_continue_new_callbacks(enc, obj);
+  if (ret == OPE_OK) return ret;
+  fclose(obj->file);
+  free(obj);
+  return OPE_INTERNAL_ERROR;
 }
 
 /* Ends the stream and create a new file (callback-based). */