Subject: bug#46220: Some non-standard O_* flags are missing

From: Maxime Devos <[email-masked]>
Date: Tue, 02 Mar 2021 19:30:01 +0100

Hi guilers,

Attached is a patch that exports O_NOFOLLOW & others
when available.  While testing, I found some weirdness
(kernel: Linux).

$ ./meta/build-env guile
scheme@(guile-user)> O_NOFOLLOW
$1 = 131072
scheme@(guile-user)> O_NOTRANS
$2 = 0
scheme@(guile-user)> O_LARGEFILE
$3 = 0

O_NOFOLLOW is exported as expected.  O_NOTRANS is exported,
even though on the Linux kernel (O_NOTRANS is Hurd-specific).
O_LARGEFILE is 0, which could be correct I suppose, but if
files are opened in large file mode by default I don't really
see a point in defining O_LARGEFILE.

This seems orthogonal to this bug (well, feature request), though.

Greetings,
Maxime.
From 885c0886295eded82188c32b3b5ae52dd08b306c Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Tue, 2 Mar 2021 18:03:22 +0100
Subject: [PATCH] Define `O_NOFOLLOW' and various other flags when supported.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* libguile/filesys.c (scm_init_filesys): Define ‘O_IGNORE_CTTY’,
  ‘O_NOLINK’, ‘O_NOFOLLOW’, ‘O_TMPFILE’, ‘O_SHLOCK’, ‘O_EXLOCK’,
  ‘O_ASYNC’, ‘O_NOATIME’, ‘O_DIRECTORY’, ‘O_CLOEXEC’ and ‘O_DIRECT’
  when available.
---
 libguile/filesys.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/libguile/filesys.c b/libguile/filesys.c
index 1b0af6e14..020c9cf7b 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -1958,9 +1958,42 @@ scm_init_filesys ()
 #ifdef O_LARGEFILE  
   scm_c_define ("O_LARGEFILE", scm_from_int (O_LARGEFILE));
 #endif
+#ifdef O_IGNORE_CTTY
+  scm_c_define ("O_IGNORE_CTTY", scm_from_int (O_IGNORE_CTTY));
+#endif
+#ifdef O_NOLINK
+  scm_c_define ("O_NOLINK", scm_from_int (O_NOLINK));
+#endif
 #ifdef O_NOTRANS
   scm_c_define ("O_NOTRANS", scm_from_int (O_NOTRANS));
 #endif
+#ifdef O_NOFOLLOW
+  scm_c_define ("O_NOFOLLOW", scm_from_int (O_NOFOLLOW));
+#endif
+#ifdef O_TMPFILE
+  scm_c_define ("O_TMPFILE", scm_from_int (O_TMPFILE));
+#endif
+#ifdef O_SHLOCK
+  scm_c_define ("O_SHLOCK", scm_from_int (O_SHLOCK));
+#endif
+#ifdef O_EXLOCK
+  scm_c_define ("O_EXLOCK", scm_from_int (O_EXLOCK));
+#endif
+#ifdef O_ASYNC
+  scm_c_define ("O_ASYNC", scm_from_int (O_ASYNC));
+#endif
+#ifdef O_NOATIME
+  scm_c_define ("O_NOATIME", scm_from_int (O_NOATIME));
+#endif
+#ifdef O_DIRECTORY
+  scm_c_define ("O_DIRECTORY", scm_from_int (O_DIRECTORY));
+#endif
+#ifdef O_CLOEXEC
+  scm_c_define ("O_CLOEXEC", scm_from_int (O_CLOEXEC));
+#endif
+#ifdef O_DIRECT
+  scm_c_define ("O_DIRECT", scm_from_int (O_DIRECT));
+#endif
 
 #ifdef F_DUPFD  
   scm_c_define ("F_DUPFD", scm_from_int (F_DUPFD));
-- 
2.30.1