equal
deleted
inserted
replaced
3 #include "pngtile.h" |
3 #include "pngtile.h" |
4 |
4 |
5 #include <getopt.h> |
5 #include <getopt.h> |
6 #include <string.h> |
6 #include <string.h> |
7 #include <stdio.h> |
7 #include <stdio.h> |
|
8 #include <unistd.h> |
8 #include <stdbool.h> |
9 #include <stdbool.h> |
9 |
10 |
10 /** |
11 /** |
11 * Command-line options |
12 * Command-line options |
12 */ |
13 */ |
261 FILE *out_file; |
262 FILE *out_file; |
262 char tmp_name[] = "pt-tile-XXXXXX"; |
263 char tmp_name[] = "pt-tile-XXXXXX"; |
263 |
264 |
264 if (strcmp(out_path, "-") == 0) { |
265 if (strcmp(out_path, "-") == 0) { |
265 // use stdout |
266 // use stdout |
266 out_file = stdout; |
267 if ((out_file = fdopen(STDOUT_FILENO, "wb")) == NULL) { |
|
268 log_errno("fdopen: STDOUT_FILENO"); |
|
269 goto error; |
|
270 } |
267 |
271 |
268 } else if (false /* tmp */) { |
272 } else if (false /* tmp */) { |
269 int fd; |
273 int fd; |
270 |
274 |
271 // temporary file for output |
275 // temporary file for output |
272 if ((fd = mkstemp(tmp_name)) < 0) { |
276 if ((fd = mkstemp(tmp_name)) < 0) { |
273 log_errno("mkstemp"); |
277 log_errno("mkstemp"); |
274 |
278 goto error; |
275 continue; |
|
276 } |
279 } |
277 |
280 |
278 out_path = tmp_name; |
281 out_path = tmp_name; |
279 |
282 |
280 // open out |
283 // open out |
281 if ((out_file = fdopen(fd, "w")) == NULL) { |
284 if ((out_file = fdopen(fd, "wb")) == NULL) { |
282 log_errno("fdopen"); |
285 log_errno("fdopen"); |
283 |
286 goto error; |
284 continue; |
|
285 } |
287 } |
286 |
288 |
287 } else { |
289 } else { |
288 // use file |
290 // use file |
289 if ((out_file = fopen(out_path, "wb")) == NULL) { |
291 if ((out_file = fopen(out_path, "wb")) == NULL) { |
305 // render |
307 // render |
306 log_info("\tRender tile %zux%zu@(%zu,%zu) -> %s", ti.width, ti.height, ti.x, ti.y, out_path); |
308 log_info("\tRender tile %zux%zu@(%zu,%zu) -> %s", ti.width, ti.height, ti.x, ti.y, out_path); |
307 |
309 |
308 if ((err = pt_image_tile_file(image, &ti, out_file))) |
310 if ((err = pt_image_tile_file(image, &ti, out_file))) |
309 log_errno("pt_image_tile_file: %s: %s", img_path, pt_strerror(err)); |
311 log_errno("pt_image_tile_file: %s: %s", img_path, pt_strerror(err)); |
310 |
312 |
|
313 // cleanup |
|
314 if (fclose(out_file)) |
|
315 log_warn_errno("fclose: out_file"); |
311 } |
316 } |
312 } |
317 } |
313 |
318 |
314 error: |
319 error: |
315 // cleanup |
320 // cleanup |