]> git.imager.perl.org - imager.git/commitdiff
- handle the possibility of strerror() returning NULL.
authorTony Cook <tony@develop=help.com>
Fri, 27 Jan 2006 03:09:59 +0000 (03:09 +0000)
committerTony Cook <tony@develop=help.com>
Fri, 27 Jan 2006 03:09:59 +0000 (03:09 +0000)
Changes
iolayer.c

diff --git a/Changes b/Changes
index 7a6d86ce74e3cfbbfd472736800f410ba1716e9d..8d27eb37058d2ec8a132999e02e339d482ece1a7 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1314,6 +1314,7 @@ Revision history for Perl extension Imager.
 - added typemap type names to types in Imager::API.
 - make skip when Inline::C not available less verbose
 - convert t/t07iolayer.t to Test::More
+- handle the possibility of strerror() returning NULL.
 
 =================================================================
 
index a425bff8a10ca140620e43e8c1662b73345474c4..b98494bc9c208c7781ef847800efd962e049acbc 100644 (file)
--- a/iolayer.c
+++ b/iolayer.c
@@ -64,6 +64,7 @@ static ssize_t fd_write(io_glue *ig, const void *buf, size_t count);
 static off_t fd_seek(io_glue *ig, off_t offset, int whence);
 static void fd_close(io_glue *ig);
 static ssize_t fd_size(io_glue *ig);
+static const char *my_strerror(int err);
 
 /*
  * Callbacks for sources that cannot seek
@@ -1073,7 +1074,7 @@ static ssize_t fd_read(io_glue *ig, void *buf, size_t count) {
 
   /* 0 is valid - means EOF */
   if (result < 0) {
-    i_push_errorf(0, "read() failure: %s (%d)", strerror(errno), errno);
+    i_push_errorf(0, "read() failure: %s (%d)", my_strerror(errno), errno);
   }
 
   return result;
@@ -1088,7 +1089,7 @@ static ssize_t fd_write(io_glue *ig, const void *buf, size_t count) {
 #endif
 
   if (result <= 0) {
-    i_push_errorf(errno, "write() failure: %s (%d)", strerror(errno), errno);
+    i_push_errorf(errno, "write() failure: %s (%d)", my_strerror(errno), errno);
   }
 
   return result;
@@ -1103,7 +1104,7 @@ static off_t fd_seek(io_glue *ig, off_t offset, int whence) {
 #endif
 
   if (result == (off_t)-1) {
-    i_push_errorf(errno, "lseek() failure: %s (%d)", strerror(errno), errno);
+    i_push_errorf(errno, "lseek() failure: %s (%d)", my_strerror(errno), errno);
   }
 
   return result;
@@ -1167,6 +1168,32 @@ io_glue_DESTROY(io_glue *ig) {
   myfree(ig);
 }
 
+/*
+=back
+
+=head1 INTERNAL FUNCTIONS
+
+=over
+
+=item my_strerror
+
+Calls strerror() and ensures we don't return NULL.
+
+On some platforms it's possible for strerror() to return NULL, this
+wrapper ensures we only get non-NULL values.
+
+=cut
+*/
+
+static
+const char *my_strerror(int err) {
+  const char *result = strerror(err);
+
+  if (!result)
+    result = "Unknown error";
+
+  return result;
+}
 
 /*
 =back