int x_munmap(void *addr, size_t length);
int x_rename(const char *oldpath, const char *newpath);
char *x_readlink(const char *path);
+char *read_file(const char *path);
/* ------------------------------------------------------------------------- */
/* stats.c */
fclose(f);
}
}
-
-/* Return the content of a text file, or NULL on error. Caller frees. */
-char *
-read_file(const char *path)
-{
- int fd, ret;
- size_t pos = 0, allocated = 1024;
- char *result = malloc(allocated);
-
- fd = open(path, O_RDONLY);
- if (fd == -1) {
- free(result);
- return NULL;
- }
- ret = 0;
- do {
- pos += ret;
- if (pos > allocated / 2) {
- allocated *= 2;
- result = realloc(result, allocated);
- }
- } while ((ret = read(fd, result + pos, allocated - pos - 1)) > 0);
- close(fd);
- if (ret == -1) {
- free(result);
- return NULL;
- }
- result[pos] = '\0';
-
- return result;
-}
return buf;
}
#endif
+
+/* Return the content of a text file, or NULL on error. Caller frees. */
+char *
+read_file(const char *path)
+{
+ int fd, ret;
+ size_t pos = 0, allocated = 1024;
+ char *result = malloc(allocated);
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1) {
+ free(result);
+ return NULL;
+ }
+ ret = 0;
+ do {
+ pos += ret;
+ if (pos > allocated / 2) {
+ allocated *= 2;
+ result = realloc(result, allocated);
+ }
+ } while ((ret = read(fd, result + pos, allocated - pos - 1)) > 0);
+ close(fd);
+ if (ret == -1) {
+ free(result);
+ return NULL;
+ }
+ result[pos] = '\0';
+
+ return result;
+}