Browse code

fate: avoid freopen(NULL) in videogen/rotozoom

A number of systems do not implement freopen() with a NULL filename
correctly. This changes these programs to output individual images
if opening a named output argument as a file fails, in this case
assuming it is a directory.

Signed-off-by: Mans Rullgard <mans@mansr.com>

Mans Rullgard authored on 2012/06/07 01:12:29
Showing 3 changed files
... ...
@@ -16,10 +16,10 @@ tests/data/asynth-%.wav: tests/audiogen$(HOSTEXESUF) | tests/data
16 16
 	$(M)./$< $@ $(subst -, ,$*)
17 17
 
18 18
 tests/data/vsynth1.yuv: tests/videogen$(HOSTEXESUF) | tests/data
19
-	$(M)$< >$@
19
+	$(M)$< $@
20 20
 
21 21
 tests/data/vsynth2.yuv: tests/rotozoom$(HOSTEXESUF) | tests/data
22
-	$(M)$< $(SRC_PATH)/tests/lena.pnm >$@
22
+	$(M)$< $(SRC_PATH)/tests/lena.pnm $@
23 23
 
24 24
 tests/data/asynth% tests/data/vsynth%.yuv tests/vsynth%/00.pgm: TAG = GEN
25 25
 
... ...
@@ -158,15 +158,16 @@ int main(int argc, char **argv)
158 158
 {
159 159
     int w, h, i;
160 160
     char buf[1024];
161
+    int isdir = 0;
161 162
 
162
-    if (argc > 3) {
163
-        printf("usage: %s image.pnm [directory/]\n"
163
+    if (argc != 3) {
164
+        printf("usage: %s image.pnm file|dir\n"
164 165
                "generate a test video stream\n", argv[0]);
165 166
         return 1;
166 167
     }
167 168
 
168
-    if (argc < 3)
169
-        err_if(!freopen(NULL, "wb", stdout));
169
+    if (!freopen(argv[2], "wb", stdout))
170
+        isdir = 1;
170 171
 
171 172
     w = DEFAULT_WIDTH;
172 173
     h = DEFAULT_HEIGHT;
... ...
@@ -181,7 +182,7 @@ int main(int argc, char **argv)
181 181
 
182 182
     for (i = 0; i < DEFAULT_NB_PICT; i++) {
183 183
         gen_image(i, w, h);
184
-        if (argc > 2) {
184
+        if (isdir) {
185 185
             snprintf(buf, sizeof(buf), "%s%02d.pgm", argv[2], i);
186 186
             pgmyuv_save(buf, w, h, rgb_tab);
187 187
         } else {
... ...
@@ -145,15 +145,16 @@ int main(int argc, char **argv)
145 145
 {
146 146
     int w, h, i;
147 147
     char buf[1024];
148
+    int isdir = 0;
148 149
 
149
-    if (argc > 2) {
150
-        printf("usage: %s [file]\n"
150
+    if (argc != 2) {
151
+        printf("usage: %s file|dir\n"
151 152
                "generate a test video stream\n", argv[0]);
152 153
         exit(1);
153 154
     }
154 155
 
155
-    if (argc < 2)
156
-        err_if(!freopen(NULL, "wb", stdout));
156
+    if (!freopen(argv[1], "wb", stdout))
157
+        isdir = 1;
157 158
 
158 159
     w = DEFAULT_WIDTH;
159 160
     h = DEFAULT_HEIGHT;
... ...
@@ -165,7 +166,7 @@ int main(int argc, char **argv)
165 165
 
166 166
     for (i = 0; i < DEFAULT_NB_PICT; i++) {
167 167
         gen_image(i, w, h);
168
-        if (argc > 1) {
168
+        if (isdir) {
169 169
             snprintf(buf, sizeof(buf), "%s%02d.pgm", argv[1], i);
170 170
             pgmyuv_save(buf, w, h, rgb_tab);
171 171
         } else {