summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-06-15 17:03:18 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-06-15 17:03:18 -0700
commit99d175aa34800b281c65210ce436cf0a423906fc (patch)
treefd1fe0ae368cf338b07fcd457956955e371b3d23
parentd8f1d5b4731228689b6badd0b34720c3dc9eeeed (diff)
downloadsyslinux-99d175aa34800b281c65210ce436cf0a423906fc.tar.gz
loadfile: make sure we don't trash errno
Make sure we don't trash a useful value in errno.
-rw-r--r--com32/lib/syslinux/loadfile.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/com32/lib/syslinux/loadfile.c b/com32/lib/syslinux/loadfile.c
index 42a1fd61..7ad8e817 100644
--- a/com32/lib/syslinux/loadfile.c
+++ b/com32/lib/syslinux/loadfile.c
@@ -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>
@@ -45,14 +46,18 @@
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;
}