Skip to content

Commit bf72834

Browse files
rscharfegitster
authored andcommitted
turn path macros into inline function
Use static inline functions instead of macros for has_dos_drive_prefix, offset_1st_component, is_dir_sep and find_last_dir_sep in order to let the compiler do type checking. The definitions of offset_1st_component and is_dir_sep are switched around because the former uses the latter. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c2369bd commit bf72834

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

git-compat-util.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,19 +267,35 @@ extern char *gitbasename(char *);
267267
#endif
268268

269269
#ifndef has_dos_drive_prefix
270-
#define has_dos_drive_prefix(path) 0
270+
static inline int git_has_dos_drive_prefix(const char *path)
271+
{
272+
return 0;
273+
}
274+
#define has_dos_drive_prefix git_has_dos_drive_prefix
271275
#endif
272276

273-
#ifndef offset_1st_component
274-
#define offset_1st_component(path) (is_dir_sep((path)[0]))
277+
#ifndef is_dir_sep
278+
static inline int git_is_dir_sep(int c)
279+
{
280+
return c == '/';
281+
}
282+
#define is_dir_sep git_is_dir_sep
275283
#endif
276284

277-
#ifndef is_dir_sep
278-
#define is_dir_sep(c) ((c) == '/')
285+
#ifndef offset_1st_component
286+
static inline int git_offset_1st_component(const char *path)
287+
{
288+
return is_dir_sep(path[0]);
289+
}
290+
#define offset_1st_component git_offset_1st_component
279291
#endif
280292

281293
#ifndef find_last_dir_sep
282-
#define find_last_dir_sep(path) strrchr(path, '/')
294+
static inline char *git_find_last_dir_sep(const char *path)
295+
{
296+
return strrchr(path, '/');
297+
}
298+
#define find_last_dir_sep git_find_last_dir_sep
283299
#endif
284300

285301
#if defined(__HP_cc) && (__HP_cc >= 61000)

0 commit comments

Comments
 (0)