This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v2 1/2] Avoid duplication of _CLOEXEC and _NONBLOCK values


The following patch adds bits/kernel-defines.h which defines __O_NONBLOCK and
__O_CLOEXEC. The files in bits and sys redefining _CLOEXEC and _NONBLOCK have
been updated to include this new file and use it's values.
This allows arch with different values in the kernel to only copy
bits/kernel-defines.h and not all the headers.
In libc, sparc will benefit from it. In libc-ports, mips, alpha and hppa will.

Compared to the initial patch, this v2 doesn't pollute name space and only adds
a single small file. This file can probably be extended later for other arch
specific values.

2010-08-23  Guy Martin  <gmsoft@tuxicoman.be>

	* sysdeps/unix/sysv/linux/bits/kernel-defines.h: New file. Defines
	__O_CLOEXEC and __O_NONBLOCK with common values across most arches.
	* sysdeps/unix/sysv/linux/bits/socket.h : Update SOCK_CLOEXEC and
	SOCK_NONBLOCK to use __O_CLOEXEC and __O_NONBLOCK respectively.
	*sysdeps/unix/sysv/linux/sys/epoll.h: Likewise for EPOLL_CLOEXEC and
	EPOLL_NONBLOCK.
	* sysdeps/unix/sysv/linux/sys/eventfd.h: Likewise for EFD_CLOEXEC and
	EFD_NONBLOCK.
	* sysdeps/unix/sysv/linux/sys/inotify.h: Likewise for IN_CLOEXEC and
	IN_NONBLOCK.
	* sysdeps/unix/sysv/linux/sys/signalfd.h: Likewise for SDF_CLOEXEC and
	SFD_NONBLOCK.
	* sysdeps/unix/sysv/linux/sys/timerfd.h: Likewise for TFD_CLOEXEC and
	TFD_NONBLOCK.


Signed-off-by: Guy Martin <gmsoft@tuxicoman.be>

---
diff --git a/sysdeps/unix/sysv/linux/bits/kernel-defines.h b/sysdeps/unix/sysv/linux/bits/kernel-defines.h
new file mode 100644
index 0000000..681d391
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/bits/kernel-defines.h
@@ -0,0 +1,26 @@
+/* Linux kernel defined values.
+   Copyright (C) 2010 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef __BITS_KERNEL_DEFINES
+#define __BITS_KERNEL_DEFINES
+
+#define __O_NONBLOCK    04000
+#define __O_CLOEXEC  02000000	/* Set close_on_exec.  */
+
+#endif
diff --git a/sysdeps/unix/sysv/linux/bits/socket.h b/sysdeps/unix/sysv/linux/bits/socket.h
index dba3a39..5bf4af6 100644
--- a/sysdeps/unix/sysv/linux/bits/socket.h
+++ b/sysdeps/unix/sysv/linux/bits/socket.h
@@ -29,6 +29,7 @@
 #include <stddef.h>
 
 #include <sys/types.h>
+#include <bits/kernel-defines.h>
 
 /* Type for length arguments in socket calls.  */
 #ifndef __socklen_t_defined
@@ -62,10 +63,10 @@ enum __socket_type
   /* Flags to be ORed into the type parameter of socket and socketpair and
      used for the flags parameter of paccept.  */
 
-  SOCK_CLOEXEC = 02000000,	/* Atomically set close-on-exec flag for the
+  SOCK_CLOEXEC = __O_CLOEXEC,	/* Atomically set close-on-exec flag for the
 				   new descriptor(s).  */
 #define SOCK_CLOEXEC SOCK_CLOEXEC
-  SOCK_NONBLOCK = 04000		/* Atomically mark descriptor(s) as
+  SOCK_NONBLOCK = __O_NONBLOCK	/* Atomically mark descriptor(s) as
 				   non-blocking.  */
 #define SOCK_NONBLOCK SOCK_NONBLOCK
 };
diff --git a/sysdeps/unix/sysv/linux/sys/epoll.h b/sysdeps/unix/sysv/linux/sys/epoll.h
index ca1d3d0..5d42df9 100644
--- a/sysdeps/unix/sysv/linux/sys/epoll.h
+++ b/sysdeps/unix/sysv/linux/sys/epoll.h
@@ -21,6 +21,7 @@
 
 #include <stdint.h>
 #include <sys/types.h>
+#include <bits/kernel-defines.h>
 
 /* Get __sigset_t.  */
 #include <bits/sigset.h>
@@ -34,9 +35,9 @@ typedef __sigset_t sigset_t;
 /* Flags to be passed to epoll_create1.  */
 enum
   {
-    EPOLL_CLOEXEC = 02000000,
+    EPOLL_CLOEXEC = __O_CLOEXEC,
 #define EPOLL_CLOEXEC EPOLL_CLOEXEC
-    EPOLL_NONBLOCK = 04000
+    EPOLL_NONBLOCK = __O_NONBLOCK
 #define EPOLL_NONBLOCK EPOLL_NONBLOCK
   };
 
diff --git a/sysdeps/unix/sysv/linux/sys/eventfd.h b/sysdeps/unix/sysv/linux/sys/eventfd.h
index d942df4..da76bab 100644
--- a/sysdeps/unix/sysv/linux/sys/eventfd.h
+++ b/sysdeps/unix/sysv/linux/sys/eventfd.h
@@ -20,6 +20,7 @@
 #define	_SYS_EVENTFD_H	1
 
 #include <stdint.h>
+#include <bits/kernel-defines.h>
 
 
 /* Type for event counter.  */
@@ -30,9 +31,9 @@ enum
   {
     EFD_SEMAPHORE = 1,
 #define EFD_SEMAPHORE EFD_SEMAPHORE
-    EFD_CLOEXEC = 02000000,
+    EFD_CLOEXEC = __O_CLOEXEC,
 #define EFD_CLOEXEC EFD_CLOEXEC
-    EFD_NONBLOCK = 04000
+    EFD_NONBLOCK = __O_NONBLOCK
 #define EFD_NONBLOCK EFD_NONBLOCK
   };
 
diff --git a/sysdeps/unix/sysv/linux/sys/inotify.h b/sysdeps/unix/sysv/linux/sys/inotify.h
index aee999a..d887949 100644
--- a/sysdeps/unix/sysv/linux/sys/inotify.h
+++ b/sysdeps/unix/sysv/linux/sys/inotify.h
@@ -20,14 +20,15 @@
 #define	_SYS_INOTIFY_H	1
 
 #include <stdint.h>
+#include <bits/kernel-defines.h>
 
 
 /* Flags for the parameter of inotify_init1.  */
 enum
   {
-    IN_CLOEXEC = 02000000,
+    IN_CLOEXEC = __O_CLOEXEC,
 #define IN_CLOEXEC IN_CLOEXEC
-    IN_NONBLOCK = 04000
+    IN_NONBLOCK = __O_NONBLOCK
 #define IN_NONBLOCK IN_NONBLOCK
   };
 
diff --git a/sysdeps/unix/sysv/linux/sys/signalfd.h b/sysdeps/unix/sysv/linux/sys/signalfd.h
index eeb27ee..9a46669 100644
--- a/sysdeps/unix/sysv/linux/sys/signalfd.h
+++ b/sysdeps/unix/sysv/linux/sys/signalfd.h
@@ -22,6 +22,7 @@
 #define __need_sigset_t
 #include <signal.h>
 #include <stdint.h>
+#include <bits/kernel-defines.h>
 
 
 struct signalfd_siginfo
@@ -48,9 +49,9 @@ struct signalfd_siginfo
 /* Flags for signalfd.  */
 enum
   {
-    SFD_CLOEXEC = 02000000,
+    SFD_CLOEXEC = __O_CLOEXEC,
 #define SFD_CLOEXEC SFD_CLOEXEC
-    SFD_NONBLOCK = 04000
+    SFD_NONBLOCK = __O_NONBLOCK
 #define SFD_NONBLOCK SFD_NONBLOCK
   };
 
diff --git a/sysdeps/unix/sysv/linux/sys/timerfd.h b/sysdeps/unix/sysv/linux/sys/timerfd.h
index c1bb06f..88baa9e 100644
--- a/sysdeps/unix/sysv/linux/sys/timerfd.h
+++ b/sysdeps/unix/sysv/linux/sys/timerfd.h
@@ -20,14 +20,15 @@
 #define	_SYS_TIMERFD_H	1
 
 #include <time.h>
+#include <bits/kernel-defines.h>
 
 
 /* Bits to be set in the FLAGS parameter of `timerfd_create'.  */
 enum
   {
-    TFD_CLOEXEC = 02000000,
+    TFD_CLOEXEC = __O_CLOEXEC,
 #define TFD_CLOEXEC TFD_CLOEXEC
-    TFD_NONBLOCK = 04000
+    TFD_NONBLOCK = __O_NONBLOCK
 #define TFD_NONBLOCK TFD_NONBLOCK
   };
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]