X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=git-compat-util.h;h=167c3fe63a4fd9ca4abf5c16694e22a9ae22717b;hb=7f0475c308625fb9e4cbbad8dc665983571cc5cf;hp=591244351ec4e410ea3b7f891d0de2f33a5aff7a;hpb=11a1d351cfd63cb110e725ba7aae247215b47b56;p=git.git diff --git a/git-compat-util.h b/git-compat-util.h index 591244351..167c3fe63 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -68,6 +68,7 @@ #include #include #include +#include #ifndef NO_SYS_SELECT_H #include #endif @@ -209,6 +210,15 @@ void *gitmemmem(const void *haystack, size_t haystacklen, extern FILE *git_fopen(const char*, const char*); #endif +#ifdef SNPRINTF_RETURNS_BOGUS +#define snprintf git_snprintf +extern int git_snprintf(char *str, size_t maxsize, + const char *format, ...); +#define vsnprintf git_vsnprintf +extern int git_vsnprintf(char *str, size_t maxsize, + const char *format, va_list ap); +#endif + #ifdef __GLIBC_PREREQ #if __GLIBC_PREREQ(2, 1) #define HAVE_STRCHRNUL @@ -258,6 +268,12 @@ static inline void *xmalloc(size_t size) return ret; } +/* + * xmemdupz() allocates (len + 1) bytes of memory, duplicates "len" bytes of + * "data" to the allocated memory, zero terminates the allocated memory, + * and returns a pointer to the allocated memory. If the allocation fails, + * the program dies. + */ static inline void *xmemdupz(const void *data, size_t len) { char *p = xmalloc(len + 1); @@ -319,6 +335,11 @@ static inline void *xmmap(void *start, size_t length, return ret; } +/* + * xread() is the same a read(), but it automatically restarts read() + * operations with a recoverable error (EAGAIN and EINTR). xread() + * DOES NOT GUARANTEE that "len" bytes is read even if the data is available. + */ static inline ssize_t xread(int fd, void *buf, size_t len) { ssize_t nr; @@ -330,6 +351,11 @@ static inline ssize_t xread(int fd, void *buf, size_t len) } } +/* + * xwrite() is the same a write(), but it automatically restarts write() + * operations with a recoverable error (EAGAIN and EINTR). xwrite() DOES NOT + * GUARANTEE that "len" bytes is written even if the operation is successful. + */ static inline ssize_t xwrite(int fd, const void *buf, size_t len) { ssize_t nr;