summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
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;
+}