Commit ced2edbd authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

lossless rotate: Use execlp instead of system for jpegtran

parent 4bf70b61
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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>

+23 −13
Original line number Diff line number Diff line
@@ -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(rotate_str, 4, "%d", rotatearg);
	snprintf(file_str, len, "%s", filename);

	snprintf(command, len, "jpegtran -copy all -rotate %d -outfile %s %s",
			rotatearg, filename, filename);
	if ((pid = fork()) < 0) {
		weprintf("lossless rotate: fork failed:");
		D_RETURN_(4);
	} else if (pid == 0) {

	D(3, ("lossless_rotate: executing: %s", command));
		execlp("jpegtran", "jpegtran", "-copy", "all", "-rotate",
				rotate_str, "-outfile", file_str, file_str, NULL);

	status = system(command);
		eprintf("lossless rotate: exec failed: jpegtran:");
	} else {
		waitpid(pid, &status, 0);

	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);
		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);
		}
	}
}