diff options
author | Nick White <git@njw.me.uk> | 2011-11-30 18:55:47 +0000 |
---|---|---|
committer | Nick White <git@njw.me.uk> | 2011-11-30 18:55:47 +0000 |
commit | 750f41033d1e8eb0a0c6ba4401e685b378ac3ae6 (patch) | |
tree | d4b8204055524e91cd852d9673d77eccdc406975 /util.c | |
parent | 83adb758f73ebc6a6c09b7dee82e139317b7ad0a (diff) |
Use appropriate file extensions when saving
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -161,3 +161,27 @@ int post(char *host, char *path, char *data, char **buf) { return l; } + +int renameifjpg(char *path) { + FILE *f; + char *newpath, *c; + + if((f = fopen(path, "rb")) == NULL) + return 1; + + if(fgetc(f) == 255) { + if((newpath = malloc(strlen(path) + 1)) == NULL) + return 1; + strncpy(newpath, path, strlen(path)); + c = strrchr(newpath, '.'); + strncpy(c+1, "jpg\0", 4); + + if(rename(path, newpath)) + return 1; + free(newpath); + } + + fclose(f); + + return 0; +} |