Changeset ce04ea44 in mainline for uspace/lib/c
- Timestamp:
- 2017-04-02T12:27:14Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d4067a7
- Parents:
- 163fc09
- Location:
- uspace/lib/c
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/elf/elf_mod.c
r163fc09 rce04ea44 138 138 int i, rc; 139 139 140 rc = read(elf->fd, &pos, header, sizeof(elf_header_t));140 rc = vfs_read(elf->fd, &pos, header, sizeof(elf_header_t)); 141 141 if (rc != sizeof(elf_header_t)) { 142 142 DPRINTF("Read error.\n"); … … 197 197 198 198 pos = header->e_phoff + i * sizeof(elf_segment_header_t); 199 rc = read(elf->fd, &pos, &segment_hdr,199 rc = vfs_read(elf->fd, &pos, &segment_hdr, 200 200 sizeof(elf_segment_header_t)); 201 201 if (rc != sizeof(elf_segment_header_t)) { … … 216 216 217 217 pos = header->e_shoff + i * sizeof(elf_section_header_t); 218 rc = read(elf->fd, &pos, §ion_hdr,218 rc = vfs_read(elf->fd, &pos, §ion_hdr, 219 219 sizeof(elf_section_header_t)); 220 220 if (rc != sizeof(elf_section_header_t)) { … … 387 387 */ 388 388 pos = entry->p_offset; 389 rc = read(elf->fd, &pos, seg_ptr, entry->p_filesz);389 rc = vfs_read(elf->fd, &pos, seg_ptr, entry->p_filesz); 390 390 if (rc < 0) { 391 391 DPRINTF("read error\n"); -
uspace/lib/c/generic/io/io.c
r163fc09 rce04ea44 434 434 return 0; 435 435 436 ssize_t rd = read(stream->fd, &stream->pos, buf, size * nmemb);436 ssize_t rd = vfs_read(stream->fd, &stream->pos, buf, size * nmemb); 437 437 if (rd < 0) { 438 /* errno was set by read() */438 errno = rd; 439 439 stream->error = true; 440 440 rd = 0; … … 472 472 } 473 473 } else { 474 wr = write(stream->fd, &stream->pos, buf, size * nmemb);474 wr = vfs_write(stream->fd, &stream->pos, buf, size * nmemb); 475 475 if (wr < 0) { 476 /* errno was set by write() */476 errno = wr; 477 477 stream->error = true; 478 478 wr = 0; … … 496 496 stream->buf_head = stream->buf_tail = stream->buf; 497 497 498 rc = read(stream->fd, &stream->pos, stream->buf, stream->buf_size);498 rc = vfs_read(stream->fd, &stream->pos, stream->buf, stream->buf_size); 499 499 if (rc < 0) { 500 /* errno was set by read() */500 errno = rc; 501 501 stream->error = true; 502 502 return; -
uspace/lib/c/generic/vfs/vfs.c
r163fc09 rce04ea44 395 395 * return success with zero bytes read. 396 396 * 397 * @param fil desFile descriptor397 * @param file File descriptor 398 398 * @param pos Position to read from 399 399 * @param buf Buffer … … 403 403 * @return EOK on success, non-zero error code on error. 404 404 */ 405 static int _read_short(int fildes, aoff64_t pos, void *buf, size_t nbyte,405 int vfs_read_short(int file, aoff64_t pos, void *buf, size_t nbyte, 406 406 ssize_t *nread) 407 407 { … … 415 415 async_exch_t *exch = vfs_exchange_begin(); 416 416 417 req = async_send_3(exch, VFS_IN_READ, fil des, LOWER32(pos),417 req = async_send_3(exch, VFS_IN_READ, file, LOWER32(pos), 418 418 UPPER32(pos), &answer); 419 419 rc = async_data_read_start(exch, (void *) buf, nbyte); … … 438 438 * may be lower, but greater than zero. 439 439 * 440 * @param fil desFile descriptor440 * @param file File descriptor 441 441 * @param pos Position to write to 442 442 * @param buf Buffer … … 446 446 * @return EOK on success, non-zero error code on error. 447 447 */ 448 static int _write_short(int fildes, aoff64_t pos, const void *buf, size_t nbyte,448 int vfs_write_short(int file, aoff64_t pos, const void *buf, size_t nbyte, 449 449 ssize_t *nwritten) 450 450 { … … 458 458 async_exch_t *exch = vfs_exchange_begin(); 459 459 460 req = async_send_3(exch, VFS_IN_WRITE, fil des, LOWER32(pos),460 req = async_send_3(exch, VFS_IN_WRITE, file, LOWER32(pos), 461 461 UPPER32(pos), &answer); 462 462 rc = async_data_write_start(exch, (void *) buf, nbyte); … … 486 486 * @param nbytes Number of bytes to read 487 487 * 488 * @return On success, non negative number of bytes read.489 * On failure, -1 and sets errno.490 */ 491 ssize_t read(int fildes, aoff64_t *pos, void *buf, size_t nbyte)488 * @return On success, non-negative number of bytes red. 489 * On failure, a negative error code. 490 */ 491 ssize_t vfs_read(int file, aoff64_t *pos, void *buf, size_t nbyte) 492 492 { 493 493 ssize_t cnt = 0; … … 500 500 nread += cnt; 501 501 *pos += cnt; 502 rc = _read_short(fildes, *pos, bp, nbyte - nread, &cnt);502 rc = vfs_read_short(file, *pos, bp, nbyte - nread, &cnt); 503 503 } while (rc == EOK && cnt > 0 && (nbyte - nread - cnt) > 0); 504 504 505 if (rc != EOK) { 506 errno = rc; 507 return -1; 508 } 505 if (rc != EOK) 506 return rc; 509 507 510 508 *pos += cnt; … … 516 514 * This function fails if it cannot write exactly @a len bytes to the file. 517 515 * 518 * @param fil desFile descriptor516 * @param file File descriptor 519 517 * @param pos Pointer to position to write to 520 518 * @param buf Data, @a nbytes bytes long 521 519 * @param nbytes Number of bytes to write 522 520 * 523 * @return On success, non negative number of bytes written.524 * On failure, -1 and sets errno.525 */ 526 ssize_t write(int fildes, aoff64_t *pos, const void *buf, size_t nbyte)521 * @return On success, non-negative number of bytes written. 522 * On failure, a negative error code. 523 */ 524 ssize_t vfs_write(int file, aoff64_t *pos, const void *buf, size_t nbyte) 527 525 { 528 526 ssize_t cnt = 0; … … 535 533 nwritten += cnt; 536 534 *pos += cnt; 537 rc = _write_short(fildes, *pos, bp, nbyte - nwritten, &cnt);535 rc = vfs_write_short(file, *pos, bp, nbyte - nwritten, &cnt); 538 536 } while (rc == EOK && ((ssize_t )nbyte - nwritten - cnt) > 0); 539 537 540 if (rc != EOK) { 541 errno = rc; 542 return -1; 543 } 538 if (rc != EOK) 539 return rc; 544 540 545 541 *pos += cnt; … … 681 677 ssize_t len = 0; 682 678 683 rc = _read_short(dirp->fd, dirp->pos, &dirp->res.d_name[0],679 rc = vfs_read_short(dirp->fd, dirp->pos, &dirp->res.d_name[0], 684 680 NAME_MAX + 1, &len); 685 681 if (rc != EOK) { -
uspace/lib/c/include/unistd.h
r163fc09 rce04ea44 58 58 #define getpagesize() (PAGE_SIZE) 59 59 60 extern ssize_t write(int, aoff64_t *, const void *, size_t);61 extern ssize_t read(int, aoff64_t *, void *, size_t);62 63 60 extern char *getcwd(char *, size_t); 64 61 extern int chdir(const char *); -
uspace/lib/c/include/vfs/vfs.h
r163fc09 rce04ea44 96 96 extern int vfs_open(int, int); 97 97 extern int vfs_put(int); 98 extern int vfs_read_short(int, aoff64_t, void *, size_t, ssize_t *); 99 extern ssize_t vfs_read(int, aoff64_t *, void *, size_t); 98 100 extern int vfs_rename_path(const char *, const char *); 99 101 extern int vfs_resize(int, aoff64_t); … … 110 112 extern int vfs_unmount_path(const char *); 111 113 extern int vfs_walk(int, const char *, int); 112 114 extern int vfs_write_short(int, aoff64_t, const void *, size_t, ssize_t *); 115 extern ssize_t vfs_write(int, aoff64_t *, const void *, size_t); 113 116 114 117 #endif
Note:
See TracChangeset
for help on using the changeset viewer.