diff options
author | Brian Paul <brian.paul@tungstengraphics.com> | 2003-02-04 12:33:37 +0000 |
---|---|---|
committer | Brian Paul <brian.paul@tungstengraphics.com> | 2003-02-04 12:33:37 +0000 |
commit | 8fee42cd6fada88f20c68bf98429308f4552f698 (patch) | |
tree | d26ab4cc9e00cb0c06291471b67173e935a9ce33 | |
parent | 34af895a99674b351844f14eea98f936284019a4 (diff) |
read/write files, not stdio (Daniel Borca)
-rw-r--r-- | progs/samples/rgbtoppm.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/progs/samples/rgbtoppm.c b/progs/samples/rgbtoppm.c index 0bc73487b0..116d9a8cfa 100644 --- a/progs/samples/rgbtoppm.c +++ b/progs/samples/rgbtoppm.c @@ -256,18 +256,30 @@ int main(int argc, char **argv) { int width, height; GLubyte *data; + char buff[32]; + int n; + FILE *fo; - if (argc != 2) + if (argc != 3) { - fprintf(stderr, "usage: %s <filename>\n", argv[0]); + fprintf(stderr, "usage: %s <infile.rgb> <outfile.p6>\n", argv[0]); return 1; } data = read_rgb_texture(argv[1], &width, &height); - printf("P6\n%d %d\n255\n", width, height); - fwrite(data, width * 3, height, stdout); + n = sprintf(buff, "P6\n%d %d\n255\n", width, height); + + /* [dBorca] avoid LF to CRLF conversion */ + if ((fo = fopen(argv[2], "wb")) == NULL) { + fprintf(stderr, "Cannot open output file!\n"); + exit(1); + } + + fwrite(buff, n, 1, fo); + fwrite(data, width * 3, height, fo); + + fclose(fo); return 0; } - |