github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/libcontainer/dmz/nolibc/ctype.h (about)

     1  /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
     2  /*
     3   * ctype function definitions for NOLIBC
     4   * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
     5   */
     6  
     7  #ifndef _NOLIBC_CTYPE_H
     8  #define _NOLIBC_CTYPE_H
     9  
    10  #include "std.h"
    11  
    12  /*
    13   * As much as possible, please keep functions alphabetically sorted.
    14   */
    15  
    16  static __attribute__((unused))
    17  int isascii(int c)
    18  {
    19  	/* 0x00..0x7f */
    20  	return (unsigned int)c <= 0x7f;
    21  }
    22  
    23  static __attribute__((unused))
    24  int isblank(int c)
    25  {
    26  	return c == '\t' || c == ' ';
    27  }
    28  
    29  static __attribute__((unused))
    30  int iscntrl(int c)
    31  {
    32  	/* 0x00..0x1f, 0x7f */
    33  	return (unsigned int)c < 0x20 || c == 0x7f;
    34  }
    35  
    36  static __attribute__((unused))
    37  int isdigit(int c)
    38  {
    39  	return (unsigned int)(c - '0') < 10;
    40  }
    41  
    42  static __attribute__((unused))
    43  int isgraph(int c)
    44  {
    45  	/* 0x21..0x7e */
    46  	return (unsigned int)(c - 0x21) < 0x5e;
    47  }
    48  
    49  static __attribute__((unused))
    50  int islower(int c)
    51  {
    52  	return (unsigned int)(c - 'a') < 26;
    53  }
    54  
    55  static __attribute__((unused))
    56  int isprint(int c)
    57  {
    58  	/* 0x20..0x7e */
    59  	return (unsigned int)(c - 0x20) < 0x5f;
    60  }
    61  
    62  static __attribute__((unused))
    63  int isspace(int c)
    64  {
    65  	/* \t is 0x9, \n is 0xA, \v is 0xB, \f is 0xC, \r is 0xD */
    66  	return ((unsigned int)c == ' ') || (unsigned int)(c - 0x09) < 5;
    67  }
    68  
    69  static __attribute__((unused))
    70  int isupper(int c)
    71  {
    72  	return (unsigned int)(c - 'A') < 26;
    73  }
    74  
    75  static __attribute__((unused))
    76  int isxdigit(int c)
    77  {
    78  	return isdigit(c) || (unsigned int)(c - 'A') < 6 || (unsigned int)(c - 'a') < 6;
    79  }
    80  
    81  static __attribute__((unused))
    82  int isalpha(int c)
    83  {
    84  	return islower(c) || isupper(c);
    85  }
    86  
    87  static __attribute__((unused))
    88  int isalnum(int c)
    89  {
    90  	return isalpha(c) || isdigit(c);
    91  }
    92  
    93  static __attribute__((unused))
    94  int ispunct(int c)
    95  {
    96  	return isgraph(c) && !isalnum(c);
    97  }
    98  
    99  /* make sure to include all global symbols */
   100  #include "nolibc.h"
   101  
   102  #endif /* _NOLIBC_CTYPE_H */