diff --git a/src/api.c b/src/api.c index f6d0a7a..03b1c35 100644 --- a/src/api.c +++ b/src/api.c @@ -492,6 +492,7 @@ imlib_free_image_and_decache(void) CHECK_PARAM_POINTER("imlib_free_image_and_decache", "image", ctxt_image); CAST_IMAGE(im, ctxt_image); SET_FLAG(im->flags, F_INVALID); + SET_FLAG(im->flags, F_UNCACHEABLE); __imlib_FreeImage(im); ctxt_image = NULL; } diff --git a/src/image.c b/src/image.c index 2e04af6..c61830b 100644 --- a/src/image.c +++ b/src/image.c @@ -15,22 +15,22 @@ extern char *__XOS2RedirRoot(const char *); #endif -static ImlibImage *images = NULL; -static ImlibImagePixmap *pixmaps = NULL; -static ImlibLoader *loaders = NULL; -static int cache_size = 4096 * 1024; +static ImlibImage *images = NULL; +static ImlibImagePixmap *pixmaps = NULL; +static ImlibLoader *loaders = NULL; +static int cache_size = 4096 * 1024; /* attach a string key'd data and/or int value to an image that cna be */ /* looked up later by its string key */ void -__imlib_AttachTag(ImlibImage *im, const char *key, int val, void *data, - ImlibDataDestructorFunction destructor) +__imlib_AttachTag(ImlibImage * im, const char *key, int val, void *data, + ImlibDataDestructorFunction destructor) { ImlibImageTag *t; - + /* no string key? abort */ if (!key) - return; + return; /* if a tag of that name alreayd exists - remove it and free it */ if ((t = __imlib_RemoveTag(im, key))) @@ -49,17 +49,17 @@ __imlib_AttachTag(ImlibImage *im, const char *key, int val, void *data, /* look up a tage by its key on the image it was attached to */ ImlibImageTag * -__imlib_GetTag(ImlibImage *im, const char *key) +__imlib_GetTag(ImlibImage * im, const char *key) { ImlibImageTag *t; t = im->tags; while (t) - { - if (!strcmp(t->key, key)) - return t; - t = t->next; - } + { + if (!strcmp(t->key, key)) + return t; + t = t->next; + } /* no tag found - return NULL */ return NULL; } @@ -67,25 +67,25 @@ __imlib_GetTag(ImlibImage *im, const char *key) /* remove a tag by looking it up by its key and removing it from */ /* the list of keys */ ImlibImageTag * -__imlib_RemoveTag(ImlibImage *im, const char *key) +__imlib_RemoveTag(ImlibImage * im, const char *key) { ImlibImageTag *t, *tt; - + tt = NULL; t = im->tags; while (t) - { - if (!strcmp(t->key, key)) - { - if (tt) - tt->next = t->next; - else - im->tags = t->next; - return t; - } - tt = t; - t = t->next; - } + { + if (!strcmp(t->key, key)) + { + if (tt) + tt->next = t->next; + else + im->tags = t->next; + return t; + } + tt = t; + t = t->next; + } /* no tag found - NULL */ return NULL; } @@ -93,7 +93,7 @@ __imlib_RemoveTag(ImlibImage *im, const char *key) /* free the data struct for the tag and if a destructor function was */ /* provided call it on the data member */ void -__imlib_FreeTag(ImlibImage *im, ImlibImageTag *t) +__imlib_FreeTag(ImlibImage * im, ImlibImageTag * t) { free(t->key); if (t->destructor) @@ -103,17 +103,17 @@ __imlib_FreeTag(ImlibImage *im, ImlibImageTag *t) /* free all the tags attached to an image */ void -__imlib_FreeAllTags(ImlibImage *im) +__imlib_FreeAllTags(ImlibImage * im) { ImlibImageTag *t, *tt; - + t = im->tags; while (t) - { - tt = t; - t = t->next; - __imlib_FreeTag(im, tt); - } + { + tt = t; + t = t->next; + __imlib_FreeTag(im, tt); + } } /* set the cache size */ @@ -126,7 +126,7 @@ __imlib_SetCacheSize(int size) } /* return the cache size */ -int +int __imlib_GetCacheSize(void) { return cache_size; @@ -137,7 +137,7 @@ ImlibImage * __imlib_ProduceImage(void) { ImlibImage *im; - + im = malloc(sizeof(ImlibImage)); memset(im, 0, sizeof(ImlibImage)); im->data = NULL; @@ -151,7 +151,7 @@ __imlib_ProduceImage(void) /* free an image struct */ void -__imlib_ConsumeImage(ImlibImage *im) +__imlib_ConsumeImage(ImlibImage * im) { __imlib_FreeAllTags(im); if (im->file) @@ -167,34 +167,34 @@ ImlibImage * __imlib_FindCachedImage(const char *file) { ImlibImage *im, *previous_im; - + im = images; previous_im = NULL; /* go through the images list */ while (im) - { - /* if the filenames match and it's valid */ - if ((!strcmp(file, im->file)) && (IMAGE_IS_VALID(im))) - { - /* move the image to the head of the pixmap list */ - if (previous_im) - { - previous_im->next = im->next; - im->next = images; - images = im; - } - /* return it */ - return im; - } - previous_im = im; - im = im->next; - } + { + /* if the filenames match and it's valid */ + if ((!strcmp(file, im->file)) && (IMAGE_IS_VALID(im))) + { + /* move the image to the head of the pixmap list */ + if (previous_im) + { + previous_im->next = im->next; + im->next = images; + images = im; + } + /* return it */ + return im; + } + previous_im = im; + im = im->next; + } return NULL; } /* add an image to the cache of images (at the start) */ void -__imlib_AddImageToCache(ImlibImage *im) +__imlib_AddImageToCache(ImlibImage * im) { im->next = images; images = im; @@ -202,96 +202,96 @@ __imlib_AddImageToCache(ImlibImage *im) /* remove (unlink) an image from the cache of images */ void -__imlib_RemoveImageFromCache(ImlibImage *im) +__imlib_RemoveImageFromCache(ImlibImage * im) { ImlibImage *current_im, *previous_im; - + current_im = images; previous_im = NULL; while (current_im) - { - if (im == current_im) - { - if (previous_im) - previous_im->next = im->next; - else - images = im->next; - return; - } - previous_im = current_im; - current_im = current_im->next; - } + { + if (im == current_im) + { + if (previous_im) + previous_im->next = im->next; + else + images = im->next; + return; + } + previous_im = current_im; + current_im = current_im->next; + } } /* work out how much we have floaitng aroudn in our speculative cache */ /* (images and pixmaps that have 0 reference counts) */ -int +int __imlib_CurrentCacheSize(void) { - ImlibImage *im; - ImlibImagePixmap *ip; + ImlibImage *im; + ImlibImagePixmap *ip; int current_cache = 0; /* go through the image cache */ im = images; - while(im) - { - /* mayaswell clean out stuff thats invalid that we dont need anymore */ - if (im->references == 0) - { - if (!(IMAGE_IS_VALID(im))) - { - ImlibImage *tmp_im = im; + while (im) + { + /* mayaswell clean out stuff thats invalid that we dont need anymore */ + if (im->references == 0) + { + if (!(IMAGE_IS_VALID(im))) + { + ImlibImage *tmp_im = im; - im = im->next; - __imlib_RemoveImageFromCache(tmp_im); - __imlib_ConsumeImage(tmp_im); - continue; - } - /* it's valid but has 0 ref's - append to cache size count */ - else - current_cache += im->w * im->h * sizeof(DATA32); - } - im = im->next; - } + im = im->next; + __imlib_RemoveImageFromCache(tmp_im); + __imlib_ConsumeImage(tmp_im); + continue; + } + /* it's valid but has 0 ref's - append to cache size count */ + else + current_cache += im->w * im->h * sizeof(DATA32); + } + im = im->next; + } /* go through the pixmaps */ ip = pixmaps; - while(ip) - { - /* if the pixmap has 0 references */ - if (ip->references == 0) - { - /* if the image is invalid */ - if (!(IMAGE_IS_VALID(ip->image))) - { - ImlibImagePixmap *tmp_ip = ip; + while (ip) + { + /* if the pixmap has 0 references */ + if (ip->references == 0) + { + /* if the image is invalid */ + if (!(IMAGE_IS_VALID(ip->image))) + { + ImlibImagePixmap *tmp_ip = ip; - ip = ip->next; - __imlib_RemoveImagePixmapFromCache(tmp_ip); - __imlib_ConsumeImagePixmap(tmp_ip); - continue; - } - else - { - /* add the pixmap data size to the cache size */ - if (ip->pixmap) - { - if (ip->depth < 8) - current_cache += ip->w * ip->h * (ip->depth / 8); - else if (ip->depth == 8) - current_cache += ip->w * ip->h; - else if (ip->depth <= 16) - current_cache += ip->w * ip->h * 2; - else if (ip->depth <= 32) - current_cache += ip->w * ip->h * 4; - } - /* if theres a mask add it too */ - if (ip->mask) - current_cache += ip->w * ip->h / 8; - } - } - ip = ip->next; - } + ip = ip->next; + __imlib_RemoveImagePixmapFromCache(tmp_ip); + __imlib_ConsumeImagePixmap(tmp_ip); + continue; + } + else + { + /* add the pixmap data size to the cache size */ + if (ip->pixmap) + { + if (ip->depth < 8) + current_cache += ip->w * ip->h * (ip->depth / 8); + else if (ip->depth == 8) + current_cache += ip->w * ip->h; + else if (ip->depth <= 16) + current_cache += ip->w * ip->h * 2; + else if (ip->depth <= 32) + current_cache += ip->w * ip->h * 4; + } + /* if theres a mask add it too */ + if (ip->mask) + current_cache += ip->w * ip->h / 8; + } + } + ip = ip->next; + } return current_cache; } @@ -299,46 +299,45 @@ __imlib_CurrentCacheSize(void) void __imlib_CleanupImageCache(void) { - ImlibImage *im, *im_last; - int current_cache; - char operation = 0; + ImlibImage *im, *im_last; + int current_cache; + char operation = 0; current_cache = __imlib_CurrentCacheSize(); im_last = NULL; im = images; /* remove 0 ref coutn invalid (dirty) images */ - while(im) - { - im_last = im; - im = im->next; - if ((im_last->references <= 0) && - (!(IMAGE_IS_VALID(im_last)))) - { - __imlib_RemoveImageFromCache(im_last); - __imlib_ConsumeImage(im_last); - } - } + while (im) + { + im_last = im; + im = im->next; + if ((im_last->references <= 0) && (!(IMAGE_IS_VALID(im_last)))) + { + __imlib_RemoveImageFromCache(im_last); + __imlib_ConsumeImage(im_last); + } + } /* while the cache size of 0 ref coutn data is bigger than the set value */ /* clean out the oldest members of the imaeg cache */ while ((current_cache > cache_size) || (operation)) - { - im_last = NULL; - operation = 0; - im = images; - while(im) - { - if (im->references <= 0) - im_last = im; - im = im->next; - } - if (im_last) - { - __imlib_RemoveImageFromCache(im_last); - __imlib_ConsumeImage(im_last); - operation = 1; - } - current_cache = __imlib_CurrentCacheSize(); - } + { + im_last = NULL; + operation = 0; + im = images; + while (im) + { + if (im->references <= 0) + im_last = im; + im = im->next; + } + if (im_last) + { + __imlib_RemoveImageFromCache(im_last); + __imlib_ConsumeImage(im_last); + operation = 1; + } + current_cache = __imlib_CurrentCacheSize(); + } } /* create a pixmap cache data struct */ @@ -346,7 +345,7 @@ ImlibImagePixmap * __imlib_ProduceImagePixmap(void) { ImlibImagePixmap *ip; - + ip = malloc(sizeof(ImlibImagePixmap)); memset(ip, 0, sizeof(ImlibImagePixmap)); ip->display = NULL; @@ -358,11 +357,12 @@ __imlib_ProduceImagePixmap(void) /* free a pixmap cache data struct and the pixmaps in it */ void -__imlib_ConsumeImagePixmap(ImlibImagePixmap *ip) +__imlib_ConsumeImagePixmap(ImlibImagePixmap * ip) { #ifdef DEBUG_CACHE - fprintf(stderr, "[Imlib2] Deleting pixmap. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n", - ip->references, ip->pixmap, ip->mask); + fprintf(stderr, + "[Imlib2] Deleting pixmap. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n", + ip->references, ip->pixmap, ip->mask); #endif if (ip->pixmap) XFreePixmap(ip->display, ip->pixmap); @@ -372,69 +372,67 @@ __imlib_ConsumeImagePixmap(ImlibImagePixmap *ip) } ImlibImagePixmap * -__imlib_FindCachedImagePixmap(ImlibImage *im, int w, int h, Display *d, Visual *v, - int depth, int sx, int sy, int sw, int sh, Colormap cm, - char aa, char hiq, char dmask, - DATABIG modification_count) +__imlib_FindCachedImagePixmap(ImlibImage * im, int w, int h, Display * d, + Visual * v, int depth, int sx, int sy, int sw, + int sh, Colormap cm, char aa, char hiq, + char dmask, DATABIG modification_count) { ImlibImagePixmap *ip, *previous_ip; - + ip = pixmaps; previous_ip = NULL; /* go through the pixmap list */ while (ip) - { - /* if all the pixmap attributes match */ - if ((ip->w == w) && (ip->h == h) && (ip->depth == depth) && - (!ip->dirty) && (ip->image == im) && - (ip->visual == v) && (ip->display == d) && - (ip->source_x == sx) && (ip->source_x == sy) && - (ip->source_w == sw) && (ip->source_h == sh) && - (ip->colormap == cm) && (ip->antialias == aa) && - (ip->modification_count == modification_count) && - (ip->dither_mask == dmask) && - (ip->border.left == im->border.left) && - (ip->border.right == im->border.right) && - (ip->border.top == im->border.top) && - (ip->border.bottom == im->border.bottom) - ) - { - /* move the pixmap to the head of the pixmap list */ - if (previous_ip) - { - previous_ip->next = ip->next; - ip->next = pixmaps; - pixmaps = ip; - } - /* return it */ - return ip; - } - previous_ip = ip; - ip = ip->next; - } + { + /* if all the pixmap attributes match */ + if ((ip->w == w) && (ip->h == h) && (ip->depth == depth) && (!ip->dirty) + && (ip->image == im) && (ip->visual == v) && (ip->display == d) + && (ip->source_x == sx) && (ip->source_x == sy) + && (ip->source_w == sw) && (ip->source_h == sh) + && (ip->colormap == cm) && (ip->antialias == aa) + && (ip->modification_count == modification_count) + && (ip->dither_mask == dmask) + && (ip->border.left == im->border.left) + && (ip->border.right == im->border.right) + && (ip->border.top == im->border.top) + && (ip->border.bottom == im->border.bottom)) + { + /* move the pixmap to the head of the pixmap list */ + if (previous_ip) + { + previous_ip->next = ip->next; + ip->next = pixmaps; + pixmaps = ip; + } + /* return it */ + return ip; + } + previous_ip = ip; + ip = ip->next; + } return NULL; } ImlibImagePixmap * -__imlib_FindCachedImagePixmapByID(Display *d, Pixmap p) +__imlib_FindCachedImagePixmapByID(Display * d, Pixmap p) { ImlibImagePixmap *ip; - + ip = pixmaps; /* go through the pixmap list */ while (ip) - { - /* if all the pixmap attributes match */ - if ((ip->pixmap == p) && (ip->display == d)) - return ip; - ip = ip->next; - } + { + /* if all the pixmap attributes match */ + if ((ip->pixmap == p) && (ip->display == d)) + return ip; + ip = ip->next; + } return NULL; } /* add a pixmap cahce struct to the pixmap cache (at the start of course */ void -__imlib_AddImagePixmapToCache(ImlibImagePixmap *ip) +__imlib_AddImagePixmapToCache(ImlibImagePixmap * ip) { ip->next = pixmaps; pixmaps = ip; @@ -442,95 +440,95 @@ __imlib_AddImagePixmapToCache(ImlibImagePixmap *ip) /* remove a pixmap cache struct fromt he pixmap cache */ void -__imlib_RemoveImagePixmapFromCache(ImlibImagePixmap *ip) +__imlib_RemoveImagePixmapFromCache(ImlibImagePixmap * ip) { ImlibImagePixmap *current_ip, *previous_ip; - + current_ip = pixmaps; previous_ip = NULL; while (current_ip) - { - if (ip == current_ip) - { - if (previous_ip) - previous_ip->next = ip->next; - else - pixmaps = ip->next; - return; - } - previous_ip = current_ip; - current_ip = current_ip->next; - } + { + if (ip == current_ip) + { + if (previous_ip) + previous_ip->next = ip->next; + else + pixmaps = ip->next; + return; + } + previous_ip = current_ip; + current_ip = current_ip->next; + } } /* clean out 0 reference count & dirty pixmaps from the cache */ void __imlib_CleanupImagePixmapCache(void) { - ImlibImagePixmap *ip, *ip_last; - int current_cache; - char operation = 0; - + ImlibImagePixmap *ip, *ip_last; + int current_cache; + char operation = 0; + current_cache = __imlib_CurrentCacheSize(); ip_last = NULL; ip = pixmaps; - while(ip) - { - ip_last = ip; - ip = ip->next; - if ((ip_last->references <= 0) && - (ip_last->dirty)) - { - __imlib_RemoveImagePixmapFromCache(ip_last); - __imlib_ConsumeImagePixmap(ip_last); - } - } + while (ip) + { + ip_last = ip; + ip = ip->next; + if ((ip_last->references <= 0) && (ip_last->dirty)) + { + __imlib_RemoveImagePixmapFromCache(ip_last); + __imlib_ConsumeImagePixmap(ip_last); + } + } while ((current_cache > cache_size) || (operation)) - { - ip_last = NULL; - operation = 0; - ip = pixmaps; - while(ip) - { - if (ip->references <= 0) - ip_last = ip; - ip = ip->next; - } - if (ip_last) - { - __imlib_RemoveImagePixmapFromCache(ip_last); - __imlib_ConsumeImagePixmap(ip_last); - operation = 1; - } - current_cache = __imlib_CurrentCacheSize(); - } + { + ip_last = NULL; + operation = 0; + ip = pixmaps; + while (ip) + { + if (ip->references <= 0) + ip_last = ip; + ip = ip->next; + } + if (ip_last) + { + __imlib_RemoveImagePixmapFromCache(ip_last); + __imlib_ConsumeImagePixmap(ip_last); + operation = 1; + } + current_cache = __imlib_CurrentCacheSize(); + } } #define LOADERS_UNINITIALISED -4444 static int errors = LOADERS_UNINITIALISED; - + static void LTDL_Init(void) { - /* Do this only once! */ - - if ((errors == LOADERS_UNINITIALISED)) - { + /* Do this only once! */ + + if ((errors == LOADERS_UNINITIALISED)) + { errors = lt_dlinit(); /* Initialise libltdl's memory management. */ lt_dlmalloc = malloc; lt_dlfree = free; - } + } - /* Failing ltdl initialisation makes continuing somewhat futile... */ - if (errors != 0) - { + /* Failing ltdl initialisation makes continuing somewhat futile... */ + if (errors != 0) + { const char *dlerror = lt_dlerror(); + fprintf(stderr, "ERROR: failed to initialise ltdl: %s\n", dlerror); exit(1); - } + } } void @@ -546,28 +544,28 @@ ImlibLoader * __imlib_ProduceLoader(char *file) { ImlibLoader *l; - void (*l_formats)(ImlibLoader *l); - + void (*l_formats) (ImlibLoader * l); + LTDL_Init(); - + l = malloc(sizeof(ImlibLoader)); l->num_formats = 0; l->formats = NULL; l->handle = lt_dlopenext(file); if (!l->handle) - { - free(l); - return NULL; - } + { + free(l); + return NULL; + } l->load = lt_dlsym(l->handle, "load"); l->save = lt_dlsym(l->handle, "save"); l_formats = lt_dlsym(l->handle, "formats"); if ((!(l->load)) || (!(l->save)) || (!(l_formats))) - { - lt_dlclose(l->handle); - free(l); - return NULL; - } + { + lt_dlclose(l->handle); + free(l); + return NULL; + } l_formats(l); l->file = strdup(file); l->next = NULL; @@ -581,7 +579,7 @@ __imlib_ListLoaders(int *num_ret) { char **list = NULL, **l, s[4096], *home; int num, i, pi = 0; - + *num_ret = 0; /* get the user's home dir */ home = __imlib_FileHomeDir(getuid()); @@ -590,114 +588,122 @@ __imlib_ListLoaders(int *num_ret) l = __imlib_FileDir(s, &num); /* if theres files */ if (num > 0) - { - /* make a list of them */ - *num_ret += num; - list = malloc(sizeof(char *) * *num_ret); - for (i = 0; i < num; i++) - { - sprintf(s, "%s/" USER_LOADERS_PATH "/image/%s", home, l[i]); - list[i] = strdup(s); - } - pi = i; - __imlib_FileFreeDirList(l, num); - } + { + /* make a list of them */ + *num_ret += num; + list = malloc(sizeof(char *) * *num_ret); + + for (i = 0; i < num; i++) + { + sprintf(s, "%s/" USER_LOADERS_PATH "/image/%s", home, l[i]); + list[i] = strdup(s); + } + pi = i; + __imlib_FileFreeDirList(l, num); + } /* same for system loader path */ sprintf(s, SYS_LOADERS_PATH "/image"); l = __imlib_FileDir(s, &num); if (num > 0) - { - *num_ret += num; - list = realloc(list, sizeof(char *) * *num_ret); - for (i = 0; i < num; i++) - { - sprintf(s, SYS_LOADERS_PATH "/image/%s", l[i]); - list[pi + i] = strdup(s); - } - __imlib_FileFreeDirList(l, num); - } - free(home); + { + *num_ret += num; + list = realloc(list, sizeof(char *) * *num_ret); - /* List currently contains *everything in there* we need to weed out - * the .so, .la, .a versions of the same loader or whatever else. - * lt_dlopen can take an extension-less name and do the Right Thing - * with it, so that's what we'll give it. */ - list = __imlib_TrimLoaderList(list, num_ret); + for (i = 0; i < num; i++) + { + sprintf(s, SYS_LOADERS_PATH "/image/%s", l[i]); + list[pi + i] = strdup(s); + } + __imlib_FileFreeDirList(l, num); + } + free(home); + + /* List currently contains *everything in there* we need to weed out + * the .so, .la, .a versions of the same loader or whatever else. + * lt_dlopen can take an extension-less name and do the Right Thing + * with it, so that's what we'll give it. */ + list = __imlib_TrimLoaderList(list, num_ret); return list; } -char **__imlib_TrimLoaderList(char **list, int *num) +char ** +__imlib_TrimLoaderList(char **list, int *num) { - int i, n, size=0; - - char **ret = NULL; - if(!list) - return NULL; - if(*num == 0) - return list; + int i, n, size = 0; - n = *num; - - for (i = 0; i < n; i++) - { - char *ext; - if(!list[i]) - continue; - ext = strrchr(list[i], '.'); - if(ext) - { - *ext = '\0'; - /* Don't add the same loader multiple times... */ - if(!__imlib_ItemInList(ret, size, list[i])) - { - ret = realloc(ret, sizeof(char *) * (size + 1)); - ret[size++] = strdup(list[i]); - } - } - if(list[i]) - free (list[i]); - } - if(list) - free(list); - *num = size; - return ret; + char **ret = NULL; + + if (!list) + return NULL; + if (*num == 0) + return list; + + n = *num; + + for (i = 0; i < n; i++) + { + char *ext; + + if (!list[i]) + continue; + ext = strrchr(list[i], '.'); + if (ext) + { + *ext = '\0'; + /* Don't add the same loader multiple times... */ + if (!__imlib_ItemInList(ret, size, list[i])) + { + ret = realloc(ret, sizeof(char *) * (size + 1)); + + ret[size++] = strdup(list[i]); + } + } + if (list[i]) + free(list[i]); + } + if (list) + free(list); + *num = size; + return ret; } -int __imlib_ItemInList(char **list, int size, char *item) +int +__imlib_ItemInList(char **list, int size, char *item) { - int i; - if(!size) - return 0; - if(!list) - return 0; - if(!item) - return 0; + int i; - for(i=0; ifile) free(l->file); if (l->handle) lt_dlclose(l->handle); if (l->formats) - { - int i; - - for (i = 0; i < l->num_formats; i++) - free(l->formats[i]); - free(l->formats); - } + { + int i; + + for (i = 0; i < l->num_formats; i++) + free(l->formats[i]); + free(l->formats); + } free(l); } @@ -705,12 +711,12 @@ void __imlib_RescanLoaders(void) { static time_t last_scan_time = 0; - static time_t last_modified_home_time = 0; + static time_t last_modified_home_time = 0; static time_t last_modified_system_time = 0; time_t current_time; char s[4096], *home; char do_reload = 0; - + /* dont stat the dir and rescan if we checked in the last 5 seconds */ current_time = time(NULL); if ((current_time - last_scan_time) < 5) @@ -718,37 +724,38 @@ __imlib_RescanLoaders(void) /* ok - was the system loaders dir contents modified ? */ last_scan_time = current_time; #ifndef __EMX__ - if (__imlib_FileIsDir(SYS_LOADERS_PATH "/image/")) + if (__imlib_FileIsDir(SYS_LOADERS_PATH "/image/")) #else if (__imlib_FileIsDir(__XOS2RedirRoot(SYS_LOADERS_PATH "/image/"))) #endif - { + { #ifndef __EMX__ - current_time = __imlib_FileModDate(SYS_LOADERS_PATH "/image/"); + current_time = __imlib_FileModDate(SYS_LOADERS_PATH "/image/"); #else - current_time = __imlib_FileModDate(__XOS2RedirRoot(SYS_LOADERS_PATH "/image/")); + current_time = + __imlib_FileModDate(__XOS2RedirRoot(SYS_LOADERS_PATH "/image/")); #endif - if (current_time > last_modified_system_time) - { - /* yup - set the "do_reload" flag */ - do_reload = 1; - last_modified_system_time = current_time; - } - } + if (current_time > last_modified_system_time) + { + /* yup - set the "do_reload" flag */ + do_reload = 1; + last_modified_system_time = current_time; + } + } /* ok - was the users own loaders dir contents modified ? */ home = __imlib_FileHomeDir(getuid()); - sprintf(s, "%s/" USER_LOADERS_PATH "/image/", home); - free(home); + sprintf(s, "%s/" USER_LOADERS_PATH "/image/", home); + free(home); if (__imlib_FileIsDir(s)) - { - current_time = __imlib_FileModDate(s); - if (current_time > last_modified_home_time) - { - /* yup - set the "do_reload" flag */ - do_reload = 1; - last_modified_home_time = current_time; - } - } + { + current_time = __imlib_FileModDate(s); + if (current_time > last_modified_home_time) + { + /* yup - set the "do_reload" flag */ + do_reload = 1; + last_modified_home_time = current_time; + } + } /* if we dont ned to reload the loaders - get out now */ if (!do_reload) return; @@ -761,14 +768,14 @@ void __imlib_RemoveAllLoaders(void) { ImlibLoader *l, *il; - + l = loaders; - while(l) - { - il = l; - l = l->next; - __imlib_ConsumeLoader(il); - } + while (l) + { + il = l; + l = l->next; + __imlib_ConsumeLoader(il); + } loaders = NULL; } @@ -777,7 +784,7 @@ __imlib_RemoveAllLoaders(void) void __imlib_LoadAllLoaders(void) { - int i, num; + int i, num; char **list; /* list all the loaders imlib can find */ @@ -785,22 +792,22 @@ __imlib_LoadAllLoaders(void) /* no loaders? well don't load anything */ if (!list) return; - + /* go through the list of filenames for loader .so's and load them */ /* (or try) and if it succeeds, append to our loader list */ for (i = num - 1; i >= 0; i--) - { - ImlibLoader *l; - - l = __imlib_ProduceLoader(list[i]); - if (l) - { - l->next = loaders; - loaders = l; - } - if (list[i]) - free(list[i]); - } + { + ImlibLoader *l; + + l = __imlib_ProduceLoader(list[i]); + if (l) + { + l->next = loaders; + loaders = l; + } + if (list[i]) + free(list[i]); + } free(list); } @@ -818,11 +825,12 @@ __imlib_FindBestLoaderForFile(const char *file) /* extensions that file format could have */ lower = extension; while (*lower) - { - *lower = tolower(*lower); - lower++; - } - if (!extension) return NULL; + { + *lower = tolower(*lower); + lower++; + } + if (!extension) + return NULL; /* go through the loaders - first loader that claims to handle that */ /* image type (extension wise) wins as a first guess to use - NOTE */ /* this is an OPTIMISATION - it is possible the file has no extension */ @@ -837,27 +845,27 @@ __imlib_FindBestLoaderForFile(const char *file) /* of the same format */ l = loaders; while (l) - { - int i; - - /* go through all the formats that loader supports */ - for (i = 0; i < l->num_formats; i++) - { - /* does it match ? */ - if (!strcmp(l->formats[i], extension)) - { - /* free the memory allocated for the extension */ - free(extension); - /* return the loader */ - return l; - } - } - l = l->next; - } + { + int i; + + /* go through all the formats that loader supports */ + for (i = 0; i < l->num_formats; i++) + { + /* does it match ? */ + if (!strcmp(l->formats[i], extension)) + { + /* free the memory allocated for the extension */ + free(extension); + /* return the loader */ + return l; + } + } + l = l->next; + } /* free the memory allocated for the extension */ free(extension); /* return the loader */ - return l; + return l; } ImlibLoader * @@ -871,48 +879,49 @@ __imlib_FindBestLoaderForFileFormat(const char *file, char *format) extension = strdup(format); /* otherwise us the extension */ else - { - extension = __imlib_FileExtension(file); - /* change the extension to all lower case as all "types" are listed as */ - /* lower case strings fromt he loader that represent all the possible */ - /* extensions that file format could have */ - lower = extension; - while (*lower) - { - *lower = tolower(*lower); - lower++; - } - } - if (!extension) return NULL; + { + extension = __imlib_FileExtension(file); + /* change the extension to all lower case as all "types" are listed as */ + /* lower case strings fromt he loader that represent all the possible */ + /* extensions that file format could have */ + lower = extension; + while (*lower) + { + *lower = tolower(*lower); + lower++; + } + } + if (!extension) + return NULL; /* look thought the loaders one by one to see if one matches that format */ l = loaders; while (l) - { - int i; - - /* go through all the formats that loader supports */ - for (i = 0; i < l->num_formats; i++) - { - /* does it match ? */ - if (!strcmp(l->formats[i], extension)) - { - /* free the memory allocated for the extension */ - free(extension); - /* return the loader */ - return l; - } - } - l = l->next; - } + { + int i; + + /* go through all the formats that loader supports */ + for (i = 0; i < l->num_formats; i++) + { + /* does it match ? */ + if (!strcmp(l->formats[i], extension)) + { + /* free the memory allocated for the extension */ + free(extension); + /* return the loader */ + return l; + } + } + l = l->next; + } /* free the memory allocated for the extension */ free(extension); /* return the loader */ - return l; + return l; } /* set or unset the alpha flag on the umage (alpha = 1 / 0 ) */ void -__imlib_SetImageAlphaFlag(ImlibImage *im, char alpha) +__imlib_SetImageAlphaFlag(ImlibImage * im, char alpha) { if (alpha) SET_FLAG(im->flags, F_HAS_ALPHA); @@ -923,9 +932,9 @@ __imlib_SetImageAlphaFlag(ImlibImage *im, char alpha) /* create a new image struct from data passed that is wize w x h then return */ /* a pointer to that image sturct */ ImlibImage * -__imlib_CreateImage(int w, int h, DATA32 *data) +__imlib_CreateImage(int w, int h, DATA32 * data) { - ImlibImage *im; + ImlibImage *im; im = __imlib_ProduceImage(); im->w = w; @@ -937,12 +946,11 @@ __imlib_CreateImage(int w, int h, DATA32 *data) } ImlibImage * -__imlib_LoadImage(const char *file, - ImlibProgressFunction progress, - char progress_granularity, char immediate_load, char dont_cache, - ImlibLoadError *er) +__imlib_LoadImage(const char *file, ImlibProgressFunction progress, + char progress_granularity, char immediate_load, + char dont_cache, ImlibLoadError * er) { - ImlibImage *im; + ImlibImage *im; ImlibLoader *best_loader; char loader_ret = 0; @@ -952,32 +960,32 @@ __imlib_LoadImage(const char *file, /* accurate to the disk conents if they changed since we last loaded */ /* and that it is still a valid image */ if ((im) && (IMAGE_IS_VALID(im))) - { - if (IMAGE_ALWAYS_CHECK_DISK(im)) - { - time_t current_modified_time; - - current_modified_time = __imlib_FileModDate(file); - /* if the file on disk is newer than the cached one */ - if (current_modified_time > im->moddate) - { - /* invalidate image */ - SET_FLAG(im->flags, F_INVALID); - } - else - { - /* image is ok to re-use - program is just being stupid loading */ - /* the same data twice */ - im->references++; - return im; - } - } - else - { - im->references++; - return im; - } - } + { + if (IMAGE_ALWAYS_CHECK_DISK(im)) + { + time_t current_modified_time; + + current_modified_time = __imlib_FileModDate(file); + /* if the file on disk is newer than the cached one */ + if (current_modified_time > im->moddate) + { + /* invalidate image */ + SET_FLAG(im->flags, F_INVALID); + } + else + { + /* image is ok to re-use - program is just being stupid loading */ + /* the same data twice */ + im->references++; + return im; + } + } + else + { + im->references++; + return im; + } + } /* either image in cache is invalid or we dont even have it in cache */ /* so produce a new one and load an image into that */ im = __imlib_ProduceImage(); @@ -989,128 +997,132 @@ __imlib_LoadImage(const char *file, best_loader = __imlib_FindBestLoaderForFile(file); errno = 0; if (best_loader) - loader_ret = best_loader->load(im, progress, progress_granularity, immediate_load); + loader_ret = + best_loader->load(im, progress, progress_granularity, + immediate_load); /* if the caller wants error returns */ if (er) - { - /* default to no error */ - *er = LOAD_ERROR_NONE; - if (errno != 0) - { - /* if theres an error default to an unknown one */ - *er = LOAD_ERROR_UNKNOWN; - /* translate common fopen() etc. errno's */ - if (errno == EEXIST) - *er = LOAD_ERROR_FILE_DOES_NOT_EXIST; - else if (errno == EISDIR) - *er = LOAD_ERROR_FILE_IS_DIRECTORY; - else if (errno == EISDIR) - *er = LOAD_ERROR_FILE_IS_DIRECTORY; - else if (errno == EACCES) - *er = LOAD_ERROR_PERMISSION_DENIED_TO_READ; - else if (errno == ENAMETOOLONG) - *er = LOAD_ERROR_PATH_TOO_LONG; - else if (errno == ENOENT) - *er = LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT; - else if (errno == ENOTDIR) - *er = LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY; - else if (errno == EFAULT) - *er = LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE; - else if (errno == ELOOP) - *er = LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS; - else if (errno == ENOMEM) - *er = LOAD_ERROR_OUT_OF_MEMORY; - else if (errno == EMFILE) - *er = LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS; - /* free our struct */ - __imlib_ConsumeImage(im); - return NULL; - } - errno = 0; - } + { + /* default to no error */ + *er = LOAD_ERROR_NONE; + if (errno != 0) + { + /* if theres an error default to an unknown one */ + *er = LOAD_ERROR_UNKNOWN; + /* translate common fopen() etc. errno's */ + if (errno == EEXIST) + *er = LOAD_ERROR_FILE_DOES_NOT_EXIST; + else if (errno == EISDIR) + *er = LOAD_ERROR_FILE_IS_DIRECTORY; + else if (errno == EISDIR) + *er = LOAD_ERROR_FILE_IS_DIRECTORY; + else if (errno == EACCES) + *er = LOAD_ERROR_PERMISSION_DENIED_TO_READ; + else if (errno == ENAMETOOLONG) + *er = LOAD_ERROR_PATH_TOO_LONG; + else if (errno == ENOENT) + *er = LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT; + else if (errno == ENOTDIR) + *er = LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY; + else if (errno == EFAULT) + *er = LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE; + else if (errno == ELOOP) + *er = LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS; + else if (errno == ENOMEM) + *er = LOAD_ERROR_OUT_OF_MEMORY; + else if (errno == EMFILE) + *er = LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS; + /* free our struct */ + __imlib_ConsumeImage(im); + return NULL; + } + errno = 0; + } /* width is still 0 - the loader didnt manage to do anything */ if (im->w == 0) - { - ImlibLoader *l, *previous_l = NULL; - l = loaders; - /* run through all loaders and try load until one succeeds */ - while ((l) && (im->w == 0)) - { - /* if its not the best loader that alreayd failed - try load */ - if (l != best_loader) - loader_ret = l->load(im, progress, progress_granularity, immediate_load); - /* if it failed - advance */ - if (im->w == 0) - { - /* if the caller wants an error return */ - if (er) - { - /* set to a default fo no error */ - *er = LOAD_ERROR_NONE; - /* if the errno is set */ - if (errno != 0) - { - /* default to unknown error */ - *er = LOAD_ERROR_UNKNOWN; - /* standrad fopen() type errors translated */ - if (errno == EEXIST) - *er = LOAD_ERROR_FILE_DOES_NOT_EXIST; - else if (errno == EISDIR) - *er = LOAD_ERROR_FILE_IS_DIRECTORY; - else if (errno == EISDIR) - *er = LOAD_ERROR_FILE_IS_DIRECTORY; - else if (errno == EACCES) - *er = LOAD_ERROR_PERMISSION_DENIED_TO_READ; - else if (errno == ENAMETOOLONG) - *er = LOAD_ERROR_PATH_TOO_LONG; - else if (errno == ENOENT) - *er = LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT; - else if (errno == ENOTDIR) - *er = LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY; - else if (errno == EFAULT) - *er = LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE; - else if (errno == ELOOP) - *er = LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS; - else if (errno == ENOMEM) - *er = LOAD_ERROR_OUT_OF_MEMORY; - else if (errno == EMFILE) - *er = LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS; - /* free the stuct we created */ - __imlib_ConsumeImage(im); - return NULL; - } - errno = 0; - } - previous_l = l; - l = l->next; - } - } - /* if we have a loader then its the loader that succeeded */ - /* move the successful loader to the head of the list */ - /* as long as it's not alreayd at the head of the list */ - if ((l) && (previous_l)) - { - im->loader = l; - previous_l->next = l->next; - l->next = loaders; - loaders = l; - } - } + { + ImlibLoader *l, *previous_l = NULL; + + l = loaders; + /* run through all loaders and try load until one succeeds */ + while ((l) && (im->w == 0)) + { + /* if its not the best loader that alreayd failed - try load */ + if (l != best_loader) + loader_ret = + l->load(im, progress, progress_granularity, immediate_load); + /* if it failed - advance */ + if (im->w == 0) + { + /* if the caller wants an error return */ + if (er) + { + /* set to a default fo no error */ + *er = LOAD_ERROR_NONE; + /* if the errno is set */ + if (errno != 0) + { + /* default to unknown error */ + *er = LOAD_ERROR_UNKNOWN; + /* standrad fopen() type errors translated */ + if (errno == EEXIST) + *er = LOAD_ERROR_FILE_DOES_NOT_EXIST; + else if (errno == EISDIR) + *er = LOAD_ERROR_FILE_IS_DIRECTORY; + else if (errno == EISDIR) + *er = LOAD_ERROR_FILE_IS_DIRECTORY; + else if (errno == EACCES) + *er = LOAD_ERROR_PERMISSION_DENIED_TO_READ; + else if (errno == ENAMETOOLONG) + *er = LOAD_ERROR_PATH_TOO_LONG; + else if (errno == ENOENT) + *er = LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT; + else if (errno == ENOTDIR) + *er = LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY; + else if (errno == EFAULT) + *er = LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE; + else if (errno == ELOOP) + *er = LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS; + else if (errno == ENOMEM) + *er = LOAD_ERROR_OUT_OF_MEMORY; + else if (errno == EMFILE) + *er = LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS; + /* free the stuct we created */ + __imlib_ConsumeImage(im); + return NULL; + } + errno = 0; + } + previous_l = l; + l = l->next; + } + } + /* if we have a loader then its the loader that succeeded */ + /* move the successful loader to the head of the list */ + /* as long as it's not alreayd at the head of the list */ + if ((l) && (previous_l)) + { + im->loader = l; + previous_l->next = l->next; + l->next = loaders; + loaders = l; + } + } else im->loader = best_loader; /* all loaders have been tried and they all failed. free the skeleton */ /* image struct we had and return NULL */ if (im->w == 0) - { - __imlib_ConsumeImage(im); - return NULL; - } - + { + __imlib_ConsumeImage(im); + return NULL; + } + /* the load succeeded - make sure the image is referenced then add */ /* it to our cache if dont_cache isn't set */ im->references = 1; if (loader_ret == 2) - dont_cache = 1; + dont_cache = 1; if (!dont_cache) __imlib_AddImageToCache(im); else @@ -1120,107 +1132,109 @@ __imlib_LoadImage(const char *file, /* find an imagepixmap cache enctyr by the display and pixmap id */ ImlibImagePixmap * -__imlib_FindImlibImagePixmapByID(Display *d, Pixmap p) +__imlib_FindImlibImagePixmapByID(Display * d, Pixmap p) { ImlibImagePixmap *ip; - + ip = pixmaps; /* go through the pixmap list */ while (ip) - { - /* if all the pixmap ID & Display match */ - if ((ip->pixmap == p) && (ip->display == d)) - { + { + /* if all the pixmap ID & Display match */ + if ((ip->pixmap == p) && (ip->display == d)) + { #ifdef DEBUG_CACHE - fprintf(stderr, "[Imlib2] Match found. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n", - ip->references, ip->pixmap, ip->mask); + fprintf(stderr, + "[Imlib2] Match found. Reference count is %d, pixmap 0x%08x, mask 0x%08x\n", + ip->references, ip->pixmap, ip->mask); #endif - return ip; - } - ip = ip->next; - } + return ip; + } + ip = ip->next; + } return NULL; } /* free and image - if its uncachable and refcoutn is 0 - free it in reality */ void -__imlib_FreeImage(ImlibImage *im) +__imlib_FreeImage(ImlibImage * im) { /* if the refcount is positive */ if (im->references >= 0) - { - /* reduce a reference from the count */ - im->references--; - /* if its uncachchable ... */ - if (IMAGE_IS_UNCACHEABLE(im)) - { - /* and we're down to no references for the image then free it */ - if (im->references == 0) - __imlib_ConsumeImage(im); - } - /* otherwise clean up our cache if the image becoem 0 ref count */ - else if (im->references == 0) - __imlib_CleanupImageCache(); - } + { + /* reduce a reference from the count */ + im->references--; + /* if its uncachchable ... */ + if (IMAGE_IS_UNCACHEABLE(im)) + { + /* and we're down to no references for the image then free it */ + if (im->references == 0) + __imlib_ConsumeImage(im); + } + /* otherwise clean up our cache if the image becoem 0 ref count */ + else if (im->references == 0) + __imlib_CleanupImageCache(); + } } /* free a cached pixmap */ void -__imlib_FreePixmap(Display *d, Pixmap p) +__imlib_FreePixmap(Display * d, Pixmap p) { ImlibImagePixmap *ip; - + /* find the pixmap in the cache by display and id */ ip = __imlib_FindImlibImagePixmapByID(d, p); if (ip) - { - /* if tis positive reference count */ - if (ip->references > 0) - { - /* dereference it by one */ - ip->references--; + { + /* if tis positive reference count */ + if (ip->references > 0) + { + /* dereference it by one */ + ip->references--; #ifdef DEBUG_CACHE - fprintf(stderr, "[Imlib2] Reference count is now %d for pixmap 0x%08x\n", - ip->references, ip->pixmap); + fprintf(stderr, + "[Imlib2] Reference count is now %d for pixmap 0x%08x\n", + ip->references, ip->pixmap); #endif - /* if it becaume 0 reference count - clean the cache up */ - if (ip->references == 0) - __imlib_CleanupImagePixmapCache(); - } - } + /* if it becaume 0 reference count - clean the cache up */ + if (ip->references == 0) + __imlib_CleanupImagePixmapCache(); + } + } else - { + { #ifdef DEBUG_CACHE - fprintf(stderr, "[Imlib2] Pixmap 0x%08x not found. Freeing.\n", p); - XFreePixmap(d, p); + fprintf(stderr, "[Imlib2] Pixmap 0x%08x not found. Freeing.\n", p); + XFreePixmap(d, p); #endif - } + } } /* mark all pixmaps generated from this image as diryt so the cache code */ /* wont pick up on them again sicne they are now invalid sicn ehte original */ /* data they were generated form has changed */ void -__imlib_DirtyPixmapsForImage(ImlibImage *im) +__imlib_DirtyPixmapsForImage(ImlibImage * im) { ImlibImagePixmap *ip; - + ip = pixmaps; /* go through the pixmap list */ while (ip) - { - /* if image matches */ - if (ip->image == im) - ip->dirty = 1; - ip = ip->next; - } + { + /* if image matches */ + if (ip->image == im) + ip->dirty = 1; + ip = ip->next; + } __imlib_CleanupImagePixmapCache(); } /* dirty and image by settings its invalid flag */ void -__imlib_DirtyImage(ImlibImage *im) +__imlib_DirtyImage(ImlibImage * im) { SET_FLAG(im->flags, F_INVALID); /* and dirty all pixmaps generated from it */ @@ -1228,42 +1242,41 @@ __imlib_DirtyImage(ImlibImage *im) } void -__imlib_SaveImage(ImlibImage *im, const char *file, - ImlibProgressFunction progress, - char progress_granularity, - ImlibLoadError *er) +__imlib_SaveImage(ImlibImage * im, const char *file, + ImlibProgressFunction progress, char progress_granularity, + ImlibLoadError * er) { ImlibLoader *l; char e, *pfile; if (!file) - { - if (er) - *er = LOAD_ERROR_FILE_DOES_NOT_EXIST; - return; - } + { + if (er) + *er = LOAD_ERROR_FILE_DOES_NOT_EXIST; + return; + } /* ok - just check all our loaders are up to date */ __imlib_RescanLoaders(); /* find the laoder for the format - if its null use the extension */ l = __imlib_FindBestLoaderForFileFormat(file, im->format); /* no loader - abort */ - if (!l) - { - if (er) - *er = LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT; - return; - } + if (!l) + { + if (er) + *er = LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT; + return; + } /* no saver function in loader - abort */ if (!l->save) - { - if (er) - *er = LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT; - return; - } + { + if (er) + *er = LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT; + return; + } /* if they want an error returned - assume none by default */ if (er) *er = LOAD_ERROR_NONE; - + /* set the filename to the saved one */ pfile = im->file; im->file = strdup(file); @@ -1275,33 +1288,33 @@ __imlib_SaveImage(ImlibImage *im, const char *file, /* if there's an error return and the save faile (e = 0) figure it out */ if ((er) && (e == 0)) - { - *er = LOAD_ERROR_UNKNOWN; - if (errno == EEXIST) - *er = LOAD_ERROR_FILE_DOES_NOT_EXIST; - else if (errno == EISDIR) - *er = LOAD_ERROR_FILE_IS_DIRECTORY; - else if (errno == EISDIR) - *er = LOAD_ERROR_FILE_IS_DIRECTORY; - else if (errno == EACCES) - *er = LOAD_ERROR_PERMISSION_DENIED_TO_WRITE; - else if (errno == ENAMETOOLONG) - *er = LOAD_ERROR_PATH_TOO_LONG; - else if (errno == ENOENT) - *er = LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT; - else if (errno == ENOTDIR) - *er = LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY; - else if (errno == EFAULT) - *er = LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE; - else if (errno == ELOOP) - *er = LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS; - else if (errno == ENOMEM) - *er = LOAD_ERROR_OUT_OF_MEMORY; - else if (errno == EMFILE) - *er = LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS; - else if (errno == ENOSPC) - *er = LOAD_ERROR_OUT_OF_DISK_SPACE; - else if (errno == EROFS) - *er = LOAD_ERROR_PERMISSION_DENIED_TO_WRITE; - } + { + *er = LOAD_ERROR_UNKNOWN; + if (errno == EEXIST) + *er = LOAD_ERROR_FILE_DOES_NOT_EXIST; + else if (errno == EISDIR) + *er = LOAD_ERROR_FILE_IS_DIRECTORY; + else if (errno == EISDIR) + *er = LOAD_ERROR_FILE_IS_DIRECTORY; + else if (errno == EACCES) + *er = LOAD_ERROR_PERMISSION_DENIED_TO_WRITE; + else if (errno == ENAMETOOLONG) + *er = LOAD_ERROR_PATH_TOO_LONG; + else if (errno == ENOENT) + *er = LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT; + else if (errno == ENOTDIR) + *er = LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY; + else if (errno == EFAULT) + *er = LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE; + else if (errno == ELOOP) + *er = LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS; + else if (errno == ENOMEM) + *er = LOAD_ERROR_OUT_OF_MEMORY; + else if (errno == EMFILE) + *er = LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS; + else if (errno == ENOSPC) + *er = LOAD_ERROR_OUT_OF_DISK_SPACE; + else if (errno == EROFS) + *er = LOAD_ERROR_PERMISSION_DENIED_TO_WRITE; + } }