zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

stdlib.h (14102B) - Raw


      1 #ifndef _STDLIB_H
      2 
      3 #ifndef _ISOMAC
      4 # include <stdbool.h>
      5 # include <stddef.h>
      6 #endif
      7 
      8 /* Workaround PR90731 with GCC 9 when using ldbl redirects in C++.  */
      9 #include <bits/floatn.h>
     10 #if defined __cplusplus && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
     11 # if __GNUC_PREREQ (9, 0) && !__GNUC_PREREQ (9, 3)
     12 #   pragma GCC system_header
     13 # endif
     14 #endif
     15 
     16 #include <stdlib/stdlib.h>
     17 
     18 /* Now define the internal interfaces.  */
     19 #if !defined _ISOMAC
     20 # include <sys/stat.h>
     21 
     22 # include <rtld-malloc.h>
     23 # include <internal-sigset.h>
     24 
     25 extern __typeof (strtol_l) __strtol_l;
     26 extern __typeof (strtoul_l) __strtoul_l;
     27 extern __typeof (strtoll_l) __strtoll_l;
     28 extern __typeof (strtoull_l) __strtoull_l;
     29 extern __typeof (strtod_l) __strtod_l;
     30 extern __typeof (strtof_l) __strtof_l;
     31 extern __typeof (strtold_l) __strtold_l;
     32 libc_hidden_proto (__strtol_l)
     33 libc_hidden_proto (__strtoul_l)
     34 libc_hidden_proto (__strtoll_l)
     35 libc_hidden_proto (__strtoull_l)
     36 libc_hidden_proto (__strtod_l)
     37 libc_hidden_proto (__strtof_l)
     38 libc_hidden_proto (__strtold_l)
     39 
     40 extern __typeof (strtol) __isoc23_strtol __attribute_copy__ (strtol);
     41 extern __typeof (strtoul) __isoc23_strtoul __attribute_copy__ (strtoul);
     42 extern __typeof (strtoll) __isoc23_strtoll __attribute_copy__ (strtoll);
     43 extern __typeof (strtoull) __isoc23_strtoull __attribute_copy__ (strtoull);
     44 extern __typeof (strtol_l) __isoc23_strtol_l __attribute_copy__ (strtol_l);
     45 extern __typeof (strtoul_l) __isoc23_strtoul_l __attribute_copy__ (strtoul_l);
     46 extern __typeof (strtoll_l) __isoc23_strtoll_l __attribute_copy__ (strtoll_l);
     47 extern __typeof (strtoull_l) __isoc23_strtoull_l __attribute_copy__ (strtoull_l);
     48 libc_hidden_proto (__isoc23_strtol)
     49 libc_hidden_proto (__isoc23_strtoul)
     50 libc_hidden_proto (__isoc23_strtoll)
     51 libc_hidden_proto (__isoc23_strtoull)
     52 libc_hidden_proto (__isoc23_strtol_l)
     53 libc_hidden_proto (__isoc23_strtoul_l)
     54 libc_hidden_proto (__isoc23_strtoll_l)
     55 libc_hidden_proto (__isoc23_strtoull_l)
     56 
     57 #if __GLIBC_USE (C23_STRTOL)
     58 /* Redirect internal uses of these functions to the C23 versions; the
     59    redirection in the installed header does not work with
     60    libc_hidden_proto.  */
     61 # undef strtol
     62 # define strtol __isoc23_strtol
     63 # undef atoi
     64 # define atoi(nptr) __isoc23_strtol(nptr, NULL, 10)
     65 # undef strtoul
     66 # define strtoul __isoc23_strtoul
     67 # undef strtoll
     68 # define strtoll __isoc23_strtoll
     69 # undef strtoull
     70 # define strtoull __isoc23_strtoull
     71 # undef strtol_l
     72 # define strtol_l __isoc23_strtol_l
     73 # undef strtoul_l
     74 # define strtoul_l __isoc23_strtoul_l
     75 # undef strtoll_l
     76 # define strtoll_l __isoc23_strtoll_l
     77 # undef strtoull_l
     78 # define strtoull_l __isoc23_strtoull_l
     79 #endif
     80 
     81 extern void __abort_fork_reset_child (void) attribute_hidden;
     82 extern void __abort_lock_rdlock (internal_sigset_t *set) attribute_hidden;
     83 extern void __abort_lock_wrlock (internal_sigset_t *set) attribute_hidden;
     84 extern void __abort_lock_unlock (const internal_sigset_t *set)
     85      attribute_hidden;
     86 
     87 libc_hidden_proto (exit)
     88 libc_hidden_proto (abort)
     89 libc_hidden_proto (getenv)
     90 extern __typeof (secure_getenv) __libc_secure_getenv;
     91 libc_hidden_proto (__libc_secure_getenv)
     92 libc_hidden_proto (bsearch)
     93 libc_hidden_proto (qsort)
     94 extern __typeof (qsort_r) __qsort_r;
     95 libc_hidden_proto (__qsort_r)
     96 libc_hidden_proto (lrand48_r)
     97 libc_hidden_proto (wctomb)
     98 
     99 extern long int __random (void) attribute_hidden;
    100 extern void __srandom (unsigned int __seed);
    101 extern char *__initstate (unsigned int __seed, char *__statebuf,
    102 			  size_t __statelen);
    103 extern char *__setstate (char *__statebuf);
    104 extern int __random_r (struct random_data *__buf, int32_t *__result)
    105      attribute_hidden;
    106 extern int __srandom_r (unsigned int __seed, struct random_data *__buf)
    107      attribute_hidden;
    108 extern int __initstate_r (unsigned int __seed, char *__statebuf,
    109 			  size_t __statelen, struct random_data *__buf)
    110      attribute_hidden;
    111 extern int __setstate_r (char *__statebuf, struct random_data *__buf)
    112      attribute_hidden;
    113 extern int __rand_r (unsigned int *__seed);
    114 extern int __erand48_r (unsigned short int __xsubi[3],
    115 			struct drand48_data *__buffer, double *__result)
    116      attribute_hidden;
    117 extern int __nrand48_r (unsigned short int __xsubi[3],
    118 			struct drand48_data *__buffer,
    119 			long int *__result) attribute_hidden;
    120 extern int __jrand48_r (unsigned short int __xsubi[3],
    121 			struct drand48_data *__buffer,
    122 			long int *__result) attribute_hidden;
    123 extern int __srand48_r (long int __seedval,
    124 			struct drand48_data *__buffer) attribute_hidden;
    125 extern int __seed48_r (unsigned short int __seed16v[3],
    126 		       struct drand48_data *__buffer) attribute_hidden;
    127 extern int __lcong48_r (unsigned short int __param[7],
    128 			struct drand48_data *__buffer) attribute_hidden;
    129 
    130 /* Internal function to compute next state of the generator.  */
    131 extern int __drand48_iterate (unsigned short int __xsubi[3],
    132 			      struct drand48_data *__buffer)
    133      attribute_hidden;
    134 
    135 /* Global state for non-reentrant functions.  Defined in drand48-iter.c.  */
    136 extern struct drand48_data __libc_drand48_data attribute_hidden;
    137 
    138 extern int __setenv (const char *__name, const char *__value, int __replace)
    139      attribute_hidden;
    140 extern int __unsetenv (const char *__name) attribute_hidden;
    141 extern int __clearenv (void) attribute_hidden;
    142 extern char *__mktemp (char *__template) __THROW __nonnull ((1));
    143 libc_hidden_proto (__mktemp)
    144 extern char *__canonicalize_file_name (const char *__name);
    145 extern char *__realpath (const char *__name, char *__resolved);
    146 libc_hidden_proto (__realpath)
    147 extern int __ptsname_r (int __fd, char *__buf, size_t __buflen)
    148      attribute_hidden;
    149 # ifndef _ISOMAC
    150 extern int __ptsname_internal (int fd, char *buf, size_t buflen,
    151 			       struct stat64 *stp) attribute_hidden;
    152 # endif
    153 extern int __getpt (void);
    154 extern int __posix_openpt (int __oflag) attribute_hidden;
    155 
    156 extern int __add_to_environ (const char *name, const char *value,
    157 			     const char *combines, int replace)
    158      attribute_hidden;
    159 
    160 extern int __on_exit (void (*__func) (int __status, void *__arg), void *__arg);
    161 
    162 extern int __cxa_atexit (void (*func) (void *), void *arg, void *d);
    163 libc_hidden_proto (__cxa_atexit);
    164 
    165 extern int __cxa_thread_atexit_impl (void (*func) (void *), void *arg,
    166 				     void *d);
    167 extern void __call_tls_dtors (void);
    168 libc_hidden_proto (__call_tls_dtors)
    169 
    170 extern void __cxa_finalize (void *d);
    171 
    172 extern int __posix_memalign (void **memptr, size_t alignment, size_t size);
    173 
    174 extern void *__libc_memalign (size_t alignment, size_t size)
    175      __attribute_malloc__;
    176 
    177 extern void *__libc_reallocarray (void *__ptr, size_t __nmemb, size_t __size)
    178      __THROW __attribute_warn_unused_result__;
    179 libc_hidden_proto (__libc_reallocarray)
    180 
    181 extern int __libc_system (const char *line);
    182 
    183 extern __typeof (getpt) __getpt;
    184 extern __typeof (ptsname_r) __ptsname_r;
    185 libc_hidden_proto (__getpt)
    186 libc_hidden_proto (__ptsname_r)
    187 libc_hidden_proto (grantpt)
    188 libc_hidden_proto (unlockpt)
    189 
    190 __typeof (arc4random) __arc4random;
    191 libc_hidden_proto (__arc4random);
    192 __typeof (arc4random_buf) __arc4random_buf;
    193 libc_hidden_proto (__arc4random_buf);
    194 __typeof (arc4random_uniform) __arc4random_uniform;
    195 libc_hidden_proto (__arc4random_uniform);
    196 extern void __arc4random_buf_internal (void *buffer, size_t len)
    197      attribute_hidden;
    198 
    199 extern double __strtod_internal (const char *__restrict __nptr,
    200 				 char **__restrict __endptr, int __group)
    201      __THROW __nonnull ((1)) __wur;
    202 extern float __strtof_internal (const char *__restrict __nptr,
    203 				char **__restrict __endptr, int __group)
    204      __THROW __nonnull ((1)) __wur;
    205 extern long double __strtold_internal (const char *__restrict __nptr,
    206 				       char **__restrict __endptr,
    207 				       int __group)
    208      __THROW __nonnull ((1)) __wur;
    209 extern long int __strtol_internal (const char *__restrict __nptr,
    210 				   char **__restrict __endptr,
    211 				   int __base, int __group)
    212      __THROW __nonnull ((1)) __wur;
    213 extern unsigned long int __strtoul_internal (const char *__restrict __nptr,
    214 					     char **__restrict __endptr,
    215 					     int __base, int __group)
    216      __THROW __nonnull ((1)) __wur;
    217 __extension__
    218 extern long long int __strtoll_internal (const char *__restrict __nptr,
    219 					 char **__restrict __endptr,
    220 					 int __base, int __group)
    221      __THROW __nonnull ((1)) __wur;
    222 __extension__
    223 extern unsigned long long int __strtoull_internal (const char *
    224 						   __restrict __nptr,
    225 						   char **__restrict __endptr,
    226 						   int __base, int __group)
    227      __THROW __nonnull ((1)) __wur;
    228 libc_hidden_proto (__strtof_internal)
    229 libc_hidden_proto (__strtod_internal)
    230 libc_hidden_proto (__strtold_internal)
    231 libc_hidden_proto (__strtol_internal)
    232 libc_hidden_proto (__strtoll_internal)
    233 libc_hidden_proto (__strtoul_internal)
    234 libc_hidden_proto (__strtoull_internal)
    235 
    236 extern double ____strtod_l_internal (const char *__restrict __nptr,
    237 				     char **__restrict __endptr, int __group,
    238 				     locale_t __loc);
    239 extern float ____strtof_l_internal (const char *__restrict __nptr,
    240 				    char **__restrict __endptr, int __group,
    241 				    locale_t __loc);
    242 extern long double ____strtold_l_internal (const char *__restrict __nptr,
    243 					   char **__restrict __endptr,
    244 					   int __group, locale_t __loc);
    245 extern long int ____strtol_l_internal (const char *__restrict __nptr,
    246 				       char **__restrict __endptr,
    247 				       int __base, int __group,
    248 				       bool __bin_cst, locale_t __loc);
    249 extern unsigned long int ____strtoul_l_internal (const char *
    250 						 __restrict __nptr,
    251 						 char **__restrict __endptr,
    252 						 int __base, int __group,
    253 						 bool __bin_cst,
    254 						 locale_t __loc);
    255 __extension__
    256 extern long long int ____strtoll_l_internal (const char *__restrict __nptr,
    257 					     char **__restrict __endptr,
    258 					     int __base, int __group,
    259 					     bool __bin_cst, locale_t __loc);
    260 __extension__
    261 extern unsigned long long int ____strtoull_l_internal (const char *
    262 						       __restrict __nptr,
    263 						       char **
    264 						       __restrict __endptr,
    265 						       int __base, int __group,
    266 						       bool __bin_cst,
    267 						       locale_t __loc);
    268 
    269 libc_hidden_proto (____strtof_l_internal)
    270 libc_hidden_proto (____strtod_l_internal)
    271 libc_hidden_proto (____strtold_l_internal)
    272 libc_hidden_proto (____strtol_l_internal)
    273 libc_hidden_proto (____strtoll_l_internal)
    274 libc_hidden_proto (____strtoul_l_internal)
    275 libc_hidden_proto (____strtoull_l_internal)
    276 
    277 #include <bits/floatn.h>
    278 libc_hidden_proto (strtof)
    279 libc_hidden_proto (strtod)
    280 #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
    281 libc_hidden_proto (strtold)
    282 #endif
    283 libc_hidden_proto (strtol)
    284 libc_hidden_proto (strtoll)
    285 libc_hidden_proto (strtoul)
    286 libc_hidden_proto (strtoull)
    287 
    288 libc_hidden_proto (atoi)
    289 
    290 extern float __strtof_nan (const char *, char **, char);
    291 extern double __strtod_nan (const char *, char **, char);
    292 extern long double __strtold_nan (const char *, char **, char);
    293 extern float __wcstof_nan (const wchar_t *, wchar_t **, wchar_t);
    294 extern double __wcstod_nan (const wchar_t *, wchar_t **, wchar_t);
    295 extern long double __wcstold_nan (const wchar_t *, wchar_t **, wchar_t);
    296 
    297 libc_hidden_proto (__strtof_nan)
    298 libc_hidden_proto (__strtod_nan)
    299 libc_hidden_proto (__strtold_nan)
    300 libc_hidden_proto (__wcstof_nan)
    301 libc_hidden_proto (__wcstod_nan)
    302 libc_hidden_proto (__wcstold_nan)
    303 
    304 /* Enable _FloatN bits as needed.  */
    305 #include <bits/floatn.h>
    306 
    307 #if __HAVE_DISTINCT_FLOAT128
    308 extern __typeof (strtof128_l) __strtof128_l;
    309 
    310 libc_hidden_proto (__strtof128_l)
    311 libc_hidden_proto (strtof128)
    312 
    313 extern _Float128 __strtof128_nan (const char *, char **, char);
    314 extern _Float128 __wcstof128_nan (const wchar_t *, wchar_t **, wchar_t);
    315 
    316 libc_hidden_proto (__strtof128_nan)
    317 libc_hidden_proto (__wcstof128_nan)
    318 
    319 extern _Float128 __strtof128_internal (const char *__restrict __nptr,
    320 				       char **__restrict __endptr,
    321 				       int __group);
    322 libc_hidden_proto (__strtof128_internal)
    323 
    324 extern _Float128 ____strtof128_l_internal (const char *__restrict __nptr,
    325 					   char **__restrict __endptr,
    326 					   int __group, locale_t __loc);
    327 
    328 libc_hidden_proto (____strtof128_l_internal)
    329 #endif
    330 
    331 extern char *__ecvt (double __value, int __ndigit, int *__restrict __decpt,
    332 		     int *__restrict __sign);
    333 extern char *__fcvt (double __value, int __ndigit, int *__restrict __decpt,
    334 		     int *__restrict __sign);
    335 extern char *__gcvt (double __value, int __ndigit, char *__buf);
    336 extern int __ecvt_r (double __value, int __ndigit, int *__restrict __decpt,
    337 		     int *__restrict __sign, char *__restrict __buf,
    338 		     size_t __len);
    339 libc_hidden_proto (__ecvt_r)
    340 extern int __fcvt_r (double __value, int __ndigit, int *__restrict __decpt,
    341 		     int *__restrict __sign, char *__restrict __buf,
    342 		     size_t __len);
    343 libc_hidden_proto (__fcvt_r)
    344 extern char *__qecvt (long double __value, int __ndigit,
    345 		      int *__restrict __decpt, int *__restrict __sign);
    346 extern char *__qfcvt (long double __value, int __ndigit,
    347 		      int *__restrict __decpt, int *__restrict __sign);
    348 extern char *__qgcvt (long double __value, int __ndigit, char *__buf);
    349 extern int __qecvt_r (long double __value, int __ndigit,
    350 		      int *__restrict __decpt, int *__restrict __sign,
    351 		      char *__restrict __buf, size_t __len);
    352 libc_hidden_proto (__qecvt_r)
    353 extern int __qfcvt_r (long double __value, int __ndigit,
    354 		      int *__restrict __decpt, int *__restrict __sign,
    355 		      char *__restrict __buf, size_t __len);
    356 libc_hidden_proto (__qfcvt_r)
    357 
    358 # if IS_IN (libc)
    359 #  undef MB_CUR_MAX
    360 #  define MB_CUR_MAX (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MB_CUR_MAX))
    361 # endif
    362 
    363 struct abort_msg_s
    364 {
    365   unsigned int size;
    366   char msg[0];
    367 };
    368 extern struct abort_msg_s *__abort_msg;
    369 libc_hidden_proto (__abort_msg)
    370 
    371 enum readonly_error_type
    372 {
    373   readonly_noerror,
    374   readonly_area_writable,
    375   readonly_procfs_inaccessible,
    376   readonly_procfs_open_fail,
    377 };
    378 
    379 extern enum readonly_error_type __readonly_area (const void *ptr,
    380 						 size_t size)
    381      attribute_hidden;
    382 extern enum readonly_error_type __readonly_area_fallback (const void *ptr,
    383 							  size_t size)
    384      attribute_hidden;
    385 
    386 # if IS_IN (rtld)
    387 extern __typeof (unsetenv) unsetenv attribute_hidden;
    388 extern __typeof (__strtoul_internal) __strtoul_internal attribute_hidden;
    389 # endif
    390 
    391 #endif
    392 
    393 #endif  /* include/stdlib.h */