struct Node;
struct Rule;
-int ReadFile(const string& path, string* contents, string* err);
-
/// Interface for accessing the disk.
///
/// Abstract so it can be mocked out for tests. The real implementation
#include "graph.h"
#include "util.h"
-int ReadFile(const string& path, string* contents, string* err) {
- FILE* f = fopen(path.c_str(), "r");
- if (!f) {
- err->assign(strerror(errno));
- return -errno;
- }
-
- char buf[64 << 10];
- size_t len;
- while ((len = fread(buf, 1, sizeof(buf), f)) > 0) {
- contents->append(buf, len);
- }
- if (ferror(f)) {
- err->assign(strerror(errno)); // XXX errno?
- contents->clear();
- fclose(f);
- return -errno;
- }
- fclose(f);
- return 0;
-}
-
int RealDiskInterface::Stat(const string& path) {
struct stat st;
if (stat(path.c_str(), &st) < 0) {
#include "util.h"
+#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
return mkdir(path.c_str(), 0777);
#endif
}
+
+int ReadFile(const string& path, string* contents, string* err) {
+ FILE* f = fopen(path.c_str(), "r");
+ if (!f) {
+ err->assign(strerror(errno));
+ return -errno;
+ }
+
+ char buf[64 << 10];
+ size_t len;
+ while ((len = fread(buf, 1, sizeof(buf), f)) > 0) {
+ contents->append(buf, len);
+ }
+ if (ferror(f)) {
+ err->assign(strerror(errno)); // XXX errno?
+ contents->clear();
+ fclose(f);
+ return -errno;
+ }
+ fclose(f);
+ return 0;
+}
/// Portability abstraction.
int MakeDir(const string& path);
+/// Read a file to a string.
+/// Returns -errno and fills in \a err on error.
+int ReadFile(const string& path, string* contents, string* err);
+
#endif // NINJA_UTIL_H_