zig

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

_stdio.h (2898B) - Raw


      1 /*
      2  * Copyright (c) 2007, 2010, 2023 Apple Inc. All rights reserved.
      3  *
      4  * @APPLE_LICENSE_HEADER_START@
      5  *
      6  * This file contains Original Code and/or Modifications of Original Code
      7  * as defined in and that are subject to the Apple Public Source License
      8  * Version 2.0 (the 'License'). You may not use this file except in
      9  * compliance with the License. Please obtain a copy of the License at
     10  * http://www.opensource.apple.com/apsl/ and read it before using this
     11  * file.
     12  *
     13  * The Original Code and all software distributed under the License are
     14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
     15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
     16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
     17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
     18  * Please see the License for the specific language governing rights and
     19  * limitations under the License.
     20  *
     21  * @APPLE_LICENSE_HEADER_END@
     22  */
     23 
     24 #ifndef _STDIO_H_
     25  #error error "Never use <secure/_stdio.h> directly; include <stdio.h> instead."
     26 #endif
     27 
     28 #ifndef _SECURE__STDIO_H_
     29 #define _SECURE__STDIO_H_
     30 
     31 #include <_bounds.h>
     32 #include <secure/_common.h>
     33 
     34 _LIBC_SINGLE_BY_DEFAULT()
     35 
     36 #if _USE_FORTIFY_LEVEL > 0
     37 
     38 #ifndef __has_builtin
     39 #define _undef__has_builtin
     40 #define __has_builtin(x) 0
     41 #endif
     42 
     43 /* sprintf, vsprintf, snprintf, vsnprintf */
     44 #if __has_builtin(__builtin___sprintf_chk) || defined(__GNUC__)
     45 extern int __sprintf_chk (char * __restrict _LIBC_UNSAFE_INDEXABLE, int, size_t,
     46 			  const char * __restrict, ...);
     47 
     48 #undef sprintf
     49 #define sprintf(str, ...) \
     50   __builtin___sprintf_chk (str, 0, __darwin_obsz(str), __VA_ARGS__)
     51 #endif
     52 
     53 #if __DARWIN_C_LEVEL >= 200112L
     54 #if __has_builtin(__builtin___snprintf_chk) || defined(__GNUC__)
     55 extern int __snprintf_chk (char * __restrict _LIBC_COUNT(__maxlen), size_t __maxlen, int, size_t,
     56 			   const char * __restrict, ...);
     57 
     58 #undef snprintf
     59 #define snprintf(str, len, ...) \
     60   __builtin___snprintf_chk (str, len, 0, __darwin_obsz(str), __VA_ARGS__)
     61 #endif
     62 
     63 #if __has_builtin(__builtin___vsprintf_chk) || defined(__GNUC__)
     64 extern int __vsprintf_chk (char * __restrict _LIBC_UNSAFE_INDEXABLE, int, size_t,
     65 			   const char * __restrict, va_list);
     66 
     67 #undef vsprintf
     68 #define vsprintf(str, format, ap) \
     69   __builtin___vsprintf_chk (str, 0, __darwin_obsz(str), format, ap)
     70 #endif
     71 
     72 #if __has_builtin(__builtin___vsnprintf_chk) || defined(__GNUC__)
     73 extern int __vsnprintf_chk (char * __restrict _LIBC_COUNT(__maxlen), size_t __maxlen, int, size_t,
     74 			    const char * __restrict, va_list);
     75 
     76 #undef vsnprintf
     77 #define vsnprintf(str, len, format, ap) \
     78   __builtin___vsnprintf_chk (str, len, 0, __darwin_obsz(str), format, ap)
     79 #endif
     80 
     81 #endif /* __DARWIN_C_LEVEL >= 200112L */
     82 
     83 #ifdef _undef__has_builtin
     84 #undef _undef__has_builtin
     85 #undef __has_builtin
     86 #endif
     87 
     88 #endif /* _USE_FORTIFY_LEVEL > 0 */
     89 #endif /* _SECURE__STDIO_H_ */