From 2ce155bd0c6da70fdec714c3b07cffb3b05125ba Mon Sep 17 00:00:00 2001 From: kraxel Date: Mon, 3 Dec 2007 10:06:23 +0000 Subject: kill popen() call --- fbi.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/fbi.c b/fbi.c index 052c5b7..f54a1fb 100644 --- a/fbi.c +++ b/fbi.c @@ -666,11 +666,29 @@ read_image(char *filename) } if (NULL == loader) { /* no loader found, try to use ImageMagick's convert */ - snprintf(command,sizeof(command), - "convert -depth 8 \"%s\" ppm:-",filename); - if (NULL == (fp = popen(command,"r"))) + int p[2]; + + if (0 != pipe(p)) return NULL; - loader = &ppm_loader; + switch (fork()) { + case -1: /* error */ + perror("fork"); + close(p[0]); + close(p[1]); + return(NULL); + case 0: /* child */ + dup2(p[1], 1 /* stdout */); + close(p[0]); + close(p[1]); + execl("convert", "convert", "-depth", "8", filename, "ppm:-", NULL); + exit(1); + default: /* parent */ + close(p[1]); + fp = fdopen(p[0], "r"); + if (NULL == (fp = popen(command,"r"))) + return NULL; + loader = &ppm_loader; + } } /* load image */ -- cgit