X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-compat-util.h;h=01c4045e89a2e156062255193ed5d865fdf8a922;hb=06f60e8edf1eb3a91e1af6f255bf46154168dd86;hp=73968e02b024f22068eb5500033f7a2f41d31e8f;hpb=1c536069780bc67c05e621f0485f787d04559f24;p=git.git diff --git a/git-compat-util.h b/git-compat-util.h index 73968e02b..01c4045e8 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 @@ -205,6 +206,9 @@ void *gitmemmem(const void *haystack, size_t haystacklen, #endif #ifdef FREAD_READS_DIRECTORIES +#ifdef fopen +#undef fopen +#endif #define fopen(a,b) git_fopen(a,b) extern FILE *git_fopen(const char*, const char*); #endif @@ -267,6 +271,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); @@ -328,6 +338,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; @@ -339,6 +354,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;