/* gifaddcomment Copyright 2005 Ray Morris Released under GPL. usage: in.gif out.gif "New comment" Compile with: gcc -Wall -o gifaddcomment gifaddcomment.c */ #include #include #include int main(int argc, char **argv) { FILE *file; int c; FILE *out; if (argc < 3) { fprintf(stderr, "usage:\n%s in.gif out.gif \"New comment\"\n\n", argv[0]); exit(EXIT_FAILURE); } file = fopen(argv[1], "r"); if (file == NULL) { perror(*argv); exit(EXIT_FAILURE); } out = fopen(argv[2], "w"); if (file == NULL) { perror(*argv); exit(EXIT_FAILURE); } while ((c = getc(file)) != EOF) { putc(c, out); } fseek(out, -1, SEEK_END); putc(0x21, out); putc(0xFE, out); putc(strlen(argv[3]), out); // size of comment fwrite(argv[3], strlen(argv[3]), 1, out); // 1 is how many putc(0, out); putc(0x3B, out); fclose(file); fclose(out); fflush(stdout); return(EXIT_SUCCESS); }