diff options
author | Ferass El Hafidi <vitali64pmemail@protonmail.com> | 2023-03-03 18:41:14 +0100 |
---|---|---|
committer | Ferass El Hafidi <vitali64pmemail@protonmail.com> | 2023-03-03 18:41:43 +0100 |
commit | 4679af335b17fd8dafbef4dd4f801bd696c46cb9 (patch) | |
tree | eb7c318c53018aad233ada34731949de5b96ddd3 | |
parent | c797c3fb85a0817fa3de940876778053a4ad55a8 (diff) | |
download | fases-4679af335b17fd8dafbef4dd4f801bd696c46cb9.tar.gz fases-4679af335b17fd8dafbef4dd4f801bd696c46cb9.zip |
core/[: Check argv[0], don't use basename()
POSIX says this:
> Applications using the exec() family of functions to execute
> these utilities shall ensure that the argument passed in arg0
> or argv[0] is '[' when executing the [ utility and has a
> basename of "test" when executing the test utility.
Which basically means (in pseudo-code if you will):
if argv[0] is "[" -> behave like the POSIX [
else -> behave like the POSIX test
[ used to compare with the basename of argv[0], which is
POSIXly incorrect.
Signed-off-by: Ferass El Hafidi <vitali64pmemail@protonmail.com>
-rw-r--r-- | core/test.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/core/test.c b/core/test.c index 2b8977d..9fd4e95 100644 --- a/core/test.c +++ b/core/test.c @@ -3,7 +3,6 @@ #include <stdio.h> #include <errno.h> #include <string.h> -#include <libgen.h> #include <sys/stat.h> #include <stdint.h> #include <string.h> @@ -19,7 +18,7 @@ int main(int argc, char *argv[]) { for (int i = 0; i < 256; i++) param[i] = 0; - if (!strcmp(basename(argv[0]), "[")) { + if (!strcmp(argv[0], "[")) { if (strcmp(argv[argc - 1], "]")) { /* FIXME: Is printing an error message POSIX-compliant? */ fprintf(stderr, "[: No matching ]\n"); |