(root)/
coreutils-9.4/
gnulib-tests/
test-errno.c
       1  /* Test of <errno.h> substitute.
       2     Copyright (C) 2008-2023 Free Software Foundation, Inc.
       3  
       4     This program is free software: you can redistribute it and/or modify
       5     it under the terms of the GNU General Public License as published by
       6     the Free Software Foundation, either version 3 of the License, or
       7     (at your option) any later version.
       8  
       9     This program is distributed in the hope that it will be useful,
      10     but WITHOUT ANY WARRANTY; without even the implied warranty of
      11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12     GNU General Public License for more details.
      13  
      14     You should have received a copy of the GNU General Public License
      15     along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      16  
      17  /* Written by Bruno Haible <bruno@clisp.org>, 2008.  */
      18  
      19  #include <config.h>
      20  
      21  #include <errno.h>
      22  
      23  /* Verify that the POSIX mandated errno values exist and can be used as
      24     initializers outside of a function.
      25     The variable names happen to match the Linux/x86 error numbers.  */
      26  int e1 = EPERM;
      27  int e2 = ENOENT;
      28  int e3 = ESRCH;
      29  int e4 = EINTR;
      30  int e5 = EIO;
      31  int e6 = ENXIO;
      32  int e7 = E2BIG;
      33  int e8 = ENOEXEC;
      34  int e9 = EBADF;
      35  int e10 = ECHILD;
      36  int e11 = EAGAIN;
      37  int e11a = EWOULDBLOCK;
      38  int e12 = ENOMEM;
      39  int e13 = EACCES;
      40  int e14 = EFAULT;
      41  int e16 = EBUSY;
      42  int e17 = EEXIST;
      43  int e18 = EXDEV;
      44  int e19 = ENODEV;
      45  int e20 = ENOTDIR;
      46  int e21 = EISDIR;
      47  int e22 = EINVAL;
      48  int e23 = ENFILE;
      49  int e24 = EMFILE;
      50  int e25 = ENOTTY;
      51  int e26 = ETXTBSY;
      52  int e27 = EFBIG;
      53  int e28 = ENOSPC;
      54  int e29 = ESPIPE;
      55  int e30 = EROFS;
      56  int e31 = EMLINK;
      57  int e32 = EPIPE;
      58  int e33 = EDOM;
      59  int e34 = ERANGE;
      60  int e35 = EDEADLK;
      61  int e36 = ENAMETOOLONG;
      62  int e37 = ENOLCK;
      63  int e38 = ENOSYS;
      64  int e39 = ENOTEMPTY;
      65  int e40 = ELOOP;
      66  int e42 = ENOMSG;
      67  int e43 = EIDRM;
      68  int e67 = ENOLINK;
      69  int e71 = EPROTO;
      70  int e72 = EMULTIHOP;
      71  int e74 = EBADMSG;
      72  int e75 = EOVERFLOW;
      73  int e84 = EILSEQ;
      74  int e88 = ENOTSOCK;
      75  int e89 = EDESTADDRREQ;
      76  int e90 = EMSGSIZE;
      77  int e91 = EPROTOTYPE;
      78  int e92 = ENOPROTOOPT;
      79  int e93 = EPROTONOSUPPORT;
      80  int e95 = EOPNOTSUPP;
      81  int e95a = ENOTSUP;
      82  int e97 = EAFNOSUPPORT;
      83  int e98 = EADDRINUSE;
      84  int e99 = EADDRNOTAVAIL;
      85  int e100 = ENETDOWN;
      86  int e101 = ENETUNREACH;
      87  int e102 = ENETRESET;
      88  int e103 = ECONNABORTED;
      89  int e104 = ECONNRESET;
      90  int e105 = ENOBUFS;
      91  int e106 = EISCONN;
      92  int e107 = ENOTCONN;
      93  int e110 = ETIMEDOUT;
      94  int e111 = ECONNREFUSED;
      95  int e113 = EHOSTUNREACH;
      96  int e114 = EALREADY;
      97  int e115 = EINPROGRESS;
      98  int e116 = ESTALE;
      99  int e122 = EDQUOT;
     100  int e125 = ECANCELED;
     101  int e130 = EOWNERDEAD;
     102  int e131 = ENOTRECOVERABLE;
     103  
     104  /* Don't verify that these errno values are all different, except for possibly
     105     EWOULDBLOCK == EAGAIN.  Even Linux/x86 does not pass this check: it has
     106     ENOTSUP == EOPNOTSUPP.  */
     107  
     108  int
     109  main ()
     110  {
     111    /* Verify that errno can be assigned.  */
     112    errno = EOVERFLOW;
     113  
     114    /* snprintf() callers want to distinguish EINVAL and EOVERFLOW.  */
     115    if (errno == EINVAL)
     116      return 1;
     117  
     118    return 0;
     119  }