utils.h (1007B)
1 #ifndef GITOUT_UTILS_H_ 2 #define GITOUT_UTILS_H_ 3 4 #include <stdio.h> 5 6 /* Concatenates path parts to "p1/p2". Exits on failure or truncation. */ 7 char* path_concat(char* out, size_t out_len, const char* p1, const char* p2); 8 9 /* Recursively creates the directories specified by path, like mkdir -p. */ 10 int mkdirp(const char* path); 11 12 /* Behaves as calloc but exits on failure. */ 13 void* ecalloc(size_t count, size_t size); 14 15 /* Behaves as strdup but exits on failure. */ 16 char* estrdup(const char* s); 17 18 /* Behaves as strlcpy but exits on failure or truncation. */ 19 size_t estrlcpy(char* dst, const char* src, size_t dsize); 20 21 /* Behaves as strlcat but exits on failure or truncation. */ 22 size_t estrlcat(char* dst, const char* src, size_t dsize); 23 24 /* Opens the specified file. Terminates with error on failure. */ 25 FILE* efopen(const char* filename, const char* flags); 26 27 /* Exits with error if the specified FILE* has an error. */ 28 void checkfileerror(FILE* fp, const char* name, char mode); 29 30 #endif // GITOUT_UTILS_H_