This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository legacy-imlib2.

View the commit online.

commit cea1207efefacb9fea0c6a013190a741fc8d655e
Author: Kim Woelders <[email protected]>
AuthorDate: Mon Apr 25 14:08:19 2022 +0200

    Introduce imlib_load_image_fde()
    
    Same as imlib_load_image_fd() but with error return.
---
 src/lib/Imlib2.h.in | 20 ++++++++++++++++++++
 src/lib/api.c       | 12 +++++++++++-
 test/test_load.cpp  |  5 +++--
 3 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/src/lib/Imlib2.h.in b/src/lib/Imlib2.h.in
index b3b7a05..c678147 100644
--- a/src/lib/Imlib2.h.in
+++ b/src/lib/Imlib2.h.in
@@ -816,6 +816,26 @@ EAPI Imlib_Image    imlib_load_image_with_errno_return(const char *file,
  */
 EAPI Imlib_Image    imlib_load_image_fd(int fd, const char *file);
 
+/**
+ * Read an image from file descriptor with error return
+ *
+ * Same as imlib_load_image_fd() but with error return.
+ *
+ * On error @p error_return is set to the detail of the error.
+ * error values:
+ *          0: Success,
+ *   positive: Regular errnos,
+ *   negative: IMLIB_ERR_... values, see above
+ *
+ * @param file          File name
+ * @param error_return  The returned error
+ * @param fd            Image file descriptor
+ *
+ * @return Image handle (NULL on failure)
+ */
+EAPI Imlib_Image    imlib_load_image_fde(const char *file, int *error_return,
+                                         int fd);
+
 /**
  * Free the current image
  */
diff --git a/src/lib/api.c b/src/lib/api.c
index 51f0a28..530b8e3 100644
--- a/src/lib/api.c
+++ b/src/lib/api.c
@@ -857,7 +857,7 @@ imlib_load_image_with_errno_return(const char *file, int *error_return)
 }
 
 EAPI                Imlib_Image
-imlib_load_image_fd(int fd, const char *file)
+imlib_load_image_fde(const char *file, int *err, int fd)
 {
    Imlib_Image         im;
    ImlibLoadArgs       ila = { ILA0(ctx, 1, 1) };
@@ -869,16 +869,26 @@ imlib_load_image_fd(int fd, const char *file)
      {
         im = __imlib_LoadImage(file, &ila);
         fclose(ila.fp);
+        if (err)
+           *err = ila.err;
      }
    else
      {
         im = NULL;
         close(fd);
+        if (err)
+           *err = errno;
      }
 
    return im;
 }
 
+EAPI                Imlib_Image
+imlib_load_image_fd(int fd, const char *file)
+{
+   return imlib_load_image_fde(file, NULL, fd);
+}
+
 EAPI                Imlib_Image
 imlib_load_image_frame(const char *file, int frame)
 {
diff --git a/test/test_load.cpp b/test/test_load.cpp
index c4c999a..641f470 100644
--- a/test/test_load.cpp
+++ b/test/test_load.cpp
@@ -178,12 +178,13 @@ test_load(void)
         fd = open(fileo, O_RDONLY);
         D("Load fd %d '%s'\n", fd, fileo);
         snprintf(fileo, sizeof(fileo), ".%s", pfxs[i]);
-        im = imlib_load_image_fd(fd, pfxs[i]);
+        im = imlib_load_image_fde(pfxs[i], &err, fd);
         EXPECT_TRUE(im);
         if (im)
            image_free(im);
+        EXPECT_EQ(err, 0);
         err = close(fd);
-        EXPECT_TRUE(err != 0);
+        EXPECT_NE(err, 0);
      }
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to