From 40b07f5b942d6af4d575274853331590d2ee8ab3 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Thu, 8 Nov 2001 01:48:57 +0000 Subject: Update. * sysdeps/generic/dl-cache.c: Optimize SEARCH_CACHE and HWCAP_CHECK macro code. * elf/dl-misc.c (_dl_sysdep_read_whole_file): Optimize code a bit. Now returns MAP_FAILED on error. * elf/rtld.c: Adjust caller. * sysdeps/generic/dl-cache.c: Likewise. * sysdeps/generic/ldsodefs.h: Adjust description. --- elf/dl-misc.c | 38 ++++++++++++++++++-------------------- elf/rtld.c | 2 +- 2 files changed, 19 insertions(+), 21 deletions(-) (limited to 'elf') diff --git a/elf/dl-misc.c b/elf/dl-misc.c index f1abfb7f29..a96689edf7 100644 --- a/elf/dl-misc.c +++ b/elf/dl-misc.c @@ -44,40 +44,38 @@ _dl_sysdep_open_zero_fill (void) #endif /* Read the whole contents of FILE into new mmap'd space with given - protections. *SIZEP gets the size of the file. */ + protections. *SIZEP gets the size of the file. On error MAP_FAILED + is returned. */ void * internal_function _dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot) { - void *result; + void *result = MAP_FAILED; struct stat64 st; int fd = __open (file, O_RDONLY); - if (fd < 0) - return NULL; - if (__fxstat64 (_STAT_VER, fd, &st) < 0 - /* No need to map the file if it is empty. */ - || st.st_size == 0) - result = NULL; - else + if (fd >= 0) { - /* Map a copy of the file contents. */ - result = __mmap (0, st.st_size, prot, + if (__fxstat64 (_STAT_VER, fd, &st) >= 0) + { + *sizep = st.st_size; + + /* No need to map the file if it is empty. */ + if (*sizep != 0) + /* Map a copy of the file contents. */ + result = __mmap (NULL, *sizep, prot, #ifdef MAP_COPY - MAP_COPY + MAP_COPY #else - MAP_PRIVATE + MAP_PRIVATE #endif #ifdef MAP_FILE - | MAP_FILE + | MAP_FILE #endif - , fd, 0); - if (result == MAP_FAILED) - result = NULL; - else - *sizep = st.st_size; + , fd, 0); + } + __close (fd); } - __close (fd); return result; } diff --git a/elf/rtld.c b/elf/rtld.c index 2d2befc627..8ed86eaedb 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -710,7 +710,7 @@ of this helper program; chances are you did not intend to run this program.\n\ /* Read the contents of the file. */ file = _dl_sysdep_read_whole_file ("/etc/ld.so.preload", &file_size, PROT_READ | PROT_WRITE); - if (__builtin_expect (file != NULL, 0)) + if (__builtin_expect (file != MAP_FAILED, 0)) { /* Parse the file. It contains names of libraries to be loaded, separated by white spaces or `:'. It may also contain -- cgit 1.4.1