[xiph-cvs] cvs commit: vorbis-tools/oggenc oggenc.c

Michael Smith msmith at xiph.org
Tue Nov 7 03:56:26 PST 2000



msmith      00/11/07 03:56:26

  Modified:    oggenc   oggenc.c
  Log:
  Don't open output file until we're sure we can read the input file (prevents
  creation of 0-length output files in error cases).

Revision  Changes    Path
1.6       +30 -27    vorbis-tools/oggenc/oggenc.c

Index: oggenc.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/oggenc/oggenc.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- oggenc.c	2000/11/05 13:38:38	1.5
+++ oggenc.c	2000/11/07 11:56:26	1.6
@@ -146,6 +146,36 @@
                         closein = 1;
                 }
 
+		/* Now, we need to select an input audio format - we do this before opening
+		   the output file so that we don't end up with a 0-byte file if the input
+		   file can't be read */
+
+		if(opt.rawmode)
+		{
+			raw_open(in, &enc_opts);
+			foundformat=1;
+		}
+		else
+		{
+			while(formats[j].open_func)
+			{
+				if(formats[j].open_func(in, &enc_opts))
+				{
+					foundformat = 1;
+					break;
+				}
+				j++;
+			}
+		}
+
+		if(!foundformat)
+		{
+			fprintf(stderr, "ERROR: Input file \"%s\" is not a supported format\n", infiles[i]);
+			continue;
+		}
+
+		/* Ok. We can read the file - so now open the output file */
+
                 if(opt.outfile && !strcmp(opt.outfile, "-"))
                 {
                         setbinmode(stdout);
@@ -200,33 +230,6 @@
                 enc_opts.comments = &vc;
                 enc_opts.filename = out_fn;
                 enc_opts.bitrate = opt.kbps; /* defaulted at the start, so this is ok */
-
-		/* Now, we need to select an input audio format */
-
-		if(opt.rawmode)
-		{
-			raw_open(in, &enc_opts);
-			foundformat=1;
-		}
-		else
-		{
-			while(formats[j].open_func)
-			{
-				if(formats[j].open_func(in, &enc_opts))
-				{
-					foundformat = 1;
-					break;
-				}
-				j++;
-			}
-		}
-
-		if(!foundformat)
-		{
-			fprintf(stderr, "ERROR: Input file \"%s\" is not a supported format\n", infiles[i]);
-			free(out_fn);
-			continue;
-		}
 
                 if(!enc_opts.total_samples_per_channel)
                         enc_opts.progress_update = update_statistics_notime;

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list