summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorNick White <git@njw.me.uk>2011-11-30 18:55:47 +0000
committerNick White <git@njw.me.uk>2011-11-30 18:55:47 +0000
commit750f41033d1e8eb0a0c6ba4401e685b378ac3ae6 (patch)
treed4b8204055524e91cd852d9673d77eccdc406975 /util.c
parent83adb758f73ebc6a6c09b7dee82e139317b7ad0a (diff)
Use appropriate file extensions when saving
Diffstat (limited to 'util.c')
-rw-r--r--util.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/util.c b/util.c
index b1f4c69..b7502f2 100644
--- a/util.c
+++ b/util.c
@@ -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;
+}