RosettaCodeData/Task/Bitmap-Read-an-image-through-a-pipe/C/bitmap-read-an-image-through-a-pipe-2.c
2023-07-01 13:44:08 -04:00

28 lines
634 B
C

#include "imglib.h"
#define MAXCMDBUF 100
#define MAXFILENAMELEN 256
#define MAXFULLCMDBUF (MAXCMDBUF + MAXFILENAMELEN)
image read_image(const char *name)
{
FILE *pipe;
char buf[MAXFULLCMDBUF];
image im;
FILE *test = fopen(name, "r");
if ( test == NULL ) {
fprintf(stderr, "cannot open file %s\n", name);
return NULL;
}
fclose(test);
snprintf(buf, MAXFULLCMDBUF, "convert \"%s\" ppm:-", name);
pipe = popen(buf, "r");
if ( pipe != NULL )
{
im = get_ppm(pipe);
pclose(pipe);
return im;
}
return NULL;
}