diff options
author | Daniel Friesel <derf@derf.homelinux.org> | 2010-03-15 17:58:18 +0100 |
---|---|---|
committer | Daniel Friesel <derf@derf.homelinux.org> | 2010-03-15 17:58:18 +0100 |
commit | ced2edbd4ed42395f719ea2cf8f98e070592f6ab (patch) | |
tree | bb3ce458fc67213f20c0ad6887bb79145eb16030 /src | |
parent | 4bf70b6101f969e2c996afd2e64e272224b6b3b4 (diff) |
lossless rotate: Use execlp instead of system for jpegtran
Diffstat (limited to 'src')
-rw-r--r-- | src/imlib.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/imlib.c b/src/imlib.c index acdbc4f..00aa6e5 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -966,24 +966,34 @@ gib_list *feh_wrap_string(char *text, int wrap_width, int max_height, Imlib_Font void feh_edit_inplace_lossless_rotate(winwidget w, int orientation) { char *filename = FEH_FILE(w->file->data)->filename; - int len = 44 + (strlen(filename) * 2); - char *command = emalloc(len); + char rotate_str[4]; + int len = strlen(filename) + 1; + char *file_str = emalloc(len); int rotatearg = 90 * orientation; - int status; + int pid, status; - snprintf(command, len, "jpegtran -copy all -rotate %d -outfile %s %s", - rotatearg, filename, filename); + snprintf(rotate_str, 4, "%d", rotatearg); + snprintf(file_str, len, "%s", filename); - D(3, ("lossless_rotate: executing: %s", command)); + if ((pid = fork()) < 0) { + weprintf("lossless rotate: fork failed:"); + D_RETURN_(4); + } else if (pid == 0) { - status = system(command); + execlp("jpegtran", "jpegtran", "-copy", "all", "-rotate", + rotate_str, "-outfile", file_str, file_str, NULL); - if (status == -1) - weprintf("lossless rotate failed: system() failed\n"); - else if (status > 0) { - weprintf("lossless rotate failed: Got return status %d from jpegtran\n", - WEXITSTATUS(status)); - weprintf("Commandline was: %s", command); + eprintf("lossless rotate: exec failed: jpegtran:"); + } else { + waitpid(pid, &status, 0); + + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { + weprintf("lossless rotate: Got exitcode %d from jpegtran." + " Commandline was:\n" + "jpegtran -copy all -rotate %d -outfile %s %s\n", + status >> 8, rotate_str, file_str, file_str); + D_RETURN_(4); + } } } |