Changeset 3529fbf0 in mainline


Ignore:
Timestamp:
2017-12-19T15:18:40Z (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:
74a2a2d
Parents:
bdb8ba9
Message:

Ensure that errno.h constants aren't missing textual descriptions.

Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • Makefile

    rbdb8ba9 r3529fbf0  
    4444CONFIG_MAKEFILE = Makefile.config
    4545CONFIG_HEADER = config.h
     46ERRNO_HEADER = abi/include/abi/errno.h
     47ERRNO_INPUT = abi/include/abi/errno.in
    4648
    4749.PHONY: all precheck cscope cscope_parts autotool config_auto config_default config distclean clean check releasefile release common boot kernel uspace
     
    5052        $(MAKE) -r -C boot PRECHECK=$(PRECHECK)
    5153
    52 common: $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER)
     54common: $(COMMON_MAKEFILE) $(COMMON_HEADER) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(ERRNO_HEADER)
    5355
    5456kernel: common
     
    125127        $(MAKE) -r -C doxygen clean
    126128
     129$(ERRNO_HEADER): $(ERRNO_INPUT)
     130        echo '/* Generated file. Edit errno.in instead. */' > $@.new
     131        sed 's/__errno_entry(\([^,]*\),\([^,]*\),.*/#define \1 \2/' < $< >> $@.new
     132        mv $@.new $@
     133
    127134-include Makefile.local
  • abi/include/abi/errno.h

    rbdb8ba9 r3529fbf0  
    1 /*
    2  * Copyright (c) 2005 Martin Decky
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  *
    9  * - Redistributions of source code must retain the above copyright
    10  *   notice, this list of conditions and the following disclaimer.
    11  * - Redistributions in binary form must reproduce the above copyright
    12  *   notice, this list of conditions and the following disclaimer in the
    13  *   documentation and/or other materials provided with the distribution.
    14  * - The name of the author may not be used to endorse or promote products
    15  *   derived from this software without specific prior written permission.
    16  *
    17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    27  */
    28 
    29 /** @addtogroup generic
    30  * @{
    31  */
    32 /** @file
    33  */
    34 
    35 #ifndef ABI_ERRNO_H_
    36 #define ABI_ERRNO_H_
    37 
    38 /**
    39  * Values in the range [-1, -255] are kernel error codes,
    40  * values in the range [-256, -512] are user error codes.
    41  */
    42 
    43 typedef enum {
    44         EOK           =  0,   /* No error */
    45         ENOENT        = -1,   /* No such entry */
    46         ENOMEM        = -2,   /* Not enough memory */
    47         ELIMIT        = -3,   /* Limit exceeded */
    48         EREFUSED      = -4,   /* Connection refused */
    49         EFORWARD      = -5,   /* Forward error */
    50         EPERM         = -6,   /* Permission denied */
    51 
    52 /*
    53  * Answerbox closed connection, call
    54  * sys_ipc_hangup() to close the connection.
    55  * Used by answerbox to close the connection.
    56  */
    57         EHANGUP       = -7,
    58 
    59 /*
    60  * The other party encountered an error when
    61  * receiving the call.
    62  */
    63         EPARTY        = -8,
    64 
    65         EEXIST        = -9,   /* Entry already exists */
    66         EBADMEM       = -10,  /* Bad memory pointer */
    67         ENOTSUP       = -11,  /* Not supported */
    68         EADDRNOTAVAIL = -12,  /* Address not available. */
    69         ETIMEOUT      = -13,  /* Timeout expired */
    70         EINVAL        = -14,  /* Invalid value */
    71         EBUSY         = -15,  /* Resource is busy */
    72         EOVERFLOW     = -16,  /* The result does not fit its size. */
    73         EINTR         = -17,  /* Operation was interrupted. */
    74 
    75         EMFILE        = -18,
    76         ENAMETOOLONG  = -256,
    77         EISDIR        = -257,
    78         ENOTDIR       = -258,
    79         ENOSPC        = -259,
    80         ENOTEMPTY     = -261,
    81         EBADF         = -262,
    82         EDOM          = -263,
    83         ERANGE        = -264,
    84         EXDEV         = -265,
    85         EIO           = -266,
    86         EMLINK        = -267,
    87         ENXIO         = -268,
    88         ENOFS         = -269,
    89 
    90 /** Bad checksum. */
    91         EBADCHECKSUM  = -300,
    92 
    93 /** USB: stalled operation. */
    94         ESTALL        = -301,
    95 
    96 /** Empty resource (no data). */
    97         EEMPTY        = -302,
    98 
    99 /** Negative acknowledgment. */
    100         ENAK          = -303,
    101 
    102 /** The requested operation was not performed. Try again later. */
    103         EAGAIN        = -11002,
    104 } errno_t;
    105 
    106 
    107 #endif
    108 
    109 /** @}
    110  */
     1/* Generated file. Edit errno.in instead. */
     2#define EOK                   0
     3#define ENOENT               -1
     4#define ENOMEM               -2
     5#define ELIMIT               -3
     6#define EREFUSED             -4
     7#define EFORWARD             -5
     8#define EPERM                -6
     9#define EHANGUP              -7
     10#define EPARTY               -8
     11#define EEXIST               -9
     12#define EBADMEM             -10
     13#define ENOTSUP             -11
     14#define EADDRNOTAVAIL       -12
     15#define ETIMEOUT            -13
     16#define EINVAL              -14
     17#define EBUSY               -15
     18#define EOVERFLOW           -16
     19#define EINTR               -17
     20#define EMFILE              -18
     21#define ENAMETOOLONG       -256
     22#define EISDIR             -257
     23#define ENOTDIR            -258
     24#define ENOSPC             -259
     25#define ENOTEMPTY          -261
     26#define EBADF              -262
     27#define EDOM               -263
     28#define ERANGE             -264
     29#define EXDEV              -265
     30#define EIO                -266
     31#define EMLINK             -267
     32#define ENXIO              -268
     33#define ENOFS              -269
     34#define EBADCHECKSUM       -300
     35#define ESTALL             -301
     36#define EEMPTY             -302
     37#define ENAK               -303
     38#define EAGAIN           -11002
  • kernel/generic/include/errno.h

    rbdb8ba9 r3529fbf0  
    3636#define KERN_ERRNO_H_
    3737
     38typedef int errno_t;
     39
    3840#include <abi/errno.h>
    3941
  • uspace/lib/c/generic/str_error.c

    rbdb8ba9 r3529fbf0  
    11/*
    22 * Copyright (c) 2010 Martin Decky
     3 * Copyright (c) 2017 CZ.NIC, z.s.p.o.
    34 * All rights reserved.
    45 *
     
    3839#include <fibril.h>
    3940
    40 #define MIN_ERRNO  -17
    4141#define NOERR_LEN  64
    4242
    43 // TODO: this file should be generated from errno declarations
     43/* The arrays bellow are automatically generated from the same file that
     44 * errno.h constants are generated from. Triple-include of the same list
     45 * with redefinitions of __errno() macro are used to ensure that the
     46 * information cannot get out of synch. This is inpired by musl libc.
     47 */
     48
     49#undef __errno_entry
     50#define __errno_entry(name, num, desc) num,
     51
     52static const int err_num[] = {
     53#include <abi/errno.in>
     54};
     55
     56#undef __errno_entry
     57#define __errno_entry(name, num, desc) #name,
    4458
    4559static 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"
     60#include <abi/errno.in>
    6461};
    6562
     63#undef __errno_entry
     64#define __errno_entry(name, num, desc) "[" #name "]" desc,
     65
    6666static const char* err_desc[] = {
    67         "No error",
    68         "No such entry",
    69         "Not enough memory",
    70         "Limit exceeded",
    71         "Connection refused",
    72         "Forwarding error",
    73         "Permission denied",
    74         "Answerbox closed connection",
    75         "Other party error",
    76         "Entry already exists",
    77         "Bad memory pointer",
    78         "Not supported",
    79         "Address not available",
    80         "Timeout expired",
    81         "Invalid value",
    82         "Resource is busy",
    83         "Result does not fit its size",
    84         "Operation interrupted"
     67#include <abi/errno.in>
    8568};
    8669
    8770static fibril_local char noerr[NOERR_LEN];
    8871
     72/* Returns index corresponding to the given errno, or -1 if not found. */
     73static int find_errno(errno_t e)
     74{
     75        /* Just a dumb linear search.
     76         * There too few entries to warrant anything smarter.
     77         */
     78
     79        int len = sizeof(err_num) / sizeof(errno_t);
     80
     81        for (int i = 0; i < len; i++) {
     82                if (err_num[i] == e) {
     83                        return i;
     84                }
     85        }
     86
     87        return -1;
     88}
     89
    8990const char *str_error_name(errno_t e)
    9091{
    91         if ((e <= 0) && (e >= MIN_ERRNO))
    92                 return err_name[-e];
     92        int i = find_errno(e);
    9393
    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;
     94        if (i >= 0) {
     95                return err_name[i];
    10996        }
    11097
     
    115102const char *str_error(errno_t e)
    116103{
    117         if ((e <= 0) && (e >= MIN_ERRNO))
    118                 return err_desc[-e];
    119        
    120         /* Ad hoc descriptions of error codes interesting for USB. */
    121         // FIXME: integrate these as first-class error values
    122         switch (e) {
    123                 case ENOFS:
    124                         return "No such file system type";
    125                 case EBADCHECKSUM:
    126                         return "Bad checksum";
    127                 case ESTALL:
    128                         return "Operation stalled";
    129                 case EAGAIN:
    130                         return "Resource temporarily unavailable";
    131                 case EEMPTY:
    132                         return "Resource is empty";
    133                 default:
    134                         break;
     104        int i = find_errno(e);
     105
     106        if (i >= 0) {
     107                return err_desc[i];
    135108        }
    136109
  • uspace/lib/c/include/errno.h

    rbdb8ba9 r3529fbf0  
    3636#define LIBC_ERRNO_H_
    3737
     38typedef int errno_t;
     39
    3840#include <abi/errno.h>
    3941
Note: See TracChangeset for help on using the changeset viewer.