Lines Matching defs:file
4 // you may not use this file except in compliance with the License.
40 // Appends the contents of the |file| to |data|, assuming each element in the
41 // file is of type |T|.
43 void ReadFile(FILE* file, std::vector<T>* data) {
44 if (file == nullptr) return;
48 while (size_t len = fread(buf, sizeof(T), buf_size, file)) {
53 // Returns true if |file| has encountered an error opening the file or reading
54 // the file as a series of element of type |T|. If there was an error, writes an
57 bool WasFileCorrectlyRead(FILE* file, const char* filename) {
58 if (file == nullptr) {
59 fprintf(stderr, "error: file does not exist '%s'\n", filename);
63 if (ftell(file) == -1L) {
64 if (ferror(file)) {
65 fprintf(stderr, "error: error reading file '%s'\n", filename);
69 if (sizeof(T) != 1 && (ftell(file) % sizeof(T))) {
72 "error: file size should be a multiple of %zd; file '%s' corrupt\n",
80 // Appends the contents of the file named |filename| to |data|, assuming
81 // each element in the file is of type |T|. The file is opened as a binary file
83 // reopened as a binary file. If any error occurs, writes error messages to
102 // Appends the contents of the file named |filename| to |data|, assuming
103 // each element in the file is of type |T|. The file is opened as a text file
105 // reopened as a text file. If any error occurs, writes error messages to
125 // A class to create and manage a file for outputting data.
154 // Returns a file handle to the file.
163 // Writes the given |data| into the file named as |filename| using the given
170 OutputFile file(filename, mode);
171 FILE* fp = file.GetFileHandle();
173 fprintf(stderr, "error: could not open file '%s'\n", filename);
179 fprintf(stderr, "error: could not write to file '%s'\n", filename);