Changeset 368ee04 in mainline for uspace/lib/bithenge/src/file.c
- Timestamp:
- 2017-04-05T18:10:39Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 93ad8166
- Parents:
- 39f892a9 (diff), 2166728 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/bithenge/src/file.c
r39f892a9 r368ee04 38 38 #include <assert.h> 39 39 #include <errno.h> 40 #include <fcntl.h>41 40 #include <stdio.h> 42 41 #include <stdlib.h> 43 #include < sys/stat.h>42 #include <vfs/vfs.h> 44 43 #include <sys/types.h> 45 44 #include <unistd.h> … … 78 77 if (offset > blob->size) 79 78 return ELIMIT; 80 if (lseek(blob->fd, offset, SEEK_SET) < 0)81 return errno == EINVAL ? EIO : errno;82 79 83 ssize_t amount_read; 84 aoff64_t remaining_size = *size; 85 *size = 0; 86 do { 87 amount_read = read(blob->fd, buffer, remaining_size); 88 if (amount_read < 0) 89 return errno; 90 buffer += amount_read; 91 *size += amount_read; 92 remaining_size -= amount_read; 93 } while (remaining_size && amount_read); 80 ssize_t amount_read = vfs_read(blob->fd, &offset, buffer, *size); 81 if (amount_read < 0) 82 return errno; 83 *size += amount_read; 94 84 return EOK; 95 85 } … … 98 88 { 99 89 file_blob_t *blob = blob_as_file(base); 100 close(blob->fd);90 vfs_put(blob->fd); 101 91 free(blob); 102 92 } … … 113 103 114 104 struct stat stat; 115 int rc = fstat(fd, &stat);116 if (rc != 0) {105 int rc = vfs_stat(fd, &stat); 106 if (rc != EOK) { 117 107 if (needs_close) 118 close(fd);108 vfs_put(fd); 119 109 return rc; 120 110 } … … 124 114 if (!blob) { 125 115 if (needs_close) 126 close(fd);116 vfs_put(fd); 127 117 return ENOMEM; 128 118 } … … 131 121 free(blob); 132 122 if (needs_close) 133 close(fd);123 vfs_put(fd); 134 124 return rc; 135 125 } … … 155 145 assert(filename); 156 146 157 int fd = open(filename, O_RDONLY);147 int fd = vfs_lookup_open(filename, WALK_REGULAR, MODE_READ); 158 148 if (fd < 0) 159 149 return errno;
Note:
See TracChangeset
for help on using the changeset viewer.