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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Aug 16, 2014 at 23:48 UTC
bf7283465b42e43b8822a8575abd1a7c6c82e7c9
1 file changed
+22
-6
git-compat-util.h
+22
-6
@@ -267,19 +267,35 @@ extern char *gitbasename(char *);
267
#endif
268
269
#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
275
#endif
276
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
283
#endif
284
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
291
#endif
292
293
#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
299
#endif
300
301
#if defined(__HP_cc) && (__HP_cc >= 61000)