summaryrefslogtreecommitdiff
path: root/include/stdio.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/stdio.h')
-rw-r--r--include/stdio.h37
1 files changed, 30 insertions, 7 deletions
diff --git a/include/stdio.h b/include/stdio.h
index e060f64..a75c9ea 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org> 2 * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
3 * Copyright (C) 2022 q66 <q66@chimera-linux.org>
3 * 4 *
4 * Permission to use, copy, modify, and/or distribute this software for any 5 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted. 6 * purpose with or without fee is hereby granted.
@@ -36,7 +37,7 @@ extern "C" {
36#undef snprintf 37#undef snprintf
37#undef sprintf 38#undef sprintf
38 39
39_FORTIFY_FN(fgets) char *fgets(char *__s, int __n, FILE *__f) 40_FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f)
40{ 41{
41 size_t __b = __bos(__s, 0); 42 size_t __b = __bos(__s, 0);
42 43
@@ -45,7 +46,8 @@ _FORTIFY_FN(fgets) char *fgets(char *__s, int __n, FILE *__f)
45 return __orig_fgets(__s, __n, __f); 46 return __orig_fgets(__s, __n, __f);
46} 47}
47 48
48_FORTIFY_FN(fread) size_t fread(void *__d, size_t __n, size_t __m, FILE *__f) 49_FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n,
50 size_t __m, FILE *__f)
49{ 51{
50 size_t __b = __bos(__d, 0); 52 size_t __b = __bos(__d, 0);
51 53
@@ -56,7 +58,8 @@ _FORTIFY_FN(fread) size_t fread(void *__d, size_t __n, size_t __m, FILE *__f)
56 return __orig_fread(__d, __n, __m, __f); 58 return __orig_fread(__d, __n, __m, __f);
57} 59}
58 60
59_FORTIFY_FN(fwrite) size_t fwrite(const void *__d, size_t __n, size_t __m, FILE *__f) 61_FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n,
62 size_t __m, FILE *__f)
60{ 63{
61 size_t __b = __bos(__d, 0); 64 size_t __b = __bos(__d, 0);
62 65
@@ -67,8 +70,8 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void *__d, size_t __n, size_t __m, FILE
67 return __orig_fwrite(__d, __n, __m, __f); 70 return __orig_fwrite(__d, __n, __m, __f);
68} 71}
69 72
70_FORTIFY_FN(vsnprintf) int vsnprintf(char *__s, size_t __n, const char *__f, 73_FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
71 __builtin_va_list __v) 74 const char *__f, __builtin_va_list __v)
72{ 75{
73 size_t __b = __bos(__s, 0); 76 size_t __b = __bos(__s, 0);
74 77
@@ -77,7 +80,8 @@ _FORTIFY_FN(vsnprintf) int vsnprintf(char *__s, size_t __n, const char *__f,
77 return __orig_vsnprintf(__s, __n, __f, __v); 80 return __orig_vsnprintf(__s, __n, __f, __v);
78} 81}
79 82
80_FORTIFY_FN(vsprintf) int vsprintf(char *__s, const char *__f, __builtin_va_list __v) 83_FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
84 __builtin_va_list __v)
81{ 85{
82 size_t __b = __bos(__s, 0); 86 size_t __b = __bos(__s, 0);
83 int __r; 87 int __r;
@@ -92,7 +96,23 @@ _FORTIFY_FN(vsprintf) int vsprintf(char *__s, const char *__f, __builtin_va_list
92 return __r; 96 return __r;
93} 97}
94 98
95_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, const char *__f, ...) 99#if defined(__has_builtin)
100#if __has_builtin(__builtin_va_arg_pack)
101
102/* clang is missing __builtin_va_arg_pack, so we cannot use these impls
103 * outside of gcc; we then have a few options:
104 *
105 * 1) using va_start/end and implementing these functions as static inline,
106 * with inlining never happening; that means extra symbols with internal
107 * linkage, which is not ideal
108 * 2) using macros; this is incompatible with c++ and since musl does not
109 * have the __chk variants, we'd need to implement a body with intermediate
110 * variables within the macro, which means more non-portable mess
111 * 3) not implementing these under clang, which is what we do for now
112 */
113
114_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n,
115 const char *__f, ...)
96{ 116{
97 size_t __b = __bos(__s, 0); 117 size_t __b = __bos(__s, 0);
98 118
@@ -116,6 +136,9 @@ _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...)
116 return __r; 136 return __r;
117} 137}
118 138
139#endif /* __has_builtin(__builtin_va_arg_pack) */
140#endif /* defined(__has_builtin) */
141
119#ifdef __cplusplus 142#ifdef __cplusplus
120} 143}
121#endif 144#endif