Changeset 9af1c61 in mainline


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.

Location:
uspace
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    r82d515e9 r9af1c61  
    3131#include <stdlib.h>
    3232#include <stdint.h>
     33#include <str_error.h>
    3334#include <dirent.h>
    3435#include <macros.h>
     
    191192                rc = vfs_write(fd, &pos, buffer, to_write, &nwritten);
    192193                if (rc != EOK) {
    193                         printf("%s: Error writing file (%d).\n", cmdname, errno);
     194                        printf("%s: Error writing file (%s).\n", cmdname, str_error(errno));
    194195                        vfs_put(fd);
    195196                        free(buffer);
     
    206207        return CMD_SUCCESS;
    207208error:
    208         printf("%s: Error writing file (%d).\n", cmdname, errno);
     209        printf("%s: Error writing file (%s).\n", cmdname, str_error(errno));
    209210        return CMD_FAILURE;
    210211}
  • uspace/app/df/df.c

    r82d515e9 r9af1c61  
    4040#include <stdlib.h>
    4141#include <stdint.h>
     42#include <str_error.h>
    4243#include <getopt.h>
    4344#include <errno.h>
     
    118119                                return 1;
    119120                } else {
    120                         fprintf(stderr, "Cannot get information for '%s' (%d).\n",
    121                             mtab_ent->mp, errno);
     121                        fprintf(stderr, "Cannot get information for '%s' (%s).\n",
     122                            mtab_ent->mp, str_error(errno));
    122123                }
    123124        }
  • uspace/app/taskdump/taskdump.c

    r82d515e9 r9af1c61  
    4040#include <stddef.h>
    4141#include <stdbool.h>
     42#include <str_error.h>
    4243#include <errno.h>
    4344#include <udebug.h>
     
    135136               
    136137                printf("Error connecting\n");
    137                 printf("async_connect_kbox(%" PRIu64 ") -> %d ", task_id, errno);
     138                printf("async_connect_kbox(%" PRIu64 ") -> %s", task_id, str_error_name(errno));
    138139                return errno;
    139140        }
  • uspace/app/tester/stdio/stdio1.c

    r82d515e9 r9af1c61  
    3030#include <stdlib.h>
    3131#include <stddef.h>
     32#include <str_error.h>
    3233#include <errno.h>
    3334#include "../tester.h"
     
    4647        file = fopen(file_name, "rt");
    4748        if (file == NULL) {
    48                 TPRINTF("errno = %d\n", errno);
     49                TPRINTF("errno = %s\n", str_error_name(errno));
    4950                return "Failed opening file";
    5051        } else
     
    5455        size_t cnt = fread(buf, 1, BUF_SIZE, file);
    5556        if (ferror(file)) {
    56                 TPRINTF("errno = %d\n", errno);
     57                TPRINTF("errno = %s\n", str_error_name(errno));
    5758                fclose(file);
    5859                return "Failed reading file";
     
    6566        TPRINTF("Seek to beginning...");
    6667        if (fseek(file, 0, SEEK_SET) != 0) {
    67                 TPRINTF("errno = %d\n", errno);
     68                TPRINTF("errno = %s\n", str_error_name(errno));
    6869                fclose(file);
    6970                return "Failed seeking in file";
     
    8384        TPRINTF("Close...");
    8485        if (fclose(file) != 0) {
    85                 TPRINTF("errno = %d\n", errno);
     86                TPRINTF("errno = %s\n", str_error_name(errno));
    8687                return "Failed closing file";
    8788        } else
  • uspace/app/tester/stdio/stdio2.c

    r82d515e9 r9af1c61  
    3030#include <stdlib.h>
    3131#include <stddef.h>
     32#include <str_error.h>
    3233#include <errno.h>
    3334#include "../tester.h"
     
    4243        file = fopen(file_name, "wt");
    4344        if (file == NULL) {
    44                 TPRINTF("errno = %d\n", errno);
     45                TPRINTF("errno = %s\n", str_error_name(errno));
    4546                return "Failed opening file";
    4647        } else
     
    5354        TPRINTF("Close...");
    5455        if (fclose(file) != 0) {
    55                 TPRINTF("errno = %d\n", errno);
     56                TPRINTF("errno = %s\n", str_error_name(errno));
    5657                return "Failed closing file";
    5758        } else
     
    6162        file = fopen(file_name, "rt");
    6263        if (file == NULL) {
    63                 TPRINTF("errno = %d\n", errno);
     64                TPRINTF("errno = %s\n", str_error_name(errno));
    6465                return "Failed opening file";
    6566        } else
     
    7677        TPRINTF("\nClose...");
    7778        if (fclose(file) != 0) {
    78                 TPRINTF("errno = %d\n", errno);
     79                TPRINTF("errno = %s\n", str_error_name(errno));
    7980                return "Failed closing file";
    8081        } else
  • uspace/app/trace/trace.c

    r82d515e9 r9af1c61  
    3838#include <stdint.h>
    3939#include <stddef.h>
     40#include <str_error.h>
    4041#include <inttypes.h>
    4142#include <fibril.h>
     
    157158               
    158159                printf("Error connecting\n");
    159                 printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, errno);
     160                printf("ipc_connect_task(%" PRIu64 ") -> %s ", task_id, str_error_name(errno));
    160161                return errno;
    161162        }
  • uspace/lib/c/generic/errno.c

    r82d515e9 r9af1c61  
    3636#include <fibril.h>
    3737
    38 static fibril_local int fibril_errno;
     38static fibril_local errno_t fibril_errno;
    3939
    40 int *__errno(void)
     40errno_t *__errno(void)
    4141{
    4242        return &fibril_errno;
  • 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}
  • uspace/lib/c/include/str_error.h

    r82d515e9 r9af1c61  
    3636#define LIBC_STRERROR_H_
    3737
    38 const char *str_error(const int);
     38#include <errno.h>
     39
     40const char *str_error(errno_t);
     41const char *str_error_name(errno_t);
    3942
    4043#endif
  • uspace/srv/devman/match.c

    r82d515e9 r9af1c61  
    232232        int rc = vfs_read(fd, (aoff64_t []) {0}, buf, len, &read_bytes);
    233233        if (rc != EOK) {
    234                 log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to read file '%s' (%d).", conf_path,
    235                     errno);
     234                log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to read file '%s': %s.", conf_path,
     235                    str_error(errno));
    236236                goto cleanup;
    237237        }
Note: See TracChangeset for help on using the changeset viewer.