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 5102d24..372fd3e 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.
@@ -37,7 +38,7 @@ extern "C" {
37#undef sprintf 38#undef sprintf
38 39
39__access(write_only, 1, 2) 40__access(write_only, 1, 2)
40_FORTIFY_FN(fgets) char *fgets(char *__s, int __n, FILE *__f) 41_FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f)
41{ 42{
42 size_t __b = __bos(__s, 0); 43 size_t __b = __bos(__s, 0);
43 44
@@ -46,7 +47,8 @@ _FORTIFY_FN(fgets) char *fgets(char *__s, int __n, FILE *__f)
46 return __orig_fgets(__s, __n, __f); 47 return __orig_fgets(__s, __n, __f);
47} 48}
48 49
49_FORTIFY_FN(fread) size_t fread(void *__d, size_t __n, size_t __m, FILE *__f) 50_FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n,
51 size_t __m, FILE *__f)
50{ 52{
51 size_t __b = __bos(__d, 0); 53 size_t __b = __bos(__d, 0);
52 54
@@ -57,7 +59,8 @@ _FORTIFY_FN(fread) size_t fread(void *__d, size_t __n, size_t __m, FILE *__f)
57 return __orig_fread(__d, __n, __m, __f); 59 return __orig_fread(__d, __n, __m, __f);
58} 60}
59 61
60_FORTIFY_FN(fwrite) size_t fwrite(const void *__d, size_t __n, size_t __m, FILE *__f) 62_FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n,
63 size_t __m, FILE *__f)
61{ 64{
62 size_t __b = __bos(__d, 0); 65 size_t __b = __bos(__d, 0);
63 66
@@ -68,8 +71,8 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void *__d, size_t __n, size_t __m, FILE
68 return __orig_fwrite(__d, __n, __m, __f); 71 return __orig_fwrite(__d, __n, __m, __f);
69} 72}
70 73
71_FORTIFY_FN(vsnprintf) int vsnprintf(char *__s, size_t __n, const char *__f, 74_FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
72 __builtin_va_list __v) 75 const char *__f, __builtin_va_list __v)
73{ 76{
74 size_t __b = __bos(__s, 0); 77 size_t __b = __bos(__s, 0);
75 78
@@ -78,7 +81,8 @@ _FORTIFY_FN(vsnprintf) int vsnprintf(char *__s, size_t __n, const char *__f,
78 return __orig_vsnprintf(__s, __n, __f, __v); 81 return __orig_vsnprintf(__s, __n, __f, __v);
79} 82}
80 83
81_FORTIFY_FN(vsprintf) int vsprintf(char *__s, const char *__f, __builtin_va_list __v) 84_FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
85 __builtin_va_list __v)
82{ 86{
83 size_t __b = __bos(__s, 0); 87 size_t __b = __bos(__s, 0);
84 int __r; 88 int __r;
@@ -93,7 +97,23 @@ _FORTIFY_FN(vsprintf) int vsprintf(char *__s, const char *__f, __builtin_va_list
93 return __r; 97 return __r;
94} 98}
95 99
96_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, const char *__f, ...) 100#if defined(__has_builtin)
101#if __has_builtin(__builtin_va_arg_pack)
102
103/* clang is missing __builtin_va_arg_pack, so we cannot use these impls
104 * outside of gcc; we then have a few options:
105 *
106 * 1) using va_start/end and implementing these functions as static inline,
107 * with inlining never happening; that means extra symbols with internal
108 * linkage, which is not ideal
109 * 2) using macros; this is incompatible with c++ and since musl does not
110 * have the __chk variants, we'd need to implement a body with intermediate
111 * variables within the macro, which means more non-portable mess
112 * 3) not implementing these under clang, which is what we do for now
113 */
114
115_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n,
116 const char *__f, ...)
97{ 117{
98 size_t __b = __bos(__s, 0); 118 size_t __b = __bos(__s, 0);
99 119
@@ -117,6 +137,9 @@ _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...)
117 return __r; 137 return __r;
118} 138}
119 139
140#endif /* __has_builtin(__builtin_va_arg_pack) */
141#endif /* defined(__has_builtin) */
142
120#ifdef __cplusplus 143#ifdef __cplusplus
121} 144}
122#endif 145#endif