diff options
Diffstat (limited to 'newlib/libc/sys')
-rw-r--r-- | newlib/libc/sys/linux/Makefile.am | 4 | ||||
-rw-r--r-- | newlib/libc/sys/linux/Makefile.in | 18 | ||||
-rw-r--r-- | newlib/libc/sys/linux/shm_open.c | 48 | ||||
-rw-r--r-- | newlib/libc/sys/linux/shm_unlink.c | 28 | ||||
-rw-r--r-- | newlib/libc/sys/linux/sys/types.h | 4 |
5 files changed, 89 insertions, 13 deletions
diff --git a/newlib/libc/sys/linux/Makefile.am b/newlib/libc/sys/linux/Makefile.am index ad9aed813..b75a41d40 100644 --- a/newlib/libc/sys/linux/Makefile.am +++ b/newlib/libc/sys/linux/Makefile.am @@ -6,14 +6,14 @@ INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) SUBDIRS = machine \ . - SUBLIBS = $(LINUX_MACH_LIB) LIB_SOURCES = \ brk.c flockfile.c funlockfile.c getoptlong.c getreent.c ids.c \ inode.c io.c io64.c linux.c mmap.c \ pread.c pread64.c process.c pwrite.c pwrite64.c raise.c realpath.c \ - sched.c select.c signal.c siglongjmp.c socket.c sleep.c stack.c \ + sched.c select.c shm_open.c shm_unlink.c signal.c siglongjmp.c \ + socket.c sleep.c stack.c \ sysconf.c systat.c system.c tcdrain.c termios.c time.c \ usleep.c wait.c diff --git a/newlib/libc/sys/linux/Makefile.in b/newlib/libc/sys/linux/Makefile.in index c158f2a8a..a61195d38 100644 --- a/newlib/libc/sys/linux/Makefile.in +++ b/newlib/libc/sys/linux/Makefile.in @@ -96,14 +96,14 @@ INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) SUBDIRS = machine \ . - SUBLIBS = $(LINUX_MACH_LIB) LIB_SOURCES = \ brk.c flockfile.c funlockfile.c getoptlong.c getreent.c ids.c \ inode.c io.c io64.c linux.c mmap.c \ pread.c pread64.c process.c pwrite.c pwrite64.c raise.c realpath.c \ - sched.c select.c signal.c siglongjmp.c socket.c sleep.c stack.c \ + sched.c select.c shm_open.c shm_unlink.c signal.c siglongjmp.c \ + socket.c sleep.c stack.c \ sysconf.c systat.c system.c tcdrain.c termios.c time.c \ usleep.c wait.c @@ -139,9 +139,9 @@ LIBS = @LIBS@ @USE_LIBTOOL_FALSE@getoptlong.o getreent.o ids.o inode.o io.o io64.o \ @USE_LIBTOOL_FALSE@linux.o mmap.o pread.o pread64.o process.o pwrite.o \ @USE_LIBTOOL_FALSE@pwrite64.o raise.o realpath.o sched.o select.o \ -@USE_LIBTOOL_FALSE@signal.o siglongjmp.o socket.o sleep.o stack.o \ -@USE_LIBTOOL_FALSE@sysconf.o systat.o system.o tcdrain.o termios.o \ -@USE_LIBTOOL_FALSE@time.o usleep.o wait.o +@USE_LIBTOOL_FALSE@shm_open.o shm_unlink.o signal.o siglongjmp.o \ +@USE_LIBTOOL_FALSE@socket.o sleep.o stack.o sysconf.o systat.o system.o \ +@USE_LIBTOOL_FALSE@tcdrain.o termios.o time.o usleep.o wait.o LTLIBRARIES = $(noinst_LTLIBRARIES) @USE_LIBTOOL_TRUE@liblinux_la_DEPENDENCIES = @@ -149,10 +149,10 @@ LTLIBRARIES = $(noinst_LTLIBRARIES) @USE_LIBTOOL_TRUE@funlockfile.lo getoptlong.lo getreent.lo ids.lo \ @USE_LIBTOOL_TRUE@inode.lo io.lo io64.lo linux.lo mmap.lo pread.lo \ @USE_LIBTOOL_TRUE@pread64.lo process.lo pwrite.lo pwrite64.lo raise.lo \ -@USE_LIBTOOL_TRUE@realpath.lo sched.lo select.lo signal.lo \ -@USE_LIBTOOL_TRUE@siglongjmp.lo socket.lo sleep.lo stack.lo sysconf.lo \ -@USE_LIBTOOL_TRUE@systat.lo system.lo tcdrain.lo termios.lo time.lo \ -@USE_LIBTOOL_TRUE@usleep.lo wait.lo +@USE_LIBTOOL_TRUE@realpath.lo sched.lo select.lo shm_open.lo \ +@USE_LIBTOOL_TRUE@shm_unlink.lo signal.lo siglongjmp.lo socket.lo \ +@USE_LIBTOOL_TRUE@sleep.lo stack.lo sysconf.lo systat.lo system.lo \ +@USE_LIBTOOL_TRUE@tcdrain.lo termios.lo time.lo usleep.lo wait.lo CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) diff --git a/newlib/libc/sys/linux/shm_open.c b/newlib/libc/sys/linux/shm_open.c new file mode 100644 index 000000000..cb92c3ae4 --- /dev/null +++ b/newlib/libc/sys/linux/shm_open.c @@ -0,0 +1,48 @@ +/* shm_open - open a shared memory file */ + +/* Copyright 2002, Red Hat Inc. */ + +#include <sys/types.h> +#include <sys/mman.h> +#include <unistd.h> +#include <string.h> +#include <fcntl.h> +#include <limits.h> + +int +shm_open (const char *name, int oflag, mode_t mode) +{ + int fd; + char shm_name[PATH_MAX+20] = "/dev/shm/"; + + /* skip opening slash */ + if (*name == '/') + ++name; + + /* create special shared memory file name and leave enough space to + cause a path/name error if name is too long */ + strlcpy (shm_name + 9, name, PATH_MAX + 10); + + fd = open (shm_name, oflag, mode); + + if (fd != -1) + { + /* once open we must add FD_CLOEXEC flag to file descriptor */ + int flags = fcntl (fd, F_GETFD, 0); + + if (flags >= 0) + { + flags |= FD_CLOEXEC; + flags = fcntl (fd, F_SETFD, flags); + } + + /* on failure, just close file and give up */ + if (flags == -1) + { + close (fd); + fd = -1; + } + } + + return fd; +} diff --git a/newlib/libc/sys/linux/shm_unlink.c b/newlib/libc/sys/linux/shm_unlink.c new file mode 100644 index 000000000..cf259c627 --- /dev/null +++ b/newlib/libc/sys/linux/shm_unlink.c @@ -0,0 +1,28 @@ +/* shm_unlink - remove a shared memory file */ + +/* Copyright 2002, Red Hat Inc. */ + +#include <sys/types.h> +#include <sys/mman.h> +#include <unistd.h> +#include <string.h> +#include <limits.h> + +int +shm_unlink (const char *name) +{ + int rc; + char shm_name[PATH_MAX+20] = "/dev/shm/"; + + /* skip opening slash */ + if (*name == '/') + ++name; + + /* create special shared memory file name and leave enough space to + cause a path/name error if name is too long */ + strlcpy (shm_name + 9, name, PATH_MAX + 10); + + rc = unlink (shm_name); + + return rc; +} diff --git a/newlib/libc/sys/linux/sys/types.h b/newlib/libc/sys/linux/sys/types.h index e72a7017d..146b8b834 100644 --- a/newlib/libc/sys/linux/sys/types.h +++ b/newlib/libc/sys/linux/sys/types.h @@ -13,13 +13,13 @@ #include <sys/config.h> #include <machine/types.h> -#ifndef __time_t_defined +#if !defined(__time_t_defined) && !defined(_TIME_T) #define _TIME_T #define __time_t_defined typedef _TIME_T_ time_t; #endif -#ifndef __clock_t_defined +#if !defined(__clock_t_defined) && !defined(_CLOCK_T) #define _CLOCK_T #define __clock_t_defined typedef _CLOCK_T_ clock_t; |