[1/6] O_CLOEXEC O_NOFOLLOW O_DIRECTORY O_EXEC O_DIRECT

Message ID 20181008133900.3554-1-sebastian.huber@embedded-brains.de
State New
Headers show
Series
  • [1/6] O_CLOEXEC O_NOFOLLOW O_DIRECTORY O_EXEC O_DIRECT
Related show

Commit Message

Sebastian Huber Oct. 8, 2018, 1:38 p.m.
Make O_CLOEXEC, O_NOFOLLOW, O_DIRECTORY, O_EXEC, and O_DIRECT available
to non-Cygwin systems.

Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>

---
 newlib/libc/include/sys/_default_fcntl.h | 46 ++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 20 deletions(-)

-- 
2.16.4

Comments

Sebastian Huber Oct. 9, 2018, 10:09 a.m. | #1
On 08/10/2018 15:38, Sebastian Huber wrote:
> +#if defined (__CYGWIN__)

>   #define O_BINARY	_FBINARY

>   #define O_TEXT		_FTEXT

>   #define O_DSYNC         _FSYNC

>   #define O_RSYNC         _FSYNC

> -#define O_EXEC          _FEXECSRCH

>   #define O_SEARCH        _FEXECSRCH


I just noticed that O_SEARCH is a POSIX flag as well, so this should 
move out of the Cygwin-specific block too.

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
Corinna Vinschen Oct. 10, 2018, 9:47 a.m. | #2
On Oct  8 15:38, Sebastian Huber wrote:
> Make O_CLOEXEC, O_NOFOLLOW, O_DIRECTORY, O_EXEC, and O_DIRECT available

> to non-Cygwin systems.

> 

> Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>

> ---

>  newlib/libc/include/sys/_default_fcntl.h | 46 ++++++++++++++++++--------------

>  1 file changed, 26 insertions(+), 20 deletions(-)

> 

> diff --git a/newlib/libc/include/sys/_default_fcntl.h b/newlib/libc/include/sys/_default_fcntl.h

> index 33b462285..19fe65cfd 100644

> --- a/newlib/libc/include/sys/_default_fcntl.h

> +++ b/newlib/libc/include/sys/_default_fcntl.h

> @@ -23,6 +23,19 @@ extern "C" {

>  #define	_FNONBLOCK	0x4000	/* non blocking I/O (POSIX style) */

>  #define	_FNDELAY	_FNONBLOCK	/* non blocking I/O (4.2 style) */

>  #define	_FNOCTTY	0x8000	/* don't assign a ctty on this open */

> +#if defined (__CYGWIN__)

> +#define _FBINARY        0x10000

> +#define _FTEXT          0x20000

> +#endif

> +#define _FNOINHERIT	0x40000

> +#define _FDIRECT        0x80000

> +#define _FNOFOLLOW      0x100000

> +#define _FDIRECTORY     0x200000

> +#define _FEXECSRCH      0x400000

> +#if defined (__CYGWIN__)

> +#define _FTMPFILE       0x800000

> +#define _FNOATIME       0x1000000

> +#endif

>  

>  #define	O_ACCMODE	(O_RDONLY|O_WRONLY|O_RDWR)

>  

> @@ -43,35 +56,28 @@ extern "C" {

>  /*	O_NDELAY	_FNBIO 		set in include/fcntl.h */

>  #define	O_NONBLOCK	_FNONBLOCK

>  #define	O_NOCTTY	_FNOCTTY

> -/* For machines which care - */

> -#if defined (__CYGWIN__)

> -#define _FBINARY        0x10000

> -#define _FTEXT          0x20000

> -#define _FNOINHERIT	0x40000

> -#define _FDIRECT        0x80000

> -#define _FNOFOLLOW      0x100000

> -#define _FDIRECTORY     0x200000

> -#define _FEXECSRCH      0x400000

> -#define _FTMPFILE       0x800000

> -#define _FNOATIME       0x1000000

>  

> +/* POSIX-1.2008 specific flags */

> +#if __POSIX_VISIBLE >= 200809

> +#define O_CLOEXEC	_FNOINHERIT

> +#define O_NOFOLLOW	_FNOFOLLOW

> +#define O_DIRECTORY	_FDIRECTORY

> +#define	O_EXEC		_FEXECSRCH

> +#endif

> +

> +#if __GNU_VISIBLE || __BSD_VISIBLE

> +#define O_DIRECT	_FDIRECT

> +#endif


This is actually a BSD flag?  If so, `#if __BSD_VISIBLE' should
suffice since that's implied by setting _GNU_SOURCE.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
Corinna Vinschen Oct. 10, 2018, 9:54 a.m. | #3
On Oct 10 11:47, Corinna Vinschen wrote:
> On Oct  8 15:38, Sebastian Huber wrote:

> > Make O_CLOEXEC, O_NOFOLLOW, O_DIRECTORY, O_EXEC, and O_DIRECT available

> > to non-Cygwin systems.


Btw., for patchset it would be nice to add a cover letter.  It's easier
to follow the thread for comments related to single patches vs. comments
related to the entire series.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
Sebastian Huber Oct. 10, 2018, 11:20 a.m. | #4
On 10/10/2018 11:47, Corinna Vinschen wrote:
> On Oct  8 15:38, Sebastian Huber wrote:

>> Make O_CLOEXEC, O_NOFOLLOW, O_DIRECTORY, O_EXEC, and O_DIRECT available

>> to non-Cygwin systems.

>>

>> Signed-off-by: Sebastian Huber<sebastian.huber@embedded-brains.de>

>> ---

>>   newlib/libc/include/sys/_default_fcntl.h | 46 ++++++++++++++++++--------------

>>   1 file changed, 26 insertions(+), 20 deletions(-)

>>

>> diff --git a/newlib/libc/include/sys/_default_fcntl.h b/newlib/libc/include/sys/_default_fcntl.h

>> index 33b462285..19fe65cfd 100644

>> --- a/newlib/libc/include/sys/_default_fcntl.h

>> +++ b/newlib/libc/include/sys/_default_fcntl.h

>> @@ -23,6 +23,19 @@ extern "C" {

>>   #define	_FNONBLOCK	0x4000	/* non blocking I/O (POSIX style) */

>>   #define	_FNDELAY	_FNONBLOCK	/* non blocking I/O (4.2 style) */

>>   #define	_FNOCTTY	0x8000	/* don't assign a ctty on this open */

>> +#if defined (__CYGWIN__)

>> +#define _FBINARY        0x10000

>> +#define _FTEXT          0x20000

>> +#endif

>> +#define _FNOINHERIT	0x40000

>> +#define _FDIRECT        0x80000

>> +#define _FNOFOLLOW      0x100000

>> +#define _FDIRECTORY     0x200000

>> +#define _FEXECSRCH      0x400000

>> +#if defined (__CYGWIN__)

>> +#define _FTMPFILE       0x800000

>> +#define _FNOATIME       0x1000000

>> +#endif

>>   

>>   #define	O_ACCMODE	(O_RDONLY|O_WRONLY|O_RDWR)

>>   

>> @@ -43,35 +56,28 @@ extern "C" {

>>   /*	O_NDELAY	_FNBIO 		set in include/fcntl.h */

>>   #define	O_NONBLOCK	_FNONBLOCK

>>   #define	O_NOCTTY	_FNOCTTY

>> -/* For machines which care - */

>> -#if defined (__CYGWIN__)

>> -#define _FBINARY        0x10000

>> -#define _FTEXT          0x20000

>> -#define _FNOINHERIT	0x40000

>> -#define _FDIRECT        0x80000

>> -#define _FNOFOLLOW      0x100000

>> -#define _FDIRECTORY     0x200000

>> -#define _FEXECSRCH      0x400000

>> -#define _FTMPFILE       0x800000

>> -#define _FNOATIME       0x1000000

>>   

>> +/* POSIX-1.2008 specific flags */

>> +#if __POSIX_VISIBLE >= 200809

>> +#define O_CLOEXEC	_FNOINHERIT

>> +#define O_NOFOLLOW	_FNOFOLLOW

>> +#define O_DIRECTORY	_FDIRECTORY

>> +#define	O_EXEC		_FEXECSRCH

>> +#endif

>> +

>> +#if __GNU_VISIBLE || __BSD_VISIBLE

>> +#define O_DIRECT	_FDIRECT

>> +#endif

> This is actually a BSD flag?  If so, `#if __BSD_VISIBLE' should

> suffice since that's implied by setting _GNU_SOURCE.


The O_DIRECT is documented in the FreeBSD man page:

https://www.freebsd.org/cgi/man.cgi?sektion=2&query=open

The guard is __BSD_VISIBLE:

https://github.com/freebsd/freebsd/blob/master/sys/sys/fcntl.h#L116

I will change this to use __BSD_VISIBLE only.

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

Patch

diff --git a/newlib/libc/include/sys/_default_fcntl.h b/newlib/libc/include/sys/_default_fcntl.h
index 33b462285..19fe65cfd 100644
--- a/newlib/libc/include/sys/_default_fcntl.h
+++ b/newlib/libc/include/sys/_default_fcntl.h
@@ -23,6 +23,19 @@  extern "C" {
 #define	_FNONBLOCK	0x4000	/* non blocking I/O (POSIX style) */
 #define	_FNDELAY	_FNONBLOCK	/* non blocking I/O (4.2 style) */
 #define	_FNOCTTY	0x8000	/* don't assign a ctty on this open */
+#if defined (__CYGWIN__)
+#define _FBINARY        0x10000
+#define _FTEXT          0x20000
+#endif
+#define _FNOINHERIT	0x40000
+#define _FDIRECT        0x80000
+#define _FNOFOLLOW      0x100000
+#define _FDIRECTORY     0x200000
+#define _FEXECSRCH      0x400000
+#if defined (__CYGWIN__)
+#define _FTMPFILE       0x800000
+#define _FNOATIME       0x1000000
+#endif
 
 #define	O_ACCMODE	(O_RDONLY|O_WRONLY|O_RDWR)
 
@@ -43,35 +56,28 @@  extern "C" {
 /*	O_NDELAY	_FNBIO 		set in include/fcntl.h */
 #define	O_NONBLOCK	_FNONBLOCK
 #define	O_NOCTTY	_FNOCTTY
-/* For machines which care - */
-#if defined (__CYGWIN__)
-#define _FBINARY        0x10000
-#define _FTEXT          0x20000
-#define _FNOINHERIT	0x40000
-#define _FDIRECT        0x80000
-#define _FNOFOLLOW      0x100000
-#define _FDIRECTORY     0x200000
-#define _FEXECSRCH      0x400000
-#define _FTMPFILE       0x800000
-#define _FNOATIME       0x1000000
 
+/* POSIX-1.2008 specific flags */
+#if __POSIX_VISIBLE >= 200809
+#define O_CLOEXEC	_FNOINHERIT
+#define O_NOFOLLOW	_FNOFOLLOW
+#define O_DIRECTORY	_FDIRECTORY
+#define	O_EXEC		_FEXECSRCH
+#endif
+
+#if __GNU_VISIBLE || __BSD_VISIBLE
+#define O_DIRECT	_FDIRECT
+#endif
+
+#if defined (__CYGWIN__)
 #define O_BINARY	_FBINARY
 #define O_TEXT		_FTEXT
 #define O_DSYNC         _FSYNC
 #define O_RSYNC         _FSYNC
-#define O_EXEC          _FEXECSRCH
 #define O_SEARCH        _FEXECSRCH
 
-/* POSIX-1.2008 specific flags */
-#if __POSIX_VISIBLE >= 200809
-#define O_CLOEXEC	_FNOINHERIT
-#define O_NOFOLLOW      _FNOFOLLOW
-#define O_DIRECTORY     _FDIRECTORY
-#endif
-
 /* Linux-specific flags */
 #if __GNU_VISIBLE
-#define O_DIRECT        _FDIRECT
 #define O_TMPFILE	_FTMPFILE
 #define O_NOATIME	_FNOATIME
 #endif