Changes in uspace/lib/bithenge/src/file.c [ce04ea44:6afc9d7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/bithenge/src/file.c
rce04ea44 r6afc9d7 38 38 #include <assert.h> 39 39 #include <errno.h> 40 #include <fcntl.h> 40 41 #include <stdio.h> 41 42 #include <stdlib.h> 42 #include < vfs/vfs.h>43 #include <sys/stat.h> 43 44 #include <sys/types.h> 44 45 #include <unistd.h> … … 77 78 if (offset > blob->size) 78 79 return ELIMIT; 80 if (lseek(blob->fd, offset, SEEK_SET) < 0) 81 return errno == EINVAL ? EIO : errno; 79 82 80 ssize_t amount_read = vfs_read(blob->fd, &offset, buffer, *size); 81 if (amount_read < 0) 82 return errno; 83 *size += amount_read; 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); 84 94 return EOK; 85 95 } … … 88 98 { 89 99 file_blob_t *blob = blob_as_file(base); 90 vfs_put(blob->fd);100 close(blob->fd); 91 101 free(blob); 92 102 } … … 103 113 104 114 struct stat stat; 105 int rc = vfs_stat(fd, &stat);106 if (rc != EOK) {115 int rc = fstat(fd, &stat); 116 if (rc != 0) { 107 117 if (needs_close) 108 vfs_put(fd);118 close(fd); 109 119 return rc; 110 120 } … … 114 124 if (!blob) { 115 125 if (needs_close) 116 vfs_put(fd);126 close(fd); 117 127 return ENOMEM; 118 128 } … … 121 131 free(blob); 122 132 if (needs_close) 123 vfs_put(fd);133 close(fd); 124 134 return rc; 125 135 } … … 145 155 assert(filename); 146 156 147 int fd = vfs_lookup_open(filename, WALK_REGULAR, MODE_READ);157 int fd = open(filename, O_RDONLY); 148 158 if (fd < 0) 149 159 return errno;
Note:
See TracChangeset
for help on using the changeset viewer.