diff options
author | John Hawthorn <jhawthor@uvic.ca> | 2008-05-19 20:10:06 -0700 |
---|---|---|
committer | John Hawthorn <jhawthor@uvic.ca> | 2008-05-19 20:10:06 -0700 |
commit | 8736618f8890638c8aedca43fa7bfa2f59e88c48 (patch) | |
tree | d2fb0d614c357b956cdfb91447251da20487f373 | |
parent | bfbeab9e9a7446ed6b40c0ad557d631c0d738c6c (diff) | |
download | mirror-meh-8736618f8890638c8aedca43fa7bfa2f59e88c48.tar.gz mirror-meh-8736618f8890638c8aedca43fa7bfa2f59e88c48.tar.bz2 mirror-meh-8736618f8890638c8aedca43fa7bfa2f59e88c48.zip |
more preparations
-rw-r--r-- | src/main.c | 22 |
1 files changed, 13 insertions, 9 deletions
@@ -112,27 +112,31 @@ XImage *create_image_from_buffer(unsigned char *buf, int width, int height, int } unsigned char *loadbuf(const char *filename, int *bufwidth, int *bufheight){ - unsigned char buf[4]; FILE *f; + unsigned char head[4]; + unsigned char *buf; if((f = fopen(filename, "rb")) == NULL){ fprintf(stderr, "Cannot open '%s'\n", filename); return NULL; } - fread(buf, 1, 4, f); + memset(head, 0, 4); + fread(head, 1, 4, f); rewind(f); - if(buf[0] == 0xff && buf[1] == 0xd8){ - return loadjpeg(f, bufwidth, bufheight); - }else if(!memcmp("\x89PNG", buf, 4)){ + if(head[0] == 0xff && head[1] == 0xd8){ + buf = loadjpeg(f, bufwidth, bufheight); + }else if(!memcmp("\x89PNG", head, 4)){ printf("IT'S A PNG!!!\n"); - return NULL; - }else if(!memcmp("GIF", buf, 3)){ + buf = NULL; + }else if(!memcmp("GIF", head, 3)){ printf("IT'S A GIF!!!\n"); - return NULL; + buf = NULL; }else{ fprintf(stderr, "Unknown file type: '%s'\n", filename); - return NULL; + buf = NULL; } + fclose(f); + return buf; } void init(){ |