summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@derf.homelinux.org>2010-03-15 17:58:18 +0100
committerDaniel Friesel <derf@derf.homelinux.org>2010-03-15 17:58:18 +0100
commitced2edbd4ed42395f719ea2cf8f98e070592f6ab (patch)
treebb3ce458fc67213f20c0ad6887bb79145eb16030
parent4bf70b6101f969e2c996afd2e64e272224b6b3b4 (diff)
lossless rotate: Use execlp instead of system for jpegtran
-rw-r--r--ChangeLog1
-rw-r--r--src/imlib.c36
2 files changed, 24 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 29daa9b..6a0b884 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@ Git head
* Fix chrome theme in the default .fehrc
* Rename cam to feh-cam and gen_cam_menu.sh to gen-cam-menu
* Add manual for feh-cam und gen-cam-menu (from Debian)
+ * Fix lossless rotate for filenames with weird characters
Thu Mar 4 14:55:02 CET 2010 Daniel Friesel <derf@chaosdorf.de>
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);
+ }
}
}