Changeset 0d0b319 in mainline for uspace


Ignore:
Timestamp:
2018-01-04T20:03:02Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
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)
Message:

Flip error constants to positive values, and update libposix for the change.

Location:
uspace/lib
Files:
2 deleted
22 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/vfs/vfs.c

    r10de842 r0d0b319  
    566566                return ENOENT;
    567567        }
     568
     569        // XXX: Workaround for GCC diagnostics.
     570        *handle = -1;
    568571
    569572        int rc = vfs_walk(root, p, flags, handle);
  • uspace/lib/posix/Makefile

    r10de842 r0d0b319  
    6363        source/ctype.c \
    6464        source/dlfcn.c \
    65         source/errno.c \
    6665        source/fcntl.c \
    6766        source/fnmatch.c \
  • uspace/lib/posix/include/posix/stdlib.h

    r10de842 r0d0b319  
    4040#define __POSIX_DEF__(x) x
    4141#endif
     42
     43#include "libc/stdlib.h"
    4244
    4345#include "sys/types.h"
  • uspace/lib/posix/source/fcntl.c

    r10de842 r0d0b319  
    4040
    4141#include "libc/vfs/vfs.h"
    42 #include "posix/errno.h"
     42
     43#include <errno.h>
    4344
    4445/**
     
    103104int posix_open(const char *pathname, int posix_flags, ...)
    104105{
    105         int rc;
    106106        posix_mode_t posix_mode = 0;
    107107        if (posix_flags & O_CREAT) {
     
    136136
    137137        int file;
    138         rc = rcerrno(vfs_lookup, pathname, flags, &file);
    139         if (rc != EOK)
     138
     139        if (failed(vfs_lookup(pathname, flags, &file)))
    140140                return -1;
    141141
    142         rc = rcerrno(vfs_open, file, mode);
    143         if (rc != EOK) {
     142        if (failed(vfs_open(file, mode))) {
    144143                vfs_put(file);
    145144                return -1;
     
    148147        if (posix_flags & O_TRUNC) {
    149148                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))) {
    152150                                vfs_put(file);
    153151                                return -1;
  • uspace/lib/posix/source/internal/common.h

    r10de842 r0d0b319  
    5050        } while (0)
    5151
    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 */
     55static inline bool failed(int rc) {
     56        if (rc != EOK) {
     57                errno = rc;
     58                return true;
     59        }
     60        return false;
     61}
    6862
    6963extern aoff64_t posix_pos[MAX_OPEN_FILES];
  • uspace/lib/posix/source/locale.c

    r10de842 r0d0b319  
    3939#include "posix/locale.h"
    4040
    41 #include "posix/errno.h"
     41#include <errno.h>
     42
    4243#include "posix/limits.h"
    4344#include "posix/string.h"
  • uspace/lib/posix/source/pthread/keys.c

    r10de842 r0d0b319  
    3838#include "posix/stdlib.h"
    3939#include "posix/pthread.h"
    40 #include "errno.h"
     40#include <errno.h>
    4141#include "../internal/common.h"
    4242
  • uspace/lib/posix/source/pthread/mutex.c

    r10de842 r0d0b319  
    3737
    3838#include "posix/pthread.h"
    39 #include "errno.h"
     39#include <errno.h>
    4040#include "../internal/common.h"
    4141
  • uspace/lib/posix/source/pwd.c

    r10de842 r0d0b319  
    3939#include "posix/pwd.h"
    4040#include "posix/string.h"
    41 #include "posix/errno.h"
     41#include <errno.h>
    4242#include "posix/assert.h"
    4343
  • uspace/lib/posix/source/signal.c

    r10de842 r0d0b319  
    4141#include "posix/stdlib.h"
    4242#include "posix/string.h"
    43 #include "posix/errno.h"
     43
     44#include <errno.h>
    4445
    4546#include "libc/fibril_synch.h"
  • uspace/lib/posix/source/stdio.c

    r10de842 r0d0b319  
    4141
    4242#include "posix/assert.h"
    43 #include "posix/errno.h"
     43
     44#include <errno.h>
     45
    4446#include "posix/stdlib.h"
    4547#include "posix/string.h"
     
    313315int posix_fflush(FILE *stream)
    314316{
    315         return negerrno(fflush, stream);
     317        return fflush(stream);
    316318}
    317319
     
    344346        const int fildes = *(int *) fd;
    345347        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;
    349350        return str_nlength(str, wr);
    350351}
     
    576577int posix_remove(const char *path)
    577578{
    578         if (rcerrno(vfs_unlink_path, path) != EOK)
     579        if (failed(vfs_unlink_path(path)))
    579580                return -1;
    580581        else
     
    591592int posix_rename(const char *old, const char *new)
    592593{
    593         int rc = rcerrno(vfs_rename_path, old, new);
    594         if (rc != EOK)
     594        if (failed(vfs_rename_path(old, new)))
    595595                return -1;
    596596        else
     
    664664               
    665665                int orig_errno = errno;
    666                 errno = 0;
     666                errno = EOK;
    667667                /* Check if the file exists. */
    668668                if (posix_access(result, F_OK) == -1) {
  • uspace/lib/posix/source/stdio/scanf.c

    r10de842 r0d0b319  
    3737
    3838#include "posix/assert.h"
    39 #include "posix/errno.h"
     39
     40#include <errno.h>
    4041
    4142#include "posix/stdio.h"
  • uspace/lib/posix/source/stdlib.c

    r10de842 r0d0b319  
    4040#include "posix/stdlib.h"
    4141
    42 #include "posix/errno.h"
     42#include <errno.h>
     43
    4344#include "posix/fcntl.h"
    4445#include "posix/limits.h"
  • uspace/lib/posix/source/stdlib/strtol.c

    r10de842 r0d0b319  
    4040
    4141#include "posix/ctype.h"
    42 #include "posix/errno.h"
     42
     43#include <errno.h>
     44
    4345#include "posix/inttypes.h"
    4446#include "posix/limits.h"
  • uspace/lib/posix/source/stdlib/strtold.c

    r10de842 r0d0b319  
    4444#include "posix/stdint.h"
    4545#include "posix/strings.h"
    46 #include "posix/errno.h"
     46
     47#include <errno.h>
     48
    4749#include "posix/limits.h"
    4850
  • uspace/lib/posix/source/string.c

    r10de842 r0d0b319  
    4141
    4242#include "posix/assert.h"
    43 #include "posix/errno.h"
     43
     44#include <errno.h>
     45
    4446#include "posix/limits.h"
    4547#include "posix/stdlib.h"
     
    615617char *posix_strerror(int errnum)
    616618{
    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);
    702621}
    703622
     
    722641        }
    723642
    724         return 0;
     643        return EOK;
    725644}
    726645
  • uspace/lib/posix/source/sys/mman.c

    r10de842 r0d0b319  
    5959int posix_munmap(void *start, size_t length)
    6060{
    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;
    6267}
    6368
  • uspace/lib/posix/source/sys/stat.c

    r10de842 r0d0b319  
    4141#include "libc/vfs/vfs.h"
    4242
    43 #include "posix/errno.h"
     43#include <errno.h>
    4444#include "libc/mem.h"
    4545
     
    8989{
    9090        struct stat hst;
    91         int rc = rcerrno(vfs_stat, fd, &hst);
    92         if (rc < 0)
     91        if (failed(vfs_stat(fd, &hst)))
    9392                return -1;
    9493        return stat_to_posix(st, &hst);
     
    118117{
    119118        struct stat hst;
    120         int rc = rcerrno(vfs_stat_path, path, &hst);
    121         if (rc < 0)
     119        if (failed(vfs_stat_path(path, &hst)))
    122120                return -1;
    123121        return stat_to_posix(st, &hst);
     
    159157int posix_mkdir(const char *path, posix_mode_t mode)
    160158{
    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)))
    163160                return -1;
    164161        else
  • uspace/lib/posix/source/sys/wait.c

    r10de842 r0d0b319  
    4242#include "libc/task.h"
    4343#include "posix/assert.h"
    44 #include "posix/errno.h"
     44
     45#include <errno.h>
     46
    4547#include "posix/limits.h"
    4648#include "posix/signal.h"
     
    100102        int retval;
    101103       
    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))) {
    105105                /* Unable to retrieve status. */
    106                 errno = -rc;
    107106                return (posix_pid_t) -1;
    108107        }
  • uspace/lib/posix/source/time.c

    r10de842 r0d0b319  
    4141
    4242#include "posix/ctype.h"
    43 #include "posix/errno.h"
     43
     44#include <errno.h>
     45
    4446#include "posix/signal.h"
    4547#include "posix/assert.h"
     
    100102    struct tm *restrict result)
    101103{
    102         int rc = time_utc2tm(*timer, result);
    103         if (rc != EOK) {
    104                 errno = rc;
     104        if (failed(time_utc2tm(*timer, result))) {
    105105                return NULL;
    106106        }
     
    197197char *posix_ctime_r(const time_t *timer, char *buf)
    198198{
    199         int r = time_local2str(*timer, buf);
    200         if (r != EOK) {
    201                 errno = r;
     199        if (failed(time_local2str(*timer, buf))) {
    202200                return NULL;
    203201        }
  • uspace/lib/posix/source/unistd.c

    r10de842 r0d0b319  
    4040#include "posix/unistd.h"
    4141
    42 #include "posix/errno.h"
     42#include <errno.h>
     43
    4344#include "posix/string.h"
    4445#include "posix/fcntl.h"
     
    5253#include <libarch/config.h>
    5354
     55// FIXME: replace with a hash table
    5456aoff64_t posix_pos[MAX_OPEN_FILES];
    5557
     
    126128char *posix_getcwd(char *buf, size_t size)
    127129{
    128         int rc = rcerrno(vfs_cwd_get, buf, size);
    129         if (rc != EOK)
     130        if (failed(vfs_cwd_get(buf, size)))
    130131                return NULL;
    131132        return buf;
     
    139140int posix_chdir(const char *path)
    140141{
    141         int rc = rcerrno(vfs_cwd_set, path);
    142         if (rc != EOK)
     142        if (failed(vfs_cwd_set(path)))
    143143                return -1;
    144144        return 0;
     
    196196{
    197197        posix_pos[fildes] = 0;
    198         int rc = rcerrno(vfs_put, fildes);
    199         if (rc != EOK)
     198        if (failed(vfs_put(fildes)))
    200199                return -1;
    201200        else
     
    214213{
    215214        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)))
    220216                return -1;
    221217        return (ssize_t) nread;
     
    233229{
    234230        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)))
    239232                return -1;
    240233        return nwr;
     
    253246{
    254247        struct stat st;
    255         int rc;
    256248
    257249        switch (whence) {
     
    263255                break;
    264256        case SEEK_END:
    265                 rc = rcerrno(vfs_stat, fildes, &st);
    266                 if (rc != EOK)
     257                if (failed(vfs_stat(fildes, &st)))
    267258                        return -1;
    268259                posix_pos[fildes] = st.size + offset;
     
    285276int posix_fsync(int fildes)
    286277{
    287         if (rcerrno(vfs_sync, fildes) != EOK)
     278        if (failed(vfs_sync(fildes)))
    288279                return -1;
    289280        else
     
    300291int posix_ftruncate(int fildes, posix_off_t length)
    301292{
    302         if (rcerrno(vfs_resize, fildes, (aoff64_t) length) != EOK)
     293        if (failed(vfs_resize(fildes, (aoff64_t) length)))
    303294                return -1;
    304295        else
     
    314305int posix_rmdir(const char *path)
    315306{
    316         if (rcerrno(vfs_unlink_path, path) != EOK)
     307        if (failed(vfs_unlink_path(path)))
    317308                return -1;
    318309        else
     
    328319int posix_unlink(const char *path)
    329320{
    330         if (rcerrno(vfs_unlink_path, path) != EOK)
     321        if (failed(vfs_unlink_path(path)))
    331322                return -1;
    332323        else
     
    356347{
    357348        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))) {
    361350                return -1;
    362351        }
  • uspace/lib/posix/test/scanf.c

    r10de842 r0d0b319  
    3030#define __POSIX_DEF__(x) posix_##x
    3131
    32 #include "posix/errno.h"
     32#include <errno.h>
     33
    3334#include "posix/stdio.h"
    3435
Note: See TracChangeset for help on using the changeset viewer.