]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Move read_file from test/util.c to util.c
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 3 Aug 2010 21:09:16 +0000 (23:09 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 3 Aug 2010 21:09:16 +0000 (23:09 +0200)
ccache.h
test/util.c
util.c

index 45b4f98ebb67598371e4e14be96d69f9d53347ad..a7d6a57e260b79ada514c250bfcf970af97bb053 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -122,6 +122,7 @@ void *x_fmmap(const char *fname, off_t *size, const char *errstr);
 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 */
index bc03923be3d61944454b35c2b9192fd5bf860686..370fd4bde8a351a243188590e64c3ca61d8a71f0 100644 (file)
@@ -50,34 +50,3 @@ create_file(const char *path, const char *content)
                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;
-}
diff --git a/util.c b/util.c
index 664c03581e3ec8151e8052ae9ef403ec6b2164a8..42adccb414c747a55a80a55d98c8201f4303e887 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1155,3 +1155,34 @@ x_readlink(const char *path)
        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;
+}