aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1996-07-15 00:05:56 +0000
committerRoland McGrath <roland@gnu.org>1996-07-15 00:05:56 +0000
commit2d3bbb8c67ce04adca32c1f99cedafcedb08093a (patch)
treec6914f584c47c36cdde4a188c914e0f8f451c7b8 /sysdeps
parent939d5646d18b178c5a46aa38a0c77b311dbbcb1a (diff)
downloadglibc-2d3bbb8c67ce04adca32c1f99cedafcedb08093a.zip
glibc-2d3bbb8c67ce04adca32c1f99cedafcedb08093a.tar.gz
glibc-2d3bbb8c67ce04adca32c1f99cedafcedb08093a.tar.bz2
Sun Jul 14 01:51:39 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* sysdeps/generic/dl-sysdep.c (_dl_sysdep_read_whole_file): New fn.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/generic/dl-sysdep.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/sysdeps/generic/dl-sysdep.c b/sysdeps/generic/dl-sysdep.c
index 8f9e782..579054d 100644
--- a/sysdeps/generic/dl-sysdep.c
+++ b/sysdeps/generic/dl-sysdep.c
@@ -19,6 +19,7 @@ Cambridge, MA 02139, USA. */
#include <elf.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <fcntl.h>
#include <link.h>
#include <unistd.h>
@@ -108,7 +109,7 @@ void
_dl_sysdep_start_cleanup (void)
{
}
-
+
#ifndef MAP_ANON
/* This is only needed if the system doesn't support MAP_ANON. */
@@ -119,6 +120,41 @@ _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. */
+
+void *
+_dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot)
+{
+ void *contents;
+ struct stat st;
+ int fd = __open (file, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+ if (__fstat (fd, &st) < 0)
+ result = NULL;
+ else
+ {
+ /* Map a copy of the file contents. */
+ result = __mmap (0, st.st_size, prot,
+#ifdef MAP_COPY
+ MAP_COPY
+#else
+ MAP_PRIVATE
+#endif
+#ifdef MAP_FILE
+ | MAP_FILE
+#endif
+ , fd, 0);
+ if (result == (void *) -1)
+ result = NULL;
+ else
+ *sizep = st.st_size;
+ }
+ __close (fd);
+ return result;
+}
+
void
_dl_sysdep_fatal (const char *msg, ...)
{