logo

utils-std

Collection of commonly available Unix tools
commit: ef5891f35c5bd86fc11e12aa60cbf3bc2caaea96
parent d7530e55805db419eb967c4b5ddfbfae354f8be6
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 19 May 2024 07:00:21 +0200

cmd/basename: Move nonnull to compile-time

Diffstat:

Mcmd/basename.c13++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/cmd/basename.c b/cmd/basename.c @@ -4,19 +4,22 @@ #define _POSIX_C_SOURCE 200809L -#include <assert.h> // assert() #include <libgen.h> // basename() #include <stdio.h> // puts(), perror() #include <string.h> // strlen(), strncmp() -static char * +#ifdef __GNUC__ +#define _NonNull __attribute__((nonnull)) +#else +#define _NonNull +#endif + +static char * _NonNull suffix_basename(char *name, char *suffix) { - assert(name); - assert(suffix); char *string = basename(name); - size_t suflen = suffix ? strlen(suffix) : 0; + size_t suflen = strlen(suffix); size_t len = strlen(string); if(suflen < len && strcmp(&string[len - suflen], suffix) == 0)