From: Johannes Sixt Date: Fri, 12 Feb 2010 10:11:23 GMT Subject: Re: [PATCH 3/5] Add is_root_path() Message-ID: <4B75294B.8080205@kdbg.org> In-Reply-To: <1265899403-15904-4-git-send-email-pclouds@gmail.com> Nguyễn Thái Ngọc Duy schrieb: > This function returns the length of the root part of a path, or zero if > there is no root. That is, the function primarily doesn't act as a predicate, and in fact you never use it as such. I just noticed that this function is identical to offset_1st_component() in sha1_file.c. > --- a/git-compat-util.h > +++ b/git-compat-util.h > @@ -210,6 +210,17 @@ static inline const char *skip_prefix(const char *str, const char *prefix) > return strncmp(str, prefix, len) ? NULL : str + len; > } > > +/* path must be canonical */ > +static inline int is_root_path(const char *path) > +{ > + int len = 0; > + if (has_dos_drive_prefix(path)) > + len += 2; > + if (is_dir_sep(path[len])) > + len++; > + return len; > +} > + > #if defined(NO_MMAP) || defined(USE_WIN32_MMAP) This is not a good location for this function because on Windows we get warnings about implicitly defined function isalpha() (which is hidden in the macro has_dos_drive_prefix). I suggest to move offset_1st_component() to path.c, which would not be inlined anymore. -- Hannes