X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-compat-util.h;h=0272d043d0b82dc6ad0ff4836fe8db8ed1e1d960;hb=173a9cbe7031bc3574b3f41cb2d2375cf959ff2a;hp=dd9209365253971c70db772929fb4541f1c609b2;hpb=ca9e3b124f6313187da641b5cd55100c4ade6a9a;p=git.git diff --git a/git-compat-util.h b/git-compat-util.h index dd9209365..0272d043d 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -26,6 +26,13 @@ #include #include +/* On most systems would have given us this, but + * not on some systems (e.g. GNU/Hurd). + */ +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + #ifdef __GNUC__ #define NORETURN __attribute__((__noreturn__)) #else @@ -84,6 +91,14 @@ extern char *gitstrcasestr(const char *haystack, const char *needle); extern size_t gitstrlcpy(char *, const char *, size_t); #endif +static inline char* xstrdup(const char *str) +{ + char *ret = strdup(str); + if (!ret) + die("Out of memory, strdup failed"); + return ret; +} + static inline void *xmalloc(size_t size) { void *ret = malloc(size); @@ -139,9 +154,10 @@ static inline ssize_t xwrite(int fd, const void *buf, size_t len) } } -static inline int has_extension(const char *filename, int len, const char *ext) +static inline int has_extension(const char *filename, const char *ext) { - int extlen = strlen(ext); + size_t len = strlen(filename); + size_t extlen = strlen(ext); return len > extlen && !memcmp(filename + len - extlen, ext, extlen); } @@ -171,7 +187,4 @@ static inline int sane_case(int x, int high) return x; } -#ifndef MAXPATHLEN -#define MAXPATHLEN 256 -#endif #endif