about summary refs log tree commit diff
path: root/io
diff options
context:
space:
mode:
Diffstat (limited to 'io')
-rw-r--r--io/bits/fcntl2.h74
1 files changed, 48 insertions, 26 deletions
diff --git a/io/bits/fcntl2.h b/io/bits/fcntl2.h
index 25ca4110b3..a1b03f6194 100644
--- a/io/bits/fcntl2.h
+++ b/io/bits/fcntl2.h
@@ -24,7 +24,7 @@
 /* Check that calls to open and openat with O_CREAT set have an
    appropriate third/fourth parameter.  */
 #ifndef __USE_FILE_OFFSET64
-extern int __open_2 (__const char *__path, int __oflag);
+extern int __open_2 (__const char *__path, int __oflag) __nonnull ((1));
 #else
 extern int __REDIRECT (__open_2, (__const char *__file, int __oflag),
 		       __open64_2) __nonnull ((1));
@@ -33,22 +33,27 @@ extern int __REDIRECT (__open_2, (__const char *__file, int __oflag),
 #define open(fname, flags, ...) \
   ({ int ___r;								      \
      /* If the compiler complains about an invalid type, excess elements, etc \
-	in the initialization this means a paraleter of the wrong type has    \
+	in the initialization this means a parameter of the wrong type has    \
 	been passed to open. */						      \
      int ___arr[] = { __VA_ARGS__ };					      \
      if (__builtin_constant_p (flags) && ((flags) & O_CREAT) != 0)	      \
        {								      \
-	 /* If the compile complains about the size of this array type the    \
-	    the mode parameter is missing since O_CREAT has been used.  */    \
+	 /* If the compiler complains about the size of this array type the   \
+	    mode parameter is missing since O_CREAT has been used.  */	      \
 	 typedef int __open_missing_mode[((flags) & O_CREAT) != 0	      \
 					 ? ((long int) sizeof (___arr)	      \
 					    - (long int) sizeof (int)) : 1];  \
        }								      \
      if (sizeof (___arr) == 0)						      \
-       ___r = __open_2 (fname, flags);					      \
+       {								      \
+	 if (__builtin_constant_p (flags) && ((flags) & O_CREAT) == 0)	      \
+	   ___r = open (fname, flags);					      \
+	 else     							      \
+	   ___r = __open_2 (fname, flags);				      \
+       }								      \
      else								      \
        {								      \
-	 /* If the compile complains about the size of this array type too    \
+	 /* If the compiler complains about the size of this array type too   \
 	    many parameters have been passed to open.  */		      \
 	 typedef int __open_too_many_args[-(sizeof (___arr) > sizeof (int))]; \
 	 ___r = open (fname, flags, ___arr[0]);				      \
@@ -58,27 +63,32 @@ extern int __REDIRECT (__open_2, (__const char *__file, int __oflag),
 
 
 #ifdef __USE_LARGEFILE64
-extern int __open64_2 (__const char *__path, int __oflag);
+extern int __open64_2 (__const char *__path, int __oflag) __nonnull ((1));
 
 # define open64(fname, flags, ...) \
   ({ int ___r;								      \
      /* If the compiler complains about an invalid type, excess elements, etc \
-	in the initialization this means a paraleter of the wrong type has    \
+	in the initialization this means a parameter of the wrong type has    \
 	been passed to open64. */					      \
      int ___arr[] = { __VA_ARGS__ };					      \
      if (__builtin_constant_p (flags) && ((flags) & O_CREAT) != 0)	      \
        {								      \
-	 /* If the compile complains about the size of this array type the    \
-	    the mode parameter is missing since O_CREAT has been used.  */    \
+	 /* If the compiler complains about the size of this array type the   \
+	    mode parameter is missing since O_CREAT has been used.  */	      \
 	 typedef int __open_missing_mode[((flags) & O_CREAT) != 0	      \
 					 ? ((long int) sizeof (___arr)	      \
 					    - (long int) sizeof (int)) : 1];  \
        }								      \
      if (sizeof (___arr) == 0)						      \
-       ___r = __open64_2 (fname, flags);				      \
+       {								      \
+	 if (__builtin_constant_p (flags) && ((flags) & O_CREAT) == 0)	      \
+	   ___r = open64 (fname, flags);				      \
+	 else     							      \
+	   ___r = __open64_2 (fname, flags);				      \
+       }								      \
      else								      \
        {								      \
-	 /* If the compile complains about the size of this array type too    \
+	 /* If the compiler complains about the size of this array type too   \
 	    many parameters have been passed to open64.  */		      \
 	 typedef int __open_too_many_args[-(sizeof (___arr) > sizeof (int))]; \
 	 ___r = open64 (fname, flags, ___arr[0]);			      \
@@ -89,32 +99,38 @@ extern int __open64_2 (__const char *__path, int __oflag);
 
 #ifdef __USE_ATFILE
 # ifndef __USE_FILE_OFFSET64
-extern int __openat_2 (int __fd, __const char *__path, int __oflag);
+extern int __openat_2 (int __fd, __const char *__path, int __oflag)
+     __nonnull ((2));
 # else
 extern int __REDIRECT (__openat_2, (int __fd, __const char *__file,
 				    int __oflag), __openat64_2)
-     __nonnull ((1));
+     __nonnull ((2));
 # endif
 
 # define openat(fd, fname, flags, ...) \
   ({ int ___r;								      \
      /* If the compiler complains about an invalid type, excess elements, etc \
-	in the initialization this means a paraleter of the wrong type has    \
+	in the initialization this means a parameter of the wrong type has    \
 	been passed to openat. */					      \
      int ___arr[] = { __VA_ARGS__ };					      \
      if (__builtin_constant_p (flags) && ((flags) & O_CREAT) != 0)	      \
        {								      \
-	 /* If the compile complains about the size of this array type the    \
-	    the mode parameter is missing since O_CREAT has been used.  */    \
+	 /* If the compiler complains about the size of this array type the   \
+	    mode parameter is missing since O_CREAT has been used.  */	      \
 	 typedef int __open_missing_mode[((flags) & O_CREAT) != 0	      \
 					 ? ((long int) sizeof (___arr)	      \
 					    - (long int) sizeof (int)) : 1];  \
        }								      \
      if (sizeof (___arr) == 0)						      \
-       ___r = __openat_2 (fd, fname, flags);				      \
+       {								      \
+	 if (__builtin_constant_p (flags) && ((flags) & O_CREAT) == 0)	      \
+	   ___r = openat (fd, fname, flags);				      \
+	 else     							      \
+	   ___r = __openat_2 (fd, fname, flags);			      \
+       }								      \
      else								      \
        {								      \
-	 /* If the compile complains about the size of this array type too    \
+	 /* If the compiler complains about the size of this array type too   \
 	    many parameters have been passed to openat.  */		      \
 	 typedef int __open_too_many_args[-(sizeof (___arr) > sizeof (int))]; \
 	 ___r = openat (fd, fname, flags, ___arr[0]);			      \
@@ -124,28 +140,34 @@ extern int __REDIRECT (__openat_2, (int __fd, __const char *__file,
 
 
 # ifdef __USE_LARGEFILE64
-extern int __openat64_2 (int __fd, __const char *__path, int __oflag);
+extern int __openat64_2 (int __fd, __const char *__path, int __oflag)
+     __nonnull ((2));
 
 #  define openat64(fd, fname, flags, ...) \
   ({ int ___r;								      \
      /* If the compiler complains about an invalid type, excess elements, etc \
-	in the initialization this means a paraleter of the wrong type has    \
+	in the initialization this means a parameter of the wrong type has    \
 	been passed to openat64. */					      \
      int ___arr[] = { __VA_ARGS__ };					      \
      if (__builtin_constant_p (flags) && ((flags) & O_CREAT) != 0)	      \
        {								      \
-	 /* If the compile complains about the size of this array type the    \
-	    the mode parameter is missing since O_CREAT has been used.  */    \
+	 /* If the compiler complains about the size of this array type the   \
+	    mode parameter is missing since O_CREAT has been used.  */	      \
 	 typedef int __open_missing_mode[((flags) & O_CREAT) != 0	      \
 					 ? ((long int) sizeof (___arr)	      \
 					    - (long int) sizeof (int)) : 1];  \
        }								      \
      if (sizeof (___arr) == 0)						      \
-       ___r = __openat64_2 (fd, fname, flags);				      \
+       {								      \
+	 if (__builtin_constant_p (flags) && ((flags) & O_CREAT) == 0)	      \
+	   ___r = openat64 (fd, fname, flags);				      \
+	 else     							      \
+	   ___r = __openat64_2 (fd, fname, flags);			      \
+       }								      \
      else								      \
        {								      \
-	 /* If the compile complains about the size of this array type too    \
-	    many parameters have been passed to openat.  */		      \
+	 /* If the compiler complains about the size of this array type too   \
+	    many parameters have been passed to openat64.  */		      \
 	 typedef int __open_too_many_args[-(sizeof (___arr) > sizeof (int))]; \
 	 ___r = openat64 (fd, fname, flags, ___arr[0]);			      \
        }								      \