Changeset 8e3498b in mainline for uspace/lib/c/generic/vfs
- Timestamp:
- 2017-12-04T18:44:24Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bde5c04
- Parents:
- 40feeac
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
r40feeac r8e3498b 86 86 * and consume system resources. 87 87 * 88 * Functions that return int return a negativeerror code on error and do not88 * Functions that return int return an error code on error and do not 89 89 * set errno. Depending on function, success is signalled by returning either 90 90 * EOK or a non-negative file handle. … … 104 104 * aoff64_t pos = 42; 105 105 * char buf[512]; 106 * ssize_t size = vfs_read(file, &pos, buf, sizeof(buf)); 107 * if (size < 0) { 106 * size_t nread; 107 * rc = vfs_read(file, &pos, buf, sizeof(buf), &nread); 108 * if (rc != EOK) { 108 109 * vfs_put(file); 109 * return size;110 * return rc; 110 111 * } 111 112 * 112 * // buf is now filled with datafrom file113 * // buf is now filled with nread bytes from file 113 114 * 114 115 * vfs_put(file); … … 808 809 * @param buf Buffer, @a nbytes bytes long 809 810 * @param nbytes Number of bytes to read 810 * 811 * @return On success, non-negative number of bytes read 812 * @return On failure, a negative error code 813 */ 814 ssize_t vfs_read(int file, aoff64_t *pos, void *buf, size_t nbyte) 811 * @param nread Place to store number of bytes actually read 812 * 813 * @return On success, EOK and @a *nread is filled with number 814 * of bytes actually read. 815 * @return On failure, an error code 816 */ 817 int vfs_read(int file, aoff64_t *pos, void *buf, size_t nbyte, size_t *nread) 815 818 { 816 819 ssize_t cnt = 0; 817 size_t nr ead= 0;820 size_t nr = 0; 818 821 uint8_t *bp = (uint8_t *) buf; 819 822 int rc; … … 821 824 do { 822 825 bp += cnt; 823 nr ead+= cnt;826 nr += cnt; 824 827 *pos += cnt; 825 rc = vfs_read_short(file, *pos, bp, nbyte - nread, &cnt); 826 } while (rc == EOK && cnt > 0 && (nbyte - nread - cnt) > 0); 827 828 if (rc != EOK) 828 rc = vfs_read_short(file, *pos, bp, nbyte - nr, &cnt); 829 } while (rc == EOK && cnt > 0 && (nbyte - nr - cnt) > 0); 830 831 if (rc != EOK) { 832 *nread = nr; 829 833 return rc; 830 834 } 835 836 nr += cnt; 831 837 *pos += cnt; 832 return nread + cnt; 838 *nread = nr; 839 return EOK; 833 840 } 834 841 … … 1247 1254 * @param buf Data, @a nbytes bytes long 1248 1255 * @param nbytes Number of bytes to write 1249 * 1250 * @return On success, non-negative number of bytes written 1251 * @return On failure, a negative error code 1252 */ 1253 ssize_t vfs_write(int file, aoff64_t *pos, const void *buf, size_t nbyte) 1256 * @param nwritten Place to store number of bytes written 1257 * 1258 * @return On success, EOK, @a *nwr is filled with number 1259 * of bytes written 1260 * @return On failure, an error code 1261 */ 1262 int vfs_write(int file, aoff64_t *pos, const void *buf, size_t nbyte, 1263 size_t *nwritten) 1254 1264 { 1255 1265 ssize_t cnt = 0; 1256 ssize_t nwr itten= 0;1266 ssize_t nwr = 0; 1257 1267 const uint8_t *bp = (uint8_t *) buf; 1258 1268 int rc; … … 1260 1270 do { 1261 1271 bp += cnt; 1262 nwr itten+= cnt;1272 nwr += cnt; 1263 1273 *pos += cnt; 1264 rc = vfs_write_short(file, *pos, bp, nbyte - nwritten, &cnt); 1265 } while (rc == EOK && ((ssize_t )nbyte - nwritten - cnt) > 0); 1266 1267 if (rc != EOK) 1274 rc = vfs_write_short(file, *pos, bp, nbyte - nwr, &cnt); 1275 } while (rc == EOK && ((ssize_t )nbyte - nwr - cnt) > 0); 1276 1277 if (rc != EOK) { 1278 *nwritten = nwr; 1268 1279 return rc; 1269 1280 } 1281 1282 nwr += cnt; 1270 1283 *pos += cnt; 1271 return nbyte; 1284 *nwritten = nwr; 1285 return EOK; 1272 1286 } 1273 1287
Note:
See TracChangeset
for help on using the changeset viewer.