From a73313e8ff269a47af6e24d28045fc264581fa10 Mon Sep 17 00:00:00 2001 From: James Jones Date: Wed, 26 Aug 2020 22:46:16 -0700 Subject: [PATCH] Treat ':' as a path separator on non-Windows platforms In addition to ';', allow the use of ':' as a path separator in RMACPATH, the -i parameter, and any other uses of nthpath. This makes rmac more consistent with standard Unix tool behavior on Unix-like systems. --- rmac.c | 15 +++++++++++++-- rmac.h | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/rmac.c b/rmac.c index b21c1ed..26cb78e 100644 --- a/rmac.c +++ b/rmac.c @@ -101,6 +101,17 @@ char * fext(char * name, char * extension, int stripp) return name; } +static int is_sep(char c) +{ + const char *seps = PATH_SEPS; + + for (seps = PATH_SEPS; *seps; seps++) { + if (*seps == c) + return 1; + } + + return 0; +} // // Return 'item'nth element of semicolon-seperated pathnames specified in the @@ -120,13 +131,13 @@ int nthpath(char * env_var, int itemno, char * buf) return 0; while (itemno--) - while (*s != EOS && *s++ != ';') + while (*s != EOS && !is_sep(*s++)) ; if (*s == EOS) return 0; - while (*s != EOS && *s != ';') + while (*s != EOS && !is_sep(*s)) *buf++ = *s++; *buf++ = EOS; diff --git a/rmac.h b/rmac.h index 357d70e..85043b7 100644 --- a/rmac.h +++ b/rmac.h @@ -27,6 +27,7 @@ #define _OPEN_FLAGS _O_TRUNC|_O_CREAT|_O_BINARY|_O_RDWR #define _OPEN_INC _O_RDONLY|_O_BINARY #define _PERM_MODE _S_IREAD|_S_IWRITE + #define PATH_SEPS ";" #ifdef _MSC_VER #if _MSC_VER > 1000 @@ -64,6 +65,7 @@ #define _OPEN_FLAGS O_TRUNC|O_CREAT|O_RDWR #define _OPEN_INC O_RDONLY #define _PERM_MODE S_IRUSR|S_IWUSR + #define PATH_SEPS ";:" #ifdef __MINGW32__ #define off64_t long @@ -86,6 +88,7 @@ #define _OPEN_FLAGS O_TRUNC|O_CREAT|O_RDWR #define _OPEN_INC O_RDONLY #define _PERM_MODE S_IREAD|S_IWRITE + #define PATH_SEPS ":;" // Defined here, even though the platform may not support it... #define DO_PRAGMA(x) _Pragma (#x) #define WARNING(desc) DO_PRAGMA(message (#desc)) -- 2.26.2