]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-compat-util.h
is_ntfs_dotgit(): only verify the leading segment
[thirdparty/git.git] / git-compat-util.h
index 7d2c0ca75922ea1ca8c67ec798ff8ce1249c925f..6cb3c2f19eb5a0822ae17a1b1e1abc08d3de25e4 100644 (file)
@@ -900,9 +900,11 @@ static inline char *xstrdup_or_null(const char *str)
 
 static inline size_t xsize_t(off_t len)
 {
-       if (len > (size_t) len)
+       size_t size = (size_t) len;
+
+       if (len != (off_t) size)
                die("Cannot handle files this big");
-       return (size_t)len;
+       return size;
 }
 
 __attribute__((format (printf, 3, 4)))
@@ -978,6 +980,23 @@ static inline int sane_iscase(int x, int is_lower)
                return (x & 0x20) == 0;
 }
 
+/*
+ * Like skip_prefix, but compare case-insensitively. Note that the comparison
+ * is done via tolower(), so it is strictly ASCII (no multi-byte characters or
+ * locale-specific conversions).
+ */
+static inline int skip_iprefix(const char *str, const char *prefix,
+                              const char **out)
+{
+       do {
+               if (!*prefix) {
+                       *out = str;
+                       return 1;
+               }
+       } while (tolower(*str++) == tolower(*prefix++));
+       return 0;
+}
+
 static inline int strtoul_ui(char const *s, int base, unsigned int *result)
 {
        unsigned long ul;