--format=pretty: avoid calculating expensive expansions twice
[gitweb.git] / git-compat-util.h
index 474f1d1ffbee5433ec311174ee37804ab16417bb..e72654bc408e36512b392e3e5ed3026d79cc141b 100644 (file)
@@ -183,6 +183,11 @@ void *gitmemmem(const void *haystack, size_t haystacklen,
                 const void *needle, size_t needlelen);
 #endif
 
+#ifdef NO_STRCHRNUL
+#define strchrnul gitstrchrnul
+char *gitstrchrnul(const char *s, int c);
+#endif
+
 extern void release_pack_memory(size_t, int);
 
 static inline char* xstrdup(const char *str)
@@ -381,4 +386,17 @@ static inline int strtoul_ui(char const *s, int base, unsigned int *result)
        return 0;
 }
 
+static inline int strtol_i(char const *s, int base, int *result)
+{
+       long ul;
+       char *p;
+
+       errno = 0;
+       ul = strtol(s, &p, base);
+       if (errno || *p || p == s || (int) ul != ul)
+               return -1;
+       *result = ul;
+       return 0;
+}
+
 #endif