Changeset 9af1c61 in mainline for uspace/lib/c/generic/str_error.c


Ignore:
Timestamp:
2017-12-05T14:52:22Z (6 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:
addbce4
Parents:
82d515e9
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2017-12-05 14:50:38)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2017-12-05 14:52:22)
Message:

Print errno values as string, rather than just numbers.

File:
1 edited

Legend:

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

    r82d515e9 r9af1c61  
    4141#define NOERR_LEN  64
    4242
     43// TODO: this file should be generated from errno declarations
     44
     45static const char* err_name[] = {
     46        "EOK",
     47        "ENOENT",
     48        "ENOMEM",
     49        "ELIMIT",
     50        "EREFUSED",
     51        "EFORWARD",
     52        "EPERM",
     53        "EHANGUP",
     54        "EPARTY",
     55        "EEXIST",
     56        "EBADMEM",
     57        "ENOTSUP",
     58        "EADDRNOTAVAIL",
     59        "ETIMEOUT",
     60        "EINVAL",
     61        "EBUSY",
     62        "EOVERFLOW",
     63        "EINTR"
     64};
     65
    4366static const char* err_desc[] = {
    4467        "No error",
    4568        "No such entry",
    4669        "Not enough memory",
    47         "Limit exceeded", 
     70        "Limit exceeded",
    4871        "Connection refused",
    4972        "Forwarding error",
     
    6487static fibril_local char noerr[NOERR_LEN];
    6588
    66 const char *str_error(const int e)
     89const char *str_error_name(errno_t e)
     90{
     91        if ((e <= 0) && (e >= MIN_ERRNO))
     92                return err_name[-e];
     93
     94        /* Ad hoc descriptions of error codes interesting for USB. */
     95        // FIXME: integrate these as first-class error values
     96        switch (e) {
     97                case ENOFS:
     98                        return "ENOFS";
     99                case EBADCHECKSUM:
     100                        return "EBADCHECKSUM";
     101                case ESTALL:
     102                        return "ESTALL";
     103                case EAGAIN:
     104                        return "EAGAIN";
     105                case EEMPTY:
     106                        return "EEMPTY";
     107                default:
     108                        break;
     109        }
     110
     111        snprintf(noerr, NOERR_LEN, "(%d)", (int)e);
     112        return noerr;
     113}
     114
     115const char *str_error(errno_t e)
    67116{
    68117        if ((e <= 0) && (e >= MIN_ERRNO))
     
    86135        }
    87136
    88         snprintf(noerr, NOERR_LEN, "Unkown error code %d", e);
     137        snprintf(noerr, NOERR_LEN, "Unknown error code (%d)", (int)e);
    89138        return noerr;
    90139}
Note: See TracChangeset for help on using the changeset viewer.