forked from old/legacy-imlib2
Introduce imlib_get_error()
Some of the image loading functions have a version with an error_return, and some not. With imlib_get_error() it is now possible to fetch the load error for any image loading function call.
This commit is contained in:
parent
51906190a1
commit
43c54e1345
|
@ -738,6 +738,19 @@ EAPI Visual *imlib_get_best_visual(Display * display, int screen,
|
|||
*/
|
||||
EAPI void imlib_flush_loaders(void);
|
||||
|
||||
/**
|
||||
* Get error code from previous imlib function call
|
||||
*
|
||||
* For now an error code is only meaningful when an image loading
|
||||
* function (imlib_load_image...()) has failed (returned NULL).
|
||||
*
|
||||
* @return error code
|
||||
* 0: Success,
|
||||
* positive: Regular errnos,
|
||||
* negative: IMLIB_ERR_... values, see above
|
||||
*/
|
||||
EAPI int imlib_get_error(void);
|
||||
|
||||
/**
|
||||
* Load an image from file (header only)
|
||||
*
|
||||
|
|
|
@ -499,6 +499,12 @@ imlib_flush_loaders(void)
|
|||
__imlib_RemoveAllLoaders();
|
||||
}
|
||||
|
||||
EAPI int
|
||||
imlib_get_error(void)
|
||||
{
|
||||
return ctx->error;
|
||||
}
|
||||
|
||||
EAPI Imlib_Image
|
||||
imlib_load_image(const char *file)
|
||||
{
|
||||
|
@ -508,6 +514,7 @@ imlib_load_image(const char *file)
|
|||
CHECK_PARAM_POINTER_RETURN("file", file, NULL);
|
||||
|
||||
im = __imlib_LoadImage(file, &ila);
|
||||
ctx->error = ila.err;
|
||||
|
||||
return im;
|
||||
}
|
||||
|
@ -521,7 +528,8 @@ _imlib_load_image_immediately(const char *file, int *err)
|
|||
CHECK_PARAM_POINTER_RETURN("file", file, NULL);
|
||||
|
||||
im = __imlib_LoadImage(file, &ila);
|
||||
*err = ila.err;
|
||||
ctx->error = ila.err;
|
||||
*err = ctx->error;
|
||||
|
||||
return im;
|
||||
}
|
||||
|
@ -543,6 +551,7 @@ imlib_load_image_without_cache(const char *file)
|
|||
CHECK_PARAM_POINTER_RETURN("file", file, NULL);
|
||||
|
||||
im = __imlib_LoadImage(file, &ila);
|
||||
ctx->error = ila.err;
|
||||
|
||||
return im;
|
||||
}
|
||||
|
@ -556,6 +565,7 @@ imlib_load_image_immediately_without_cache(const char *file)
|
|||
CHECK_PARAM_POINTER_RETURN("file", file, NULL);
|
||||
|
||||
im = __imlib_LoadImage(file, &ila);
|
||||
ctx->error = ila.err;
|
||||
|
||||
return im;
|
||||
}
|
||||
|
@ -599,18 +609,19 @@ imlib_load_image_fde(const char *file, int *err, int fd)
|
|||
if (ila.fp)
|
||||
{
|
||||
im = __imlib_LoadImage(file, &ila);
|
||||
ctx->error = ila.err;
|
||||
fclose(ila.fp);
|
||||
if (err)
|
||||
*err = ila.err;
|
||||
}
|
||||
else
|
||||
{
|
||||
im = NULL;
|
||||
ctx->error = errno;
|
||||
close(fd);
|
||||
if (err)
|
||||
*err = errno;
|
||||
}
|
||||
|
||||
if (err)
|
||||
*err = ctx->error;
|
||||
|
||||
return im;
|
||||
}
|
||||
|
||||
|
@ -633,6 +644,7 @@ imlib_load_image_mem(const char *file, int *err, const void *data, size_t size)
|
|||
ila.fsize = size;
|
||||
|
||||
im = __imlib_LoadImage(file, &ila);
|
||||
ctx->error = ila.err;
|
||||
|
||||
return im;
|
||||
}
|
||||
|
@ -646,6 +658,7 @@ imlib_load_image_frame(const char *file, int frame)
|
|||
CHECK_PARAM_POINTER_RETURN("file", file, NULL);
|
||||
|
||||
im = __imlib_LoadImage(file, &ila);
|
||||
ctx->error = ila.err;
|
||||
|
||||
return im;
|
||||
}
|
||||
|
@ -664,6 +677,7 @@ imlib_load_image_frame_mem(const char *file, int frame, const void *data,
|
|||
ila.fsize = size;
|
||||
|
||||
im = __imlib_LoadImage(file, &ila);
|
||||
ctx->error = ila.err;
|
||||
|
||||
return im;
|
||||
}
|
||||
|
@ -1879,11 +1893,14 @@ _imlib_save_image(const char *file, int *err)
|
|||
CHECK_PARAM_POINTER("file", file);
|
||||
CAST_IMAGE(im, ctx->image);
|
||||
|
||||
ctx->error = 0;
|
||||
|
||||
if (__imlib_LoadImageData(im))
|
||||
return;
|
||||
|
||||
__imlib_SaveImage(im, file, &ila);
|
||||
*err = ila.err;
|
||||
ctx->error = ila.err;
|
||||
*err = ctx->error;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
|
|
|
@ -41,6 +41,7 @@ typedef struct {
|
|||
Drawable drawable;
|
||||
Pixmap mask;
|
||||
#endif
|
||||
int error;
|
||||
char anti_alias;
|
||||
char dither;
|
||||
char blend;
|
||||
|
|
|
@ -150,10 +150,18 @@ test_load(void)
|
|||
fp = fopen(fileo, "wb");
|
||||
fclose(fp);
|
||||
D("Load empty '%s'\n", fileo);
|
||||
|
||||
im = imlib_load_image(fileo);
|
||||
err = imlib_get_error();
|
||||
EXPECT_FALSE(im);
|
||||
D(" err = %d\n", err);
|
||||
EXPECT_EQ(err, IMLIB_ERR_BAD_IMAGE);
|
||||
|
||||
im = imlib_load_image_with_errno_return(fileo, &err);
|
||||
D(" err = %d\n", err);
|
||||
EXPECT_FALSE(im);
|
||||
EXPECT_EQ(err, IMLIB_ERR_BAD_IMAGE);
|
||||
|
||||
im = imlib_load_image_with_error_return(fileo, &lerr);
|
||||
D(" err = %d\n", lerr);
|
||||
EXPECT_FALSE(im);
|
||||
|
@ -164,10 +172,18 @@ test_load(void)
|
|||
unlink(fileo);
|
||||
symlink("non-existing", fileo);
|
||||
D("Load non-existing '%s'\n", fileo);
|
||||
|
||||
im = imlib_load_image(fileo);
|
||||
EXPECT_FALSE(im);
|
||||
err = imlib_get_error();
|
||||
D(" err = %d\n", err);
|
||||
EXPECT_EQ(err, ENOENT);
|
||||
|
||||
im = imlib_load_image_with_errno_return(fileo, &err);
|
||||
D(" err = %d\n", err);
|
||||
EXPECT_FALSE(im);
|
||||
EXPECT_EQ(err, ENOENT);
|
||||
|
||||
im = imlib_load_image_with_error_return(fileo, &lerr);
|
||||
D(" err = %d\n", lerr);
|
||||
EXPECT_FALSE(im);
|
||||
|
|
Loading…
Reference in New Issue