- Timestamp:
- 2018-01-04T20:03:02Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3c7702c0
- Parents:
- 10de842
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-01-04 19:18:29)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-01-04 20:03:02)
- Location:
- uspace/lib
- Files:
-
- 2 deleted
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
r10de842 r0d0b319 566 566 return ENOENT; 567 567 } 568 569 // XXX: Workaround for GCC diagnostics. 570 *handle = -1; 568 571 569 572 int rc = vfs_walk(root, p, flags, handle); -
uspace/lib/posix/Makefile
r10de842 r0d0b319 63 63 source/ctype.c \ 64 64 source/dlfcn.c \ 65 source/errno.c \66 65 source/fcntl.c \ 67 66 source/fnmatch.c \ -
uspace/lib/posix/include/posix/stdlib.h
r10de842 r0d0b319 40 40 #define __POSIX_DEF__(x) x 41 41 #endif 42 43 #include "libc/stdlib.h" 42 44 43 45 #include "sys/types.h" -
uspace/lib/posix/source/fcntl.c
r10de842 r0d0b319 40 40 41 41 #include "libc/vfs/vfs.h" 42 #include "posix/errno.h" 42 43 #include <errno.h> 43 44 44 45 /** … … 103 104 int posix_open(const char *pathname, int posix_flags, ...) 104 105 { 105 int rc;106 106 posix_mode_t posix_mode = 0; 107 107 if (posix_flags & O_CREAT) { … … 136 136 137 137 int file; 138 rc = rcerrno(vfs_lookup, pathname, flags, &file); 139 if ( rc != EOK)138 139 if (failed(vfs_lookup(pathname, flags, &file))) 140 140 return -1; 141 141 142 rc = rcerrno(vfs_open, file, mode); 143 if (rc != EOK) { 142 if (failed(vfs_open(file, mode))) { 144 143 vfs_put(file); 145 144 return -1; … … 148 147 if (posix_flags & O_TRUNC) { 149 148 if (posix_flags & (O_RDWR | O_WRONLY)) { 150 rc = rcerrno(vfs_resize, file, 0); 151 if (rc != EOK) { 149 if (failed(vfs_resize(file, 0))) { 152 150 vfs_put(file); 153 151 return -1; -
uspace/lib/posix/source/internal/common.h
r10de842 r0d0b319 50 50 } while (0) 51 51 52 /* Convert negative errno to positive errno */ 53 #define negerrno(func, ...) ({ \ 54 int rc = func(__VA_ARGS__); \ 55 if (rc < 0) { \ 56 errno = -errno; \ 57 } \ 58 rc; \ 59 }) 60 61 /* Convert error code to positive errno and -1 return value */ 62 #define rcerrno(func, ...) ({ \ 63 int rc = func(__VA_ARGS__); \ 64 if (rc < 0) \ 65 errno = -rc; \ 66 rc; \ 67 }) 52 /* Checks if the value is a failing error code. 53 * If so, writes the error code to errno and returns true. 54 */ 55 static inline bool failed(int rc) { 56 if (rc != EOK) { 57 errno = rc; 58 return true; 59 } 60 return false; 61 } 68 62 69 63 extern aoff64_t posix_pos[MAX_OPEN_FILES]; -
uspace/lib/posix/source/locale.c
r10de842 r0d0b319 39 39 #include "posix/locale.h" 40 40 41 #include "posix/errno.h" 41 #include <errno.h> 42 42 43 #include "posix/limits.h" 43 44 #include "posix/string.h" -
uspace/lib/posix/source/pthread/keys.c
r10de842 r0d0b319 38 38 #include "posix/stdlib.h" 39 39 #include "posix/pthread.h" 40 #include "errno.h"40 #include <errno.h> 41 41 #include "../internal/common.h" 42 42 -
uspace/lib/posix/source/pthread/mutex.c
r10de842 r0d0b319 37 37 38 38 #include "posix/pthread.h" 39 #include "errno.h"39 #include <errno.h> 40 40 #include "../internal/common.h" 41 41 -
uspace/lib/posix/source/pwd.c
r10de842 r0d0b319 39 39 #include "posix/pwd.h" 40 40 #include "posix/string.h" 41 #include "posix/errno.h"41 #include <errno.h> 42 42 #include "posix/assert.h" 43 43 -
uspace/lib/posix/source/signal.c
r10de842 r0d0b319 41 41 #include "posix/stdlib.h" 42 42 #include "posix/string.h" 43 #include "posix/errno.h" 43 44 #include <errno.h> 44 45 45 46 #include "libc/fibril_synch.h" -
uspace/lib/posix/source/stdio.c
r10de842 r0d0b319 41 41 42 42 #include "posix/assert.h" 43 #include "posix/errno.h" 43 44 #include <errno.h> 45 44 46 #include "posix/stdlib.h" 45 47 #include "posix/string.h" … … 313 315 int posix_fflush(FILE *stream) 314 316 { 315 return negerrno(fflush,stream);317 return fflush(stream); 316 318 } 317 319 … … 344 346 const int fildes = *(int *) fd; 345 347 size_t wr; 346 int rc = vfs_write(fildes, &posix_pos[fildes], str, size, &wr); 347 if (rc != EOK) 348 return rc; 348 if (failed(vfs_write(fildes, &posix_pos[fildes], str, size, &wr))) 349 return -1; 349 350 return str_nlength(str, wr); 350 351 } … … 576 577 int posix_remove(const char *path) 577 578 { 578 if ( rcerrno(vfs_unlink_path, path) != EOK)579 if (failed(vfs_unlink_path(path))) 579 580 return -1; 580 581 else … … 591 592 int posix_rename(const char *old, const char *new) 592 593 { 593 int rc = rcerrno(vfs_rename_path, old, new); 594 if (rc != EOK) 594 if (failed(vfs_rename_path(old, new))) 595 595 return -1; 596 596 else … … 664 664 665 665 int orig_errno = errno; 666 errno = 0;666 errno = EOK; 667 667 /* Check if the file exists. */ 668 668 if (posix_access(result, F_OK) == -1) { -
uspace/lib/posix/source/stdio/scanf.c
r10de842 r0d0b319 37 37 38 38 #include "posix/assert.h" 39 #include "posix/errno.h" 39 40 #include <errno.h> 40 41 41 42 #include "posix/stdio.h" -
uspace/lib/posix/source/stdlib.c
r10de842 r0d0b319 40 40 #include "posix/stdlib.h" 41 41 42 #include "posix/errno.h" 42 #include <errno.h> 43 43 44 #include "posix/fcntl.h" 44 45 #include "posix/limits.h" -
uspace/lib/posix/source/stdlib/strtol.c
r10de842 r0d0b319 40 40 41 41 #include "posix/ctype.h" 42 #include "posix/errno.h" 42 43 #include <errno.h> 44 43 45 #include "posix/inttypes.h" 44 46 #include "posix/limits.h" -
uspace/lib/posix/source/stdlib/strtold.c
r10de842 r0d0b319 44 44 #include "posix/stdint.h" 45 45 #include "posix/strings.h" 46 #include "posix/errno.h" 46 47 #include <errno.h> 48 47 49 #include "posix/limits.h" 48 50 -
uspace/lib/posix/source/string.c
r10de842 r0d0b319 41 41 42 42 #include "posix/assert.h" 43 #include "posix/errno.h" 43 44 #include <errno.h> 45 44 46 #include "posix/limits.h" 45 47 #include "posix/stdlib.h" … … 615 617 char *posix_strerror(int errnum) 616 618 { 617 static const char *error_msgs[] = { 618 [E2BIG] = "[E2BIG] Argument list too long", 619 [EACCES] = "[EACCES] Permission denied", 620 [EADDRINUSE] = "[EADDRINUSE] Address in use", 621 [EADDRNOTAVAIL] = "[EADDRNOTAVAIL] Address not available", 622 [EAFNOSUPPORT] = "[EAFNOSUPPORT] Address family not supported", 623 [EAGAIN] = "[EAGAIN] Resource unavailable, try again", 624 [EALREADY] = "[EALREADY] Connection already in progress", 625 [EBADF] = "[EBADF] Bad file descriptor", 626 [EBADMSG] = "[EBADMSG] Bad message", 627 [EBUSY] = "[EBUSY] Device or resource busy", 628 [ECANCELED] = "[ECANCELED] Operation canceled", 629 [ECHILD] = "[ECHILD] No child processes", 630 [ECONNABORTED] = "[ECONNABORTED] Connection aborted", 631 [ECONNREFUSED] = "[ECONNREFUSED] Connection refused", 632 [ECONNRESET] = "[ECONNRESET] Connection reset", 633 [EDEADLK] = "[EDEADLK] Resource deadlock would occur", 634 [EDESTADDRREQ] = "[EDESTADDRREQ] Destination address required", 635 [EDOM] = "[EDOM] Mathematics argument out of domain of function", 636 [EDQUOT] = "[EDQUOT] Reserved", 637 [EEXIST] = "[EEXIST] File exists", 638 [EFAULT] = "[EFAULT] Bad address", 639 [EFBIG] = "[EFBIG] File too large", 640 [EHOSTUNREACH] = "[EHOSTUNREACH] Host is unreachable", 641 [EIDRM] = "[EIDRM] Identifier removed", 642 [EILSEQ] = "[EILSEQ] Illegal byte sequence", 643 [EINPROGRESS] = "[EINPROGRESS] Operation in progress", 644 [EINTR] = "[EINTR] Interrupted function", 645 [EINVAL] = "[EINVAL] Invalid argument", 646 [EIO] = "[EIO] I/O error", 647 [EISCONN] = "[EISCONN] Socket is connected", 648 [EISDIR] = "[EISDIR] Is a directory", 649 [ELOOP] = "[ELOOP] Too many levels of symbolic links", 650 [EMFILE] = "[EMFILE] File descriptor value too large", 651 [EMLINK] = "[EMLINK] Too many links", 652 [EMSGSIZE] = "[EMSGSIZE] Message too large", 653 [EMULTIHOP] = "[EMULTIHOP] Reserved", 654 [ENAMETOOLONG] = "[ENAMETOOLONG] Filename too long", 655 [ENETDOWN] = "[ENETDOWN] Network is down", 656 [ENETRESET] = "[ENETRESET] Connection aborted by network", 657 [ENETUNREACH] = "[ENETUNREACH] Network unreachable", 658 [ENFILE] = "[ENFILE] Too many files open in system", 659 [ENOBUFS] = "[ENOBUFS] No buffer space available", 660 [ENODATA] = "[ENODATA] No message is available on the STREAM head read queue", 661 [ENODEV] = "[ENODEV] No such device", 662 [ENOENT] = "[ENOENT] No such file or directory", 663 [ENOEXEC] = "[ENOEXEC] Executable file format error", 664 [ENOLCK] = "[ENOLCK] No locks available", 665 [ENOLINK] = "[ENOLINK] Reserved", 666 [ENOMEM] = "[ENOMEM] Not enough space", 667 [ENOMSG] = "[ENOMSG] No message of the desired type", 668 [ENOPROTOOPT] = "[ENOPROTOOPT] Protocol not available", 669 [ENOSPC] = "[ENOSPC] No space left on device", 670 [ENOSR] = "[ENOSR] No STREAM resources.", 671 [ENOSTR] = "[ENOSTR] Not a STREAM", 672 [ENOSYS] = "[ENOSYS] Function not supported", 673 [ENOTCONN] = "[ENOTCONN] The socket is not connected", 674 [ENOTDIR] = "[ENOTDIR] Not a directory", 675 [ENOTEMPTY] = "[ENOTEMPTY] Directory not empty", 676 [ENOTRECOVERABLE] = "[ENOTRECOVERABLE] State not recoverable", 677 [ENOTSOCK] = "[ENOTSOCK] Not a socket", 678 [ENOTSUP] = "[ENOTSUP] Not supported", 679 [ENOTTY] = "[ENOTTY] Inappropriate I/O control operation", 680 [ENXIO] = "[ENXIO] No such device or address", 681 [EOPNOTSUPP] = "[EOPNOTSUPP] Operation not supported", 682 [EOVERFLOW] = "[EOVERFLOW] Value too large to be stored in data type", 683 [EOWNERDEAD] = "[EOWNERDEAD] Previous owned died", 684 [EPERM] = "[EPERM] Operation not permitted", 685 [EPIPE] = "[EPIPE] Broken pipe", 686 [EPROTO] = "[EPROTO] Protocol error", 687 [EPROTONOSUPPORT] = "[EPROTONOSUPPORT] Protocol not supported", 688 [EPROTOTYPE] = "[EPROTOTYPE] Protocol wrong type for socket", 689 [ERANGE] = "[ERANGE] Result too large", 690 [EROFS] = "[EROFS] Read-only file system", 691 [ESPIPE] = "[ESPIPE] Invalid seek", 692 [ESRCH] = "[ESRCH] No such process", 693 [ESTALE] = "[ESTALE] Reserved", 694 [ETIME] = "[ETIME] Stream ioctl() timeout", 695 [ETIMEDOUT] = "[ETIMEDOUT] Connection timed out", 696 [ETXTBSY] = "[ETXTBSY] Text file busy", 697 [EWOULDBLOCK] = "[EWOULDBLOCK] Operation would block", 698 [EXDEV] = "[EXDEV] Cross-device link", 699 }; 700 701 return (char *) error_msgs[posix_abs(errnum)]; 619 // FIXME: move strerror() and strerror_r() to libc. 620 return (char *) str_error(errnum); 702 621 } 703 622 … … 722 641 } 723 642 724 return 0;643 return EOK; 725 644 } 726 645 -
uspace/lib/posix/source/sys/mman.c
r10de842 r0d0b319 59 59 int posix_munmap(void *start, size_t length) 60 60 { 61 return as_area_destroy(start); 61 int rc = as_area_destroy(start); 62 if (rc != EOK) { 63 errno = rc; 64 return -1; 65 } 66 return 0; 62 67 } 63 68 -
uspace/lib/posix/source/sys/stat.c
r10de842 r0d0b319 41 41 #include "libc/vfs/vfs.h" 42 42 43 #include "posix/errno.h"43 #include <errno.h> 44 44 #include "libc/mem.h" 45 45 … … 89 89 { 90 90 struct stat hst; 91 int rc = rcerrno(vfs_stat, fd, &hst); 92 if (rc < 0) 91 if (failed(vfs_stat(fd, &hst))) 93 92 return -1; 94 93 return stat_to_posix(st, &hst); … … 118 117 { 119 118 struct stat hst; 120 int rc = rcerrno(vfs_stat_path, path, &hst); 121 if (rc < 0) 119 if (failed(vfs_stat_path(path, &hst))) 122 120 return -1; 123 121 return stat_to_posix(st, &hst); … … 159 157 int posix_mkdir(const char *path, posix_mode_t mode) 160 158 { 161 int rc = rcerrno(vfs_link_path, path, KIND_DIRECTORY, NULL); 162 if (rc != EOK) 159 if (failed(vfs_link_path(path, KIND_DIRECTORY, NULL))) 163 160 return -1; 164 161 else -
uspace/lib/posix/source/sys/wait.c
r10de842 r0d0b319 42 42 #include "libc/task.h" 43 43 #include "posix/assert.h" 44 #include "posix/errno.h" 44 45 #include <errno.h> 46 45 47 #include "posix/limits.h" 46 48 #include "posix/signal.h" … … 100 102 int retval; 101 103 102 int rc = task_wait_task_id((task_id_t) pid, &texit, &retval); 103 104 if (rc < 0) { 104 if (failed(task_wait_task_id((task_id_t) pid, &texit, &retval))) { 105 105 /* Unable to retrieve status. */ 106 errno = -rc;107 106 return (posix_pid_t) -1; 108 107 } -
uspace/lib/posix/source/time.c
r10de842 r0d0b319 41 41 42 42 #include "posix/ctype.h" 43 #include "posix/errno.h" 43 44 #include <errno.h> 45 44 46 #include "posix/signal.h" 45 47 #include "posix/assert.h" … … 100 102 struct tm *restrict result) 101 103 { 102 int rc = time_utc2tm(*timer, result); 103 if (rc != EOK) { 104 errno = rc; 104 if (failed(time_utc2tm(*timer, result))) { 105 105 return NULL; 106 106 } … … 197 197 char *posix_ctime_r(const time_t *timer, char *buf) 198 198 { 199 int r = time_local2str(*timer, buf); 200 if (r != EOK) { 201 errno = r; 199 if (failed(time_local2str(*timer, buf))) { 202 200 return NULL; 203 201 } -
uspace/lib/posix/source/unistd.c
r10de842 r0d0b319 40 40 #include "posix/unistd.h" 41 41 42 #include "posix/errno.h" 42 #include <errno.h> 43 43 44 #include "posix/string.h" 44 45 #include "posix/fcntl.h" … … 52 53 #include <libarch/config.h> 53 54 55 // FIXME: replace with a hash table 54 56 aoff64_t posix_pos[MAX_OPEN_FILES]; 55 57 … … 126 128 char *posix_getcwd(char *buf, size_t size) 127 129 { 128 int rc = rcerrno(vfs_cwd_get, buf, size); 129 if (rc != EOK) 130 if (failed(vfs_cwd_get(buf, size))) 130 131 return NULL; 131 132 return buf; … … 139 140 int posix_chdir(const char *path) 140 141 { 141 int rc = rcerrno(vfs_cwd_set, path); 142 if (rc != EOK) 142 if (failed(vfs_cwd_set(path))) 143 143 return -1; 144 144 return 0; … … 196 196 { 197 197 posix_pos[fildes] = 0; 198 int rc = rcerrno(vfs_put, fildes); 199 if (rc != EOK) 198 if (failed(vfs_put(fildes))) 200 199 return -1; 201 200 else … … 214 213 { 215 214 size_t nread; 216 int rc; 217 218 rc = rcerrno(vfs_read, fildes, &posix_pos[fildes], buf, nbyte, &nread); 219 if (rc != EOK) 215 if (failed(vfs_read(fildes, &posix_pos[fildes], buf, nbyte, &nread))) 220 216 return -1; 221 217 return (ssize_t) nread; … … 233 229 { 234 230 size_t nwr; 235 int rc; 236 237 rc = rcerrno(vfs_write, fildes, &posix_pos[fildes], buf, nbyte, &nwr); 238 if (rc != EOK) 231 if (failed(vfs_write(fildes, &posix_pos[fildes], buf, nbyte, &nwr))) 239 232 return -1; 240 233 return nwr; … … 253 246 { 254 247 struct stat st; 255 int rc;256 248 257 249 switch (whence) { … … 263 255 break; 264 256 case SEEK_END: 265 rc = rcerrno(vfs_stat, fildes, &st); 266 if (rc != EOK) 257 if (failed(vfs_stat(fildes, &st))) 267 258 return -1; 268 259 posix_pos[fildes] = st.size + offset; … … 285 276 int posix_fsync(int fildes) 286 277 { 287 if ( rcerrno(vfs_sync, fildes) != EOK)278 if (failed(vfs_sync(fildes))) 288 279 return -1; 289 280 else … … 300 291 int posix_ftruncate(int fildes, posix_off_t length) 301 292 { 302 if ( rcerrno(vfs_resize, fildes, (aoff64_t) length) != EOK)293 if (failed(vfs_resize(fildes, (aoff64_t) length))) 303 294 return -1; 304 295 else … … 314 305 int posix_rmdir(const char *path) 315 306 { 316 if ( rcerrno(vfs_unlink_path, path) != EOK)307 if (failed(vfs_unlink_path(path))) 317 308 return -1; 318 309 else … … 328 319 int posix_unlink(const char *path) 329 320 { 330 if ( rcerrno(vfs_unlink_path, path) != EOK)321 if (failed(vfs_unlink_path(path))) 331 322 return -1; 332 323 else … … 356 347 { 357 348 int file; 358 int rc = vfs_clone(fildes, fildes2, false, &file); 359 if (rc != EOK) { 360 errno = rc < 0 ? -rc : rc; 349 if (failed(vfs_clone(fildes, fildes2, false, &file))) { 361 350 return -1; 362 351 } -
uspace/lib/posix/test/scanf.c
r10de842 r0d0b319 30 30 #define __POSIX_DEF__(x) posix_##x 31 31 32 #include "posix/errno.h" 32 #include <errno.h> 33 33 34 #include "posix/stdio.h" 34 35
Note:
See TracChangeset
for help on using the changeset viewer.