Skip to contentSkip to conversation

include libgen.h for basename API prototype

PATCH In review Khem Raj 2 participants 4 messages Mar 25, 2024 – Mar 26, 2024

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/2 include libgen.h for basename API prototype

basename prototype has been removed from string.h from latest musl [1] compilers e.g. clang-18 flags the absense of prototype as error. therefore include libgen.h for providing it.

[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7

---
 src/splice-test.c                   | 1 +
 src/stat_test.c                     | 1 +
 src/t_ext4_dax_inline_corruption.c  | 1 +
 src/t_ext4_dax_journal_corruption.c | 1 +
 src/t_mmap_collision.c              | 1 +
 5 files changed, 5 insertions(+)
src/splice-test.c +1 -0
index eb863673..7b7094f5 100644
@@ -11,6 +11,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <err.h>
+#include <libgen.h>
 
 #include <stdlib.h>
 #include <stdio.h>
src/stat_test.c +1 -0
index 95cfdc4f..77e1acdd 100644
@@ -4,6 +4,7 @@
  * Written by David Howells ([email protected])
  */
 
+#include <libgen.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
src/t_ext4_dax_inline_corruption.c +1 -0
index e1a39a6c..a40c5df5 100644
@@ -2,6 +2,7 @@
 /* Copyright (c) 2018 Intel Corporation. */
 #include <errno.h>
 #include <fcntl.h>
+#include <libgen.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
src/t_ext4_dax_journal_corruption.c +1 -0
index ba7a96e4..53be10c2 100644
@@ -2,6 +2,7 @@
 /* Copyright (c) 2018 Intel Corporation. */
 #include <errno.h>
 #include <fcntl.h>
+#include <libgen.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
src/t_mmap_collision.c +1 -0
index c872f4e2..d9315fcf 100644
@@ -15,6 +15,7 @@
  */
 #include <errno.h>
 #include <fcntl.h>
+#include <libgen.h>
 #include <pthread.h>
 #include <stdbool.h>
 #include <stdio.h>
Signature · 1 line
2.44.0
author
#1 lore raw

PATCH 2/2 Add missing STATX_ATTR_* defines from musl sys/stat.h

These defines are not provided by sys/stat.h on musl but are in glibc's sys/stat.h, therefore to compile the tests on musl based systems add the missing defines from linux/stat.h if they are not provided

---
 src/statx.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
src/statx.h +12 -0
index 3f239d79..12599f5b 100644
@@ -12,6 +12,18 @@
 #define AT_STATX_DONT_SYNC      0x4000  /* - Don't sync attributes with the server */
 #endif
 
+#ifndef STATX_ATTR_COMPRESSED
+#define STATX_ATTR_COMPRESSED		0x00000004 /* [I] File is compressed by the fs */
+#define STATX_ATTR_IMMUTABLE		0x00000010 /* [I] File is marked immutable */
+#define STATX_ATTR_APPEND		0x00000020 /* [I] File is append-only */
+#define STATX_ATTR_NODUMP		0x00000040 /* [I] File is not to be dumped */
+#define STATX_ATTR_ENCRYPTED		0x00000800 /* [I] File requires key to decrypt in fs */
+#define STATX_ATTR_AUTOMOUNT		0x00001000 /* Dir: Automount trigger */
+#define STATX_ATTR_MOUNT_ROOT		0x00002000 /* Root of a mount */
+#define STATX_ATTR_VERITY		0x00100000 /* [I] Verity protected file */
+#define STATX_ATTR_DAX			0x00200000 /* File is currently in DAX state */
+#endif
+
 #ifndef AT_NO_AUTOMOUNT
 #define AT_NO_AUTOMOUNT		0x800	/* Suppress terminal automount traversal */
 #endif
Signature · 1 line
2.44.0
#2 lore raw
In reply to Khem Raj
Quoted 5 lines · Khem Raj

basename prototype has been removed from string.h from latest musl [1] compilers e.g. clang-18 flags the absense of prototype as error. therefore include libgen.h for providing it.

[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7

Same question as I had for your xfsdump patchset -- the manpage for basename(3) mentions that old glibc posix implementations would modify the argument. Is that still true, or has that not been the case for long enough that it's ok not to care?

--D

Quoted 73 lines
---
 src/splice-test.c                   | 1 +
 src/stat_test.c                     | 1 +
 src/t_ext4_dax_inline_corruption.c  | 1 +
 src/t_ext4_dax_journal_corruption.c | 1 +
 src/t_mmap_collision.c              | 1 +
 5 files changed, 5 insertions(+)
src/splice-test.c +1 -0
index eb863673..7b7094f5 100644
@@ -11,6 +11,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <err.h>
+#include <libgen.h>
 
 #include <stdlib.h>
 #include <stdio.h>
src/stat_test.c +1 -0
index 95cfdc4f..77e1acdd 100644
@@ -4,6 +4,7 @@
  * Written by David Howells ([email protected])
  */
 
+#include <libgen.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
src/t_ext4_dax_inline_corruption.c +1 -0
index e1a39a6c..a40c5df5 100644
@@ -2,6 +2,7 @@
 /* Copyright (c) 2018 Intel Corporation. */
 #include <errno.h>
 #include <fcntl.h>
+#include <libgen.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
src/t_ext4_dax_journal_corruption.c +1 -0
index ba7a96e4..53be10c2 100644
@@ -2,6 +2,7 @@
 /* Copyright (c) 2018 Intel Corporation. */
 #include <errno.h>
 #include <fcntl.h>
+#include <libgen.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
src/t_mmap_collision.c +1 -0
index c872f4e2..d9315fcf 100644
@@ -15,6 +15,7 @@
  */
 #include <errno.h>
 #include <fcntl.h>
+#include <libgen.h>
 #include <pthread.h>
 #include <stdbool.h>
 #include <stdio.h>
Signature · 1 line
2.44.0
author
#3 lore raw
Quoted 6 lines · Darrick J. Wong
Quoted 4 lines · Khem Raj

basename prototype has been removed from string.h from latest musl [1] compilers e.g. clang-18 flags the absense of prototype as error. therefore include libgen.h for providing it.

Quoted 6 lines
Quoted 1 line

[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7

Same question as I had for your xfsdump patchset -- the manpage for basename(3) mentions that old glibc posix implementations would modify the argument. Is that still true, or has that not been the case for long enough that it's ok not to care?

Thats posix basename's behavior and its still true. If we depend on GNU basename behavior then
it can be an issue in that case, I will make a copy of the string to pass to basename to avoid this

Quoted 76 lines

--D

Quoted 73 lines
---
 src/splice-test.c                   | 1 +
 src/stat_test.c                     | 1 +
 src/t_ext4_dax_inline_corruption.c  | 1 +
 src/t_ext4_dax_journal_corruption.c | 1 +
 src/t_mmap_collision.c              | 1 +
 5 files changed, 5 insertions(+)
src/splice-test.c +1 -0
index eb863673..7b7094f5 100644
@@ -11,6 +11,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <err.h>
+#include <libgen.h>
 
 #include <stdlib.h>
 #include <stdio.h>
src/stat_test.c +1 -0
index 95cfdc4f..77e1acdd 100644
@@ -4,6 +4,7 @@
  * Written by David Howells ([email protected])
  */
 
+#include <libgen.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
src/t_ext4_dax_inline_corruption.c +1 -0
index e1a39a6c..a40c5df5 100644
@@ -2,6 +2,7 @@
 /* Copyright (c) 2018 Intel Corporation. */
 #include <errno.h>
 #include <fcntl.h>
+#include <libgen.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
src/t_ext4_dax_journal_corruption.c +1 -0
index ba7a96e4..53be10c2 100644
@@ -2,6 +2,7 @@
 /* Copyright (c) 2018 Intel Corporation. */
 #include <errno.h>
 #include <fcntl.h>
+#include <libgen.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
src/t_mmap_collision.c +1 -1
index c872f4e2..d9315fcf 100644
@@ -15,6 +15,7 @@
  */
 #include <errno.h>
 #include <fcntl.h>
+#include <libgen.h>
 #include <pthread.h>
 #include <stdbool.h>
 #include <stdio.h>
--

2.44.0