[PATCH v2 1/2] mingw.h: permit arguments with side effects for is_dir_sep
- From
Johannes Sixt <j6t@kdbg.org>
- Date
- May 22, 2017, 18:58 UTC
- Message-ID
- <7b1f97ff-52b7-72c3-211f-e73dce562911@kdbg.org>
- In-Reply-To
- <cover.1495261020.git.j6t@kdbg.org>
Taking git-compat-util.h's cue (which uses an inline function to back is_dir_sep()), let's use an inline function to back also the Windows version of is_dir_sep(). This avoids problems when calling the function with arguments that do more than just provide a single character, e.g. incrementing a pointer. Example:
is_dir_sep(*p++)
Signed-off-by: Johannes Sixt <j6t@kdbg.org> --- This v2 takes your commit message body because I like it better than mine. I did not change the subject because your suggestion sounded like the exact opposite of what this patch wants to achieve on first reading. Patch text is unchanged.
compat/mingw.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/compat/mingw.h b/compat/mingw.h index 034fff9479..d2168c1e5e 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -395,7 +395,11 @@ HANDLE winansi_get_osfhandle(int fd); (isalpha(*(path)) && (path)[1] == ':' ? 2 : 0) int mingw_skip_dos_drive_prefix(char **path); #define skip_dos_drive_prefix mingw_skip_dos_drive_prefix -#define is_dir_sep(c) ((c) == '/' || (c) == '\\') +static inline int mingw_is_dir_sep(int c) +{ + return c == '/' || c == '\\'; +} +#define is_dir_sep mingw_is_dir_sep static inline char *mingw_find_last_dir_sep(const char *path) { char *ret = NULL;
-- 2.13.0.55.g17b7d13330