loadfile: make sure we don't trash errno
authorH. Peter Anvin <hpa@zytor.com>
Mon, 16 Jun 2008 00:03:18 +0000 (17:03 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Mon, 16 Jun 2008 00:03:18 +0000 (17:03 -0700)
Make sure we don't trash a useful value in errno.

com32/lib/syslinux/loadfile.c

index 42a1fd6..7ad8e81 100644 (file)
@@ -31,6 +31,7 @@
  * Read the contents of a data file into a malloc'd buffer
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 int loadfile(const char *filename, void **ptr, size_t *len)
 {
   FILE *f;
-  int rv;
+  int rv, e;
 
   f = fopen(filename, "r");
   if ( !f )
     return -1;
 
   rv = floadfile(f, ptr, len, NULL, 0);
+  e = errno;
+
   fclose(f);
 
+  if (rv)
+    errno = e;
   return rv;
 }