Lines Matching defs:file

8  * license that can be found in the LICENSE file or at
90 __noreturn void assertion_failed(const char *expr, const char *file, int line)
92 fatal_error("Assertion failed: %s at %s:%d", expr, file, line);
107 bool open_file(struct filedes *file, const char *filename, int flags, int mode)
109 file->fd = open(filename, flags | O_BINARY, mode);
110 if (file->fd < 0) {
117 file->name = xstrdup(filename);
121 bool get_file_size(struct filedes *file, u64 *size_ret)
125 if (fstat(file->fd, &stbuf) != 0) {
126 error_msg_errno("can't stat file '%s'", file->name);
133 bool preallocate_file(struct filedes *file, u64 size)
141 res = _chsize_s(file->fd, size);
143 res = posix_fallocate(file->fd, 0, size);
146 error_msg_errno("preallocating %" PRIu64 "-byte file '%s'",
147 size, file->name);
153 bool full_read(struct filedes *file, void *buf, size_t count)
156 int n = read(file->fd, buf, min(count, INT_MAX));
159 error_msg_errno("reading from '%s'", file->name);
163 error_msg("unexpected end-of-file on '%s'", file->name);
172 bool full_write(struct filedes *file, const void *buf, size_t count)
175 int n = write(file->fd, buf, min(count, INT_MAX));
178 error_msg_errno("writing to '%s'", file->name);
205 bool full_pwrite(struct filedes *file, const void *buf, size_t count,
209 int n = raw_pwrite(file->fd, buf, min(count, INT_MAX), offset);
212 error_msg_errno("writing to '%s'", file->name);
222 bool filedes_close(struct filedes *file)
226 if (file->fd < 0)
228 res = close(file->fd);
230 error_msg_errno("closing '%s'", file->name);
231 file->fd = -1;
232 free(file->name);
233 file->name = NULL;
237 int read_callback(void *file, void *buf, size_t count)
240 if (!full_read(file, buf, count))