1 /* *printf* family compatibility routines for IEEE double as long double
2 Copyright (C) 2006-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 /* This file may define some of the deprecated scanf variants. */
20 #include <features.h>
21 #undef __GLIBC_USE_DEPRECATED_SCANF
22 #define __GLIBC_USE_DEPRECATED_SCANF 1
23
24 #include <argp.h>
25 #include <err.h>
26 #include <error.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <libio/strfile.h>
30 #include <math.h>
31 #include <wchar.h>
32 #include <printf.h>
33 #include <monetary.h>
34 #include <locale/localeinfo.h>
35 #include <sys/syslog.h>
36 #include <libc-lock.h>
37
38 #include "nldbl-compat.h"
39
40 libc_hidden_proto (__nldbl_vsscanf)
libc_hidden_proto(__nldbl_vfscanf)41 libc_hidden_proto (__nldbl_vfscanf)
42 libc_hidden_proto (__nldbl_vfwscanf)
43 libc_hidden_proto (__nldbl_vswscanf)
44 libc_hidden_proto (__nldbl___isoc99_vsscanf)
45 libc_hidden_proto (__nldbl___isoc99_vfscanf)
46 libc_hidden_proto (__nldbl___isoc99_vswscanf)
47 libc_hidden_proto (__nldbl___isoc99_vfwscanf)
48
49 /* Compatibility with IEEE double as long double.
50 IEEE quad long double is used by default for most programs, so
51 we don't need to split this into one file per function for the
52 sake of statically linked programs. */
53
54 int
55 attribute_compat_text_section
56 __nldbl___asprintf (char **string_ptr, const char *fmt, ...)
57 {
58 va_list ap;
59 int ret;
60
61 va_start (ap, fmt);
62 ret = __vasprintf_internal (string_ptr, fmt, ap, PRINTF_LDBL_IS_DBL);
63 va_end (ap);
64
65 return ret;
66 }
weak_alias(__nldbl___asprintf,__nldbl_asprintf)67 weak_alias (__nldbl___asprintf, __nldbl_asprintf)
68
69 int
70 attribute_compat_text_section
71 __nldbl_dprintf (int d, const char *fmt, ...)
72 {
73 va_list ap;
74 int ret;
75
76 va_start (ap, fmt);
77 ret = __vdprintf_internal (d, fmt, ap, PRINTF_LDBL_IS_DBL);
78 va_end (ap);
79
80 return ret;
81 }
82
83 int
84 attribute_compat_text_section
__nldbl_fprintf(FILE * stream,const char * fmt,...)85 __nldbl_fprintf (FILE *stream, const char *fmt, ...)
86 {
87 va_list ap;
88 int ret;
89
90 va_start (ap, fmt);
91 ret = __vfprintf_internal (stream, fmt, ap, PRINTF_LDBL_IS_DBL);
92 va_end (ap);
93
94 return ret;
95 }
weak_alias(__nldbl_fprintf,__nldbl__IO_fprintf)96 weak_alias (__nldbl_fprintf, __nldbl__IO_fprintf)
97
98 int
99 attribute_compat_text_section weak_function
100 __nldbl_fwprintf (FILE *stream, const wchar_t *fmt, ...)
101 {
102 va_list ap;
103 int ret;
104
105 va_start (ap, fmt);
106 ret = __vfwprintf_internal (stream, fmt, ap, PRINTF_LDBL_IS_DBL);
107 va_end (ap);
108
109 return ret;
110 }
111
112 int
113 attribute_compat_text_section
__nldbl_printf(const char * fmt,...)114 __nldbl_printf (const char *fmt, ...)
115 {
116 va_list ap;
117 int ret;
118
119 va_start (ap, fmt);
120 ret = __vfprintf_internal (stdout, fmt, ap, PRINTF_LDBL_IS_DBL);
121 va_end (ap);
122
123 return ret;
124 }
strong_alias(__nldbl_printf,__nldbl__IO_printf)125 strong_alias (__nldbl_printf, __nldbl__IO_printf)
126
127 int
128 attribute_compat_text_section
129 __nldbl_sprintf (char *s, const char *fmt, ...)
130 {
131 va_list ap;
132 int ret;
133
134 va_start (ap, fmt);
135 ret = __vsprintf_internal (s, -1, fmt, ap, PRINTF_LDBL_IS_DBL);
136 va_end (ap);
137
138 return ret;
139 }
strong_alias(__nldbl_sprintf,__nldbl__IO_sprintf)140 strong_alias (__nldbl_sprintf, __nldbl__IO_sprintf)
141
142 int
143 attribute_compat_text_section
144 __nldbl_vfprintf (FILE *s, const char *fmt, va_list ap)
145 {
146 return __vfprintf_internal (s, fmt, ap, PRINTF_LDBL_IS_DBL);
147 }
strong_alias(__nldbl_vfprintf,__nldbl__IO_vfprintf)148 strong_alias (__nldbl_vfprintf, __nldbl__IO_vfprintf)
149
150 int
151 attribute_compat_text_section
152 __nldbl___vsprintf (char *string, const char *fmt, va_list ap)
153 {
154 return __vsprintf_internal (string, -1, fmt, ap, PRINTF_LDBL_IS_DBL);
155 }
strong_alias(__nldbl___vsprintf,__nldbl__IO_vsprintf)156 strong_alias (__nldbl___vsprintf, __nldbl__IO_vsprintf)
157 weak_alias (__nldbl___vsprintf, __nldbl_vsprintf)
158
159 int
160 attribute_compat_text_section
161 __nldbl_obstack_vprintf (struct obstack *obstack, const char *fmt,
162 va_list ap)
163 {
164 return __obstack_vprintf_internal (obstack, fmt, ap, PRINTF_LDBL_IS_DBL);
165 }
166
167 int
168 attribute_compat_text_section
__nldbl_obstack_printf(struct obstack * obstack,const char * fmt,...)169 __nldbl_obstack_printf (struct obstack *obstack, const char *fmt, ...)
170 {
171 int ret;
172 va_list ap;
173 va_start (ap, fmt);
174 ret = __obstack_vprintf_internal (obstack, fmt, ap, PRINTF_LDBL_IS_DBL);
175 va_end (ap);
176 return ret;
177 }
178
179 int
180 attribute_compat_text_section weak_function
__nldbl_snprintf(char * s,size_t maxlen,const char * fmt,...)181 __nldbl_snprintf (char *s, size_t maxlen, const char *fmt, ...)
182 {
183 va_list ap;
184 int ret;
185
186 va_start (ap, fmt);
187 ret = __vsnprintf_internal (s, maxlen, fmt, ap, PRINTF_LDBL_IS_DBL);
188 va_end (ap);
189
190 return ret;
191 }
192
193 int
194 attribute_compat_text_section
__nldbl_swprintf(wchar_t * s,size_t n,const wchar_t * fmt,...)195 __nldbl_swprintf (wchar_t *s, size_t n, const wchar_t *fmt, ...)
196 {
197 va_list ap;
198 int ret;
199
200 va_start (ap, fmt);
201 ret = __vswprintf_internal (s, n, fmt, ap, PRINTF_LDBL_IS_DBL);
202 va_end (ap);
203
204 return ret;
205 }
206
207 int
208 attribute_compat_text_section weak_function
__nldbl_vasprintf(char ** result_ptr,const char * fmt,va_list ap)209 __nldbl_vasprintf (char **result_ptr, const char *fmt, va_list ap)
210 {
211 return __vasprintf_internal (result_ptr, fmt, ap, PRINTF_LDBL_IS_DBL);
212 }
213
214 int
215 attribute_compat_text_section
__nldbl_vdprintf(int d,const char * fmt,va_list ap)216 __nldbl_vdprintf (int d, const char *fmt, va_list ap)
217 {
218 return __vdprintf_internal (d, fmt, ap, PRINTF_LDBL_IS_DBL);
219 }
220
221 int
222 attribute_compat_text_section weak_function
__nldbl_vfwprintf(FILE * s,const wchar_t * fmt,va_list ap)223 __nldbl_vfwprintf (FILE *s, const wchar_t *fmt, va_list ap)
224 {
225 return __vfwprintf_internal (s, fmt, ap, PRINTF_LDBL_IS_DBL);
226 }
227
228 int
229 attribute_compat_text_section
__nldbl_vprintf(const char * fmt,va_list ap)230 __nldbl_vprintf (const char *fmt, va_list ap)
231 {
232 return __vfprintf_internal (stdout, fmt, ap, PRINTF_LDBL_IS_DBL);
233 }
234
235 int
236 attribute_compat_text_section
__nldbl_vsnprintf(char * string,size_t maxlen,const char * fmt,va_list ap)237 __nldbl_vsnprintf (char *string, size_t maxlen, const char *fmt,
238 va_list ap)
239 {
240 return __vsnprintf_internal (string, maxlen, fmt, ap, PRINTF_LDBL_IS_DBL);
241 }
weak_alias(__nldbl_vsnprintf,__nldbl___vsnprintf)242 weak_alias (__nldbl_vsnprintf, __nldbl___vsnprintf)
243
244 int
245 attribute_compat_text_section weak_function
246 __nldbl_vswprintf (wchar_t *string, size_t maxlen, const wchar_t *fmt,
247 va_list ap)
248 {
249 return __vswprintf_internal (string, maxlen, fmt, ap, PRINTF_LDBL_IS_DBL);
250 }
251
252 int
253 attribute_compat_text_section
__nldbl_vwprintf(const wchar_t * fmt,va_list ap)254 __nldbl_vwprintf (const wchar_t *fmt, va_list ap)
255 {
256 return __vfwprintf_internal (stdout, fmt, ap, PRINTF_LDBL_IS_DBL);
257 }
258
259 int
260 attribute_compat_text_section
__nldbl_wprintf(const wchar_t * fmt,...)261 __nldbl_wprintf (const wchar_t *fmt, ...)
262 {
263 va_list ap;
264 int ret;
265
266 va_start (ap, fmt);
267 ret = __vfwprintf_internal (stdout, fmt, ap, PRINTF_LDBL_IS_DBL);
268 va_end (ap);
269
270 return ret;
271 }
272
273 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_29)
274 int
275 attribute_compat_text_section
__nldbl__IO_vfscanf(FILE * s,const char * fmt,va_list ap,int * errp)276 __nldbl__IO_vfscanf (FILE *s, const char *fmt, va_list ap, int *errp)
277 {
278 int ret = __vfscanf_internal (s, fmt, ap, SCANF_LDBL_IS_DBL);
279 if (__glibc_unlikely (errp != 0))
280 *errp = (ret == -1);
281 return ret;
282 }
283 #endif
284
285 int
286 attribute_compat_text_section
__nldbl___vfscanf(FILE * s,const char * fmt,va_list ap)287 __nldbl___vfscanf (FILE *s, const char *fmt, va_list ap)
288 {
289 return __vfscanf_internal (s, fmt, ap, SCANF_LDBL_IS_DBL);
290 }
weak_alias(__nldbl___vfscanf,__nldbl_vfscanf)291 weak_alias (__nldbl___vfscanf, __nldbl_vfscanf)
292 libc_hidden_def (__nldbl_vfscanf)
293
294 int
295 attribute_compat_text_section
296 __nldbl_sscanf (const char *s, const char *fmt, ...)
297 {
298 _IO_strfile sf;
299 FILE *f = _IO_strfile_read (&sf, s);
300 va_list ap;
301 int ret;
302
303 va_start (ap, fmt);
304 ret = __vfscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL);
305 va_end (ap);
306
307 return ret;
308 }
strong_alias(__nldbl_sscanf,__nldbl__IO_sscanf)309 strong_alias (__nldbl_sscanf, __nldbl__IO_sscanf)
310
311 int
312 attribute_compat_text_section
313 __nldbl___vsscanf (const char *s, const char *fmt, va_list ap)
314 {
315 _IO_strfile sf;
316 FILE *f = _IO_strfile_read (&sf, s);
317 return __vfscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL);
318 }
weak_alias(__nldbl___vsscanf,__nldbl_vsscanf)319 weak_alias (__nldbl___vsscanf, __nldbl_vsscanf)
320 libc_hidden_def (__nldbl_vsscanf)
321
322 int
323 attribute_compat_text_section weak_function
324 __nldbl_vscanf (const char *fmt, va_list ap)
325 {
326 return __vfscanf_internal (stdin, fmt, ap, SCANF_LDBL_IS_DBL);
327 }
328
329 int
330 attribute_compat_text_section
__nldbl_fscanf(FILE * stream,const char * fmt,...)331 __nldbl_fscanf (FILE *stream, const char *fmt, ...)
332 {
333 va_list ap;
334 int ret;
335
336 va_start (ap, fmt);
337 ret = __vfscanf_internal (stream, fmt, ap, SCANF_LDBL_IS_DBL);
338 va_end (ap);
339
340 return ret;
341 }
342
343 int
344 attribute_compat_text_section
__nldbl_scanf(const char * fmt,...)345 __nldbl_scanf (const char *fmt, ...)
346 {
347 va_list ap;
348 int ret;
349
350 va_start (ap, fmt);
351 ret = __vfscanf_internal (stdin, fmt, ap, SCANF_LDBL_IS_DBL);
352 va_end (ap);
353
354 return ret;
355 }
356
357 int
358 attribute_compat_text_section
__nldbl_vfwscanf(FILE * s,const wchar_t * fmt,va_list ap)359 __nldbl_vfwscanf (FILE *s, const wchar_t *fmt, va_list ap)
360 {
361 return __vfwscanf_internal (s, fmt, ap, SCANF_LDBL_IS_DBL);
362 }
libc_hidden_def(__nldbl_vfwscanf)363 libc_hidden_def (__nldbl_vfwscanf)
364
365 int
366 attribute_compat_text_section
367 __nldbl_swscanf (const wchar_t *s, const wchar_t *fmt, ...)
368 {
369 _IO_strfile sf;
370 struct _IO_wide_data wd;
371 FILE *f = _IO_strfile_readw (&sf, &wd, s);
372 va_list ap;
373 int ret;
374
375 va_start (ap, fmt);
376 ret = __vfwscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL);
377 va_end (ap);
378
379 return ret;
380 }
381
382 int
383 attribute_compat_text_section
__nldbl_vswscanf(const wchar_t * s,const wchar_t * fmt,va_list ap)384 __nldbl_vswscanf (const wchar_t *s, const wchar_t *fmt, va_list ap)
385 {
386 _IO_strfile sf;
387 struct _IO_wide_data wd;
388 FILE *f = _IO_strfile_readw (&sf, &wd, s);
389
390 return __vfwscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL);
391 }
libc_hidden_def(__nldbl_vswscanf)392 libc_hidden_def (__nldbl_vswscanf)
393
394 int
395 attribute_compat_text_section weak_function
396 __nldbl_vwscanf (const wchar_t *fmt, va_list ap)
397 {
398 return __vfwscanf_internal (stdin, fmt, ap, SCANF_LDBL_IS_DBL);
399 }
400
401 int
402 attribute_compat_text_section
__nldbl_fwscanf(FILE * stream,const wchar_t * fmt,...)403 __nldbl_fwscanf (FILE *stream, const wchar_t *fmt, ...)
404 {
405 va_list ap;
406 int ret;
407
408 va_start (ap, fmt);
409 ret = __vfwscanf_internal (stream, fmt, ap, SCANF_LDBL_IS_DBL);
410 va_end (ap);
411
412 return ret;
413 }
414
415 int
416 attribute_compat_text_section
__nldbl_wscanf(const wchar_t * fmt,...)417 __nldbl_wscanf (const wchar_t *fmt, ...)
418 {
419 va_list ap;
420 int ret;
421
422 va_start (ap, fmt);
423 ret = __vfwscanf_internal (stdin, fmt, ap, SCANF_LDBL_IS_DBL);
424 va_end (ap);
425
426 return ret;
427 }
428
429 int
430 attribute_compat_text_section
__nldbl___fprintf_chk(FILE * stream,int flag,const char * fmt,...)431 __nldbl___fprintf_chk (FILE *stream, int flag, const char *fmt, ...)
432 {
433 va_list ap;
434 int ret;
435 unsigned int mode = PRINTF_LDBL_IS_DBL;
436 if (flag > 0)
437 mode |= PRINTF_FORTIFY;
438
439 va_start (ap, fmt);
440 ret = __vfprintf_internal (stream, fmt, ap, mode);
441 va_end (ap);
442
443 return ret;
444 }
445
446 int
447 attribute_compat_text_section
__nldbl___fwprintf_chk(FILE * stream,int flag,const wchar_t * fmt,...)448 __nldbl___fwprintf_chk (FILE *stream, int flag, const wchar_t *fmt, ...)
449 {
450 va_list ap;
451 int ret;
452 unsigned int mode = PRINTF_LDBL_IS_DBL;
453 if (flag > 0)
454 mode |= PRINTF_FORTIFY;
455
456 va_start (ap, fmt);
457 ret = __vfwprintf_internal (stream, fmt, ap, mode);
458 va_end (ap);
459
460 return ret;
461 }
462
463 int
464 attribute_compat_text_section
__nldbl___printf_chk(int flag,const char * fmt,...)465 __nldbl___printf_chk (int flag, const char *fmt, ...)
466 {
467 va_list ap;
468 int ret;
469 unsigned int mode = PRINTF_LDBL_IS_DBL;
470 if (flag > 0)
471 mode |= PRINTF_FORTIFY;
472
473 va_start (ap, fmt);
474 ret = __vfprintf_internal (stdout, fmt, ap, mode);
475 va_end (ap);
476
477 return ret;
478 }
479
480 int
481 attribute_compat_text_section
__nldbl___snprintf_chk(char * s,size_t maxlen,int flag,size_t slen,const char * fmt,...)482 __nldbl___snprintf_chk (char *s, size_t maxlen, int flag, size_t slen,
483 const char *fmt, ...)
484 {
485 if (__glibc_unlikely (slen < maxlen))
486 __chk_fail ();
487
488 va_list ap;
489 int ret;
490 unsigned int mode = PRINTF_LDBL_IS_DBL;
491 if (flag > 0)
492 mode |= PRINTF_FORTIFY;
493
494 va_start (ap, fmt);
495 ret = __vsnprintf_internal (s, maxlen, fmt, ap, mode);
496 va_end (ap);
497
498 return ret;
499 }
500
501 int
502 attribute_compat_text_section
__nldbl___sprintf_chk(char * s,int flag,size_t slen,const char * fmt,...)503 __nldbl___sprintf_chk (char *s, int flag, size_t slen, const char *fmt, ...)
504 {
505 if (slen == 0)
506 __chk_fail ();
507
508 va_list ap;
509 int ret;
510 unsigned int mode = PRINTF_LDBL_IS_DBL;
511 if (flag > 0)
512 mode |= PRINTF_FORTIFY;
513
514 va_start (ap, fmt);
515 ret = __vsprintf_internal (s, slen, fmt, ap, mode);
516 va_end (ap);
517
518 return ret;
519 }
520
521 int
522 attribute_compat_text_section
__nldbl___swprintf_chk(wchar_t * s,size_t maxlen,int flag,size_t slen,const wchar_t * fmt,...)523 __nldbl___swprintf_chk (wchar_t *s, size_t maxlen, int flag, size_t slen,
524 const wchar_t *fmt, ...)
525 {
526 if (__glibc_unlikely (slen < maxlen))
527 __chk_fail ();
528
529 va_list ap;
530 int ret;
531 unsigned int mode = PRINTF_LDBL_IS_DBL;
532 if (flag > 0)
533 mode |= PRINTF_FORTIFY;
534
535 va_start (ap, fmt);
536 ret = __vswprintf_internal (s, maxlen, fmt, ap, mode);
537 va_end (ap);
538
539 return ret;
540 }
541
542 int
543 attribute_compat_text_section
__nldbl___vfprintf_chk(FILE * s,int flag,const char * fmt,va_list ap)544 __nldbl___vfprintf_chk (FILE *s, int flag, const char *fmt, va_list ap)
545 {
546 unsigned int mode = PRINTF_LDBL_IS_DBL;
547 if (flag > 0)
548 mode |= PRINTF_FORTIFY;
549
550 return __vfprintf_internal (s, fmt, ap, mode);
551 }
552
553 int
554 attribute_compat_text_section
__nldbl___vfwprintf_chk(FILE * s,int flag,const wchar_t * fmt,va_list ap)555 __nldbl___vfwprintf_chk (FILE *s, int flag, const wchar_t *fmt, va_list ap)
556 {
557 unsigned int mode = PRINTF_LDBL_IS_DBL;
558 if (flag > 0)
559 mode |= PRINTF_FORTIFY;
560
561 return __vfwprintf_internal (s, fmt, ap, mode);
562 }
563
564 int
565 attribute_compat_text_section
__nldbl___vprintf_chk(int flag,const char * fmt,va_list ap)566 __nldbl___vprintf_chk (int flag, const char *fmt, va_list ap)
567 {
568 unsigned int mode = PRINTF_LDBL_IS_DBL;
569 if (flag > 0)
570 mode |= PRINTF_FORTIFY;
571
572 return __vfprintf_internal (stdout, fmt, ap, mode);
573 }
574
575 int
576 attribute_compat_text_section
__nldbl___vsnprintf_chk(char * string,size_t maxlen,int flag,size_t slen,const char * fmt,va_list ap)577 __nldbl___vsnprintf_chk (char *string, size_t maxlen, int flag, size_t slen,
578 const char *fmt, va_list ap)
579 {
580 if (__glibc_unlikely (slen < maxlen))
581 __chk_fail ();
582
583 unsigned int mode = PRINTF_LDBL_IS_DBL;
584 if (flag > 0)
585 mode |= PRINTF_FORTIFY;
586
587 return __vsnprintf_internal (string, maxlen, fmt, ap, mode);
588 }
589
590 int
591 attribute_compat_text_section
__nldbl___vsprintf_chk(char * string,int flag,size_t slen,const char * fmt,va_list ap)592 __nldbl___vsprintf_chk (char *string, int flag, size_t slen, const char *fmt,
593 va_list ap)
594 {
595 if (slen == 0)
596 __chk_fail ();
597
598 unsigned int mode = PRINTF_LDBL_IS_DBL;
599 if (flag > 0)
600 mode |= PRINTF_FORTIFY;
601
602 return __vsprintf_internal (string, slen, fmt, ap, mode);
603 }
604
605 int
606 attribute_compat_text_section
__nldbl___vswprintf_chk(wchar_t * string,size_t maxlen,int flag,size_t slen,const wchar_t * fmt,va_list ap)607 __nldbl___vswprintf_chk (wchar_t *string, size_t maxlen, int flag, size_t slen,
608 const wchar_t *fmt, va_list ap)
609 {
610 if (__glibc_unlikely (slen < maxlen))
611 __chk_fail ();
612
613 unsigned int mode = PRINTF_LDBL_IS_DBL;
614 if (flag > 0)
615 mode |= PRINTF_FORTIFY;
616
617 return __vswprintf_internal (string, maxlen, fmt, ap, mode);
618 }
619
620 int
621 attribute_compat_text_section
__nldbl___vwprintf_chk(int flag,const wchar_t * fmt,va_list ap)622 __nldbl___vwprintf_chk (int flag, const wchar_t *fmt, va_list ap)
623 {
624 unsigned int mode = PRINTF_LDBL_IS_DBL;
625 if (flag > 0)
626 mode |= PRINTF_FORTIFY;
627
628 return __vfwprintf_internal (stdout, fmt, ap, mode);
629 }
630
631 int
632 attribute_compat_text_section
__nldbl___wprintf_chk(int flag,const wchar_t * fmt,...)633 __nldbl___wprintf_chk (int flag, const wchar_t *fmt, ...)
634 {
635 va_list ap;
636 int ret;
637 unsigned int mode = PRINTF_LDBL_IS_DBL;
638 if (flag > 0)
639 mode |= PRINTF_FORTIFY;
640
641 va_start (ap, fmt);
642 ret = __vfwprintf_internal (stdout, fmt, ap, mode);
643 va_end (ap);
644
645 return ret;
646 }
647
648 int
649 attribute_compat_text_section
__nldbl___vasprintf_chk(char ** ptr,int flag,const char * fmt,va_list ap)650 __nldbl___vasprintf_chk (char **ptr, int flag, const char *fmt, va_list ap)
651 {
652 unsigned int mode = PRINTF_LDBL_IS_DBL;
653 if (flag > 0)
654 mode |= PRINTF_FORTIFY;
655
656 return __vasprintf_internal (ptr, fmt, ap, mode);
657 }
658
659 int
660 attribute_compat_text_section
__nldbl___asprintf_chk(char ** ptr,int flag,const char * fmt,...)661 __nldbl___asprintf_chk (char **ptr, int flag, const char *fmt, ...)
662 {
663 va_list ap;
664 int ret;
665 unsigned int mode = PRINTF_LDBL_IS_DBL;
666 if (flag > 0)
667 mode |= PRINTF_FORTIFY;
668
669 va_start (ap, fmt);
670 ret = __vasprintf_internal (ptr, fmt, ap, mode);
671 va_end (ap);
672
673 return ret;
674 }
675
676 int
677 attribute_compat_text_section
__nldbl___vdprintf_chk(int d,int flag,const char * fmt,va_list ap)678 __nldbl___vdprintf_chk (int d, int flag, const char *fmt, va_list ap)
679 {
680 unsigned int mode = PRINTF_LDBL_IS_DBL;
681 if (flag > 0)
682 mode |= PRINTF_FORTIFY;
683
684 return __vdprintf_internal (d, fmt, ap, mode);
685 }
686
687 int
688 attribute_compat_text_section
__nldbl___dprintf_chk(int d,int flag,const char * fmt,...)689 __nldbl___dprintf_chk (int d, int flag, const char *fmt, ...)
690 {
691 va_list ap;
692 int ret;
693 unsigned int mode = PRINTF_LDBL_IS_DBL;
694 if (flag > 0)
695 mode |= PRINTF_FORTIFY;
696
697 va_start (ap, fmt);
698 ret = __vdprintf_internal (d, fmt, ap, mode);
699 va_end (ap);
700
701 return ret;
702 }
703
704 int
705 attribute_compat_text_section
__nldbl___obstack_vprintf_chk(struct obstack * obstack,int flag,const char * fmt,va_list ap)706 __nldbl___obstack_vprintf_chk (struct obstack *obstack, int flag,
707 const char *fmt, va_list ap)
708 {
709 unsigned int mode = PRINTF_LDBL_IS_DBL;
710 if (flag > 0)
711 mode |= PRINTF_FORTIFY;
712
713 return __obstack_vprintf_internal (obstack, fmt, ap, mode);
714 }
715
716 int
717 attribute_compat_text_section
__nldbl___obstack_printf_chk(struct obstack * obstack,int flag,const char * fmt,...)718 __nldbl___obstack_printf_chk (struct obstack *obstack, int flag,
719 const char *fmt, ...)
720 {
721 va_list ap;
722 int ret;
723 unsigned int mode = PRINTF_LDBL_IS_DBL;
724 if (flag > 0)
725 mode |= PRINTF_FORTIFY;
726
727 va_start (ap, fmt);
728 ret = __obstack_vprintf_internal (obstack, fmt, ap, mode);
729 va_end (ap);
730
731 return ret;
732 }
733
734 extern __typeof (printf_size) __printf_size;
735
736 int
737 attribute_compat_text_section
__nldbl_printf_size(FILE * fp,const struct printf_info * info,const void * const * args)738 __nldbl_printf_size (FILE *fp, const struct printf_info *info,
739 const void *const *args)
740 {
741 struct printf_info info_no_ldbl = *info;
742
743 info_no_ldbl.is_long_double = 0;
744 return __printf_size (fp, &info_no_ldbl, args);
745 }
746
747 extern __typeof (__printf_fp) ___printf_fp;
748
749 int
750 attribute_compat_text_section
__nldbl___printf_fp(FILE * fp,const struct printf_info * info,const void * const * args)751 __nldbl___printf_fp (FILE *fp, const struct printf_info *info,
752 const void *const *args)
753 {
754 struct printf_info info_no_ldbl = *info;
755
756 info_no_ldbl.is_long_double = 0;
757 return ___printf_fp (fp, &info_no_ldbl, args);
758 }
759
760 ssize_t
761 attribute_compat_text_section
__nldbl_strfmon(char * s,size_t maxsize,const char * format,...)762 __nldbl_strfmon (char *s, size_t maxsize, const char *format, ...)
763 {
764 va_list ap;
765 ssize_t ret;
766
767 va_start (ap, format);
768 ret = __vstrfmon_l_internal (s, maxsize, _NL_CURRENT_LOCALE, format, ap,
769 STRFMON_LDBL_IS_DBL);
770 va_end (ap);
771 return ret;
772 }
773
774 ssize_t
775 attribute_compat_text_section
__nldbl___strfmon_l(char * s,size_t maxsize,locale_t loc,const char * format,...)776 __nldbl___strfmon_l (char *s, size_t maxsize, locale_t loc,
777 const char *format, ...)
778 {
779 va_list ap;
780 ssize_t ret;
781
782 va_start (ap, format);
783 ret = __vstrfmon_l_internal (s, maxsize, loc, format, ap,
784 STRFMON_LDBL_IS_DBL);
785 va_end (ap);
786 return ret;
787 }
weak_alias(__nldbl___strfmon_l,__nldbl_strfmon_l)788 weak_alias (__nldbl___strfmon_l, __nldbl_strfmon_l)
789
790 ssize_t
791 attribute_compat_text_section
792 __nldbl___vstrfmon (char *s, size_t maxsize, const char *format, va_list ap)
793 {
794 return __vstrfmon_l_internal (s, maxsize, _NL_CURRENT_LOCALE, format, ap,
795 STRFMON_LDBL_IS_DBL);
796 }
797
798 ssize_t
799 attribute_compat_text_section
__nldbl___vstrfmon_l(char * s,size_t maxsize,locale_t loc,const char * format,va_list ap)800 __nldbl___vstrfmon_l (char *s, size_t maxsize, locale_t loc,
801 const char *format, va_list ap)
802 {
803 return __vstrfmon_l_internal (s, maxsize, loc, format, ap,
804 STRFMON_LDBL_IS_DBL);
805 }
806
807 void
808 attribute_compat_text_section
__nldbl_syslog(int pri,const char * fmt,...)809 __nldbl_syslog (int pri, const char *fmt, ...)
810 {
811 va_list ap;
812 va_start (ap, fmt);
813 __vsyslog_internal (pri, fmt, ap, PRINTF_LDBL_IS_DBL);
814 va_end (ap);
815 }
816
817 void
818 attribute_compat_text_section
__nldbl_vsyslog(int pri,const char * fmt,va_list ap)819 __nldbl_vsyslog (int pri, const char *fmt, va_list ap)
820 {
821 __vsyslog_internal (pri, fmt, ap, PRINTF_LDBL_IS_DBL);
822 }
823
824 void
825 attribute_compat_text_section
__nldbl___syslog_chk(int pri,int flag,const char * fmt,...)826 __nldbl___syslog_chk (int pri, int flag, const char *fmt, ...)
827 {
828 va_list ap;
829 unsigned int mode = PRINTF_LDBL_IS_DBL;
830 if (flag > 0)
831 mode |= PRINTF_FORTIFY;
832
833 va_start (ap, fmt);
834 __vsyslog_internal (pri, fmt, ap, mode);
835 va_end(ap);
836 }
837
838 void
839 attribute_compat_text_section
__nldbl___vsyslog_chk(int pri,int flag,const char * fmt,va_list ap)840 __nldbl___vsyslog_chk (int pri, int flag, const char *fmt, va_list ap)
841 {
842 unsigned int mode = PRINTF_LDBL_IS_DBL;
843 if (flag > 0)
844 mode |= PRINTF_FORTIFY;
845
846 __vsyslog_internal (pri, fmt, ap, mode);
847 }
848
849 int
850 attribute_compat_text_section
__nldbl___isoc99_vfscanf(FILE * s,const char * fmt,va_list ap)851 __nldbl___isoc99_vfscanf (FILE *s, const char *fmt, va_list ap)
852 {
853 return __vfscanf_internal (s, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A);
854 }
libc_hidden_def(__nldbl___isoc99_vfscanf)855 libc_hidden_def (__nldbl___isoc99_vfscanf)
856
857 int
858 attribute_compat_text_section
859 __nldbl___isoc99_sscanf (const char *s, const char *fmt, ...)
860 {
861 _IO_strfile sf;
862 FILE *f = _IO_strfile_read (&sf, s);
863 va_list ap;
864 int ret;
865
866 va_start (ap, fmt);
867 ret = __vfscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A);
868 va_end (ap);
869
870 return ret;
871 }
872
873 int
874 attribute_compat_text_section
__nldbl___isoc99_vsscanf(const char * s,const char * fmt,va_list ap)875 __nldbl___isoc99_vsscanf (const char *s, const char *fmt, va_list ap)
876 {
877 _IO_strfile sf;
878 FILE *f = _IO_strfile_read (&sf, s);
879
880 return __vfscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A);
881 }
libc_hidden_def(__nldbl___isoc99_vsscanf)882 libc_hidden_def (__nldbl___isoc99_vsscanf)
883
884 int
885 attribute_compat_text_section
886 __nldbl___isoc99_vscanf (const char *fmt, va_list ap)
887 {
888 return __vfscanf_internal (stdin, fmt, ap,
889 SCANF_LDBL_IS_DBL | SCANF_ISOC99_A);
890 }
891
892 int
893 attribute_compat_text_section
__nldbl___isoc99_fscanf(FILE * s,const char * fmt,...)894 __nldbl___isoc99_fscanf (FILE *s, const char *fmt, ...)
895 {
896 va_list ap;
897 int ret;
898
899 va_start (ap, fmt);
900 ret = __vfscanf_internal (s, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A);
901 va_end (ap);
902
903 return ret;
904 }
905
906 int
907 attribute_compat_text_section
__nldbl___isoc99_scanf(const char * fmt,...)908 __nldbl___isoc99_scanf (const char *fmt, ...)
909 {
910 va_list ap;
911 int ret;
912
913 va_start (ap, fmt);
914 ret = __vfscanf_internal (stdin, fmt, ap,
915 SCANF_LDBL_IS_DBL | SCANF_ISOC99_A);
916 va_end (ap);
917
918 return ret;
919 }
920
921 int
922 attribute_compat_text_section
__nldbl___isoc99_vfwscanf(FILE * s,const wchar_t * fmt,va_list ap)923 __nldbl___isoc99_vfwscanf (FILE *s, const wchar_t *fmt, va_list ap)
924 {
925 return __vfwscanf_internal (s, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A);
926 }
libc_hidden_def(__nldbl___isoc99_vfwscanf)927 libc_hidden_def (__nldbl___isoc99_vfwscanf)
928
929 int
930 attribute_compat_text_section
931 __nldbl___isoc99_swscanf (const wchar_t *s, const wchar_t *fmt, ...)
932 {
933 _IO_strfile sf;
934 struct _IO_wide_data wd;
935 FILE *f = _IO_strfile_readw (&sf, &wd, s);
936 va_list ap;
937 int ret;
938
939 va_start (ap, fmt);
940 ret = __vfwscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A);
941 va_end (ap);
942
943 return ret;
944 }
945
946 int
947 attribute_compat_text_section
__nldbl___isoc99_vswscanf(const wchar_t * s,const wchar_t * fmt,va_list ap)948 __nldbl___isoc99_vswscanf (const wchar_t *s, const wchar_t *fmt, va_list ap)
949 {
950 _IO_strfile sf;
951 struct _IO_wide_data wd;
952 FILE *f = _IO_strfile_readw (&sf, &wd, s);
953
954 return __vfwscanf_internal (f, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A);
955 }
libc_hidden_def(__nldbl___isoc99_vswscanf)956 libc_hidden_def (__nldbl___isoc99_vswscanf)
957
958 int
959 attribute_compat_text_section
960 __nldbl___isoc99_vwscanf (const wchar_t *fmt, va_list ap)
961 {
962 return __vfwscanf_internal (stdin, fmt, ap,
963 SCANF_LDBL_IS_DBL | SCANF_ISOC99_A);
964 }
965
966 int
967 attribute_compat_text_section
__nldbl___isoc99_fwscanf(FILE * s,const wchar_t * fmt,...)968 __nldbl___isoc99_fwscanf (FILE *s, const wchar_t *fmt, ...)
969 {
970 va_list ap;
971 int ret;
972
973 va_start (ap, fmt);
974 ret = __vfwscanf_internal (s, fmt, ap, SCANF_LDBL_IS_DBL | SCANF_ISOC99_A);
975 va_end (ap);
976
977 return ret;
978 }
979
980 int
981 attribute_compat_text_section
__nldbl___isoc99_wscanf(const wchar_t * fmt,...)982 __nldbl___isoc99_wscanf (const wchar_t *fmt, ...)
983 {
984 va_list ap;
985 int ret;
986
987 va_start (ap, fmt);
988 ret = __vfwscanf_internal (stdin, fmt, ap,
989 SCANF_LDBL_IS_DBL | SCANF_ISOC99_A);
990 va_end (ap);
991
992 return ret;
993 }
994
995 void
__nldbl_argp_error(const struct argp_state * state,const char * fmt,...)996 __nldbl_argp_error (const struct argp_state *state, const char *fmt, ...)
997 {
998 va_list ap;
999 va_start (ap, fmt);
1000 __argp_error_internal (state, fmt, ap, PRINTF_LDBL_IS_DBL);
1001 va_end (ap);
1002 }
1003
1004 void
__nldbl_argp_failure(const struct argp_state * state,int status,int errnum,const char * fmt,...)1005 __nldbl_argp_failure (const struct argp_state *state, int status,
1006 int errnum, const char *fmt, ...)
1007 {
1008 va_list ap;
1009 va_start (ap, fmt);
1010 __argp_failure_internal (state, status, errnum, fmt, ap,
1011 PRINTF_LDBL_IS_DBL);
1012 va_end (ap);
1013 }
1014
1015 #define VA_CALL(call) \
1016 { \
1017 va_list ap; \
1018 va_start (ap, format); \
1019 call (format, ap, PRINTF_LDBL_IS_DBL); \
1020 va_end (ap); \
1021 }
1022
1023 void
__nldbl_err(int status,const char * format,...)1024 __nldbl_err (int status, const char *format, ...)
1025 {
1026 VA_CALL (__vwarn_internal)
1027 exit (status);
1028 }
1029
1030 void
__nldbl_errx(int status,const char * format,...)1031 __nldbl_errx (int status, const char *format, ...)
1032 {
1033 VA_CALL (__vwarnx_internal)
1034 exit (status);
1035 }
1036
1037 void
__nldbl_verr(int status,const char * format,__gnuc_va_list ap)1038 __nldbl_verr (int status, const char *format, __gnuc_va_list ap)
1039 {
1040 __vwarn_internal (format, ap, PRINTF_LDBL_IS_DBL);
1041 exit (status);
1042 }
1043
1044 void
__nldbl_verrx(int status,const char * format,__gnuc_va_list ap)1045 __nldbl_verrx (int status, const char *format, __gnuc_va_list ap)
1046 {
1047 __vwarnx_internal (format, ap, PRINTF_LDBL_IS_DBL);
1048 exit (status);
1049 }
1050
1051 void
__nldbl_warn(const char * format,...)1052 __nldbl_warn (const char *format, ...)
1053 {
1054 VA_CALL (__vwarn_internal)
1055 }
1056
1057 void
__nldbl_warnx(const char * format,...)1058 __nldbl_warnx (const char *format, ...)
1059 {
1060 VA_CALL (__vwarnx_internal)
1061 }
1062
1063 void
__nldbl_vwarn(const char * format,__gnuc_va_list ap)1064 __nldbl_vwarn (const char *format, __gnuc_va_list ap)
1065 {
1066 __vwarn_internal (format, ap, PRINTF_LDBL_IS_DBL);
1067 }
1068
1069 void
__nldbl_vwarnx(const char * format,__gnuc_va_list ap)1070 __nldbl_vwarnx (const char *format, __gnuc_va_list ap)
1071 {
1072 __vwarnx_internal (format, ap, PRINTF_LDBL_IS_DBL);
1073 }
1074
1075 void
__nldbl_error(int status,int errnum,const char * message,...)1076 __nldbl_error (int status, int errnum, const char *message, ...)
1077 {
1078 va_list ap;
1079 va_start (ap, message);
1080 __error_internal (status, errnum, message, ap, PRINTF_LDBL_IS_DBL);
1081 va_end (ap);
1082 }
1083
1084 void
__nldbl_error_at_line(int status,int errnum,const char * file_name,unsigned int line_number,const char * message,...)1085 __nldbl_error_at_line (int status, int errnum, const char *file_name,
1086 unsigned int line_number, const char *message,
1087 ...)
1088 {
1089 va_list ap;
1090 va_start (ap, message);
1091 __error_at_line_internal (status, errnum, file_name, line_number,
1092 message, ap, PRINTF_LDBL_IS_DBL);
1093 va_end (ap);
1094 }
1095
1096 #if LONG_DOUBLE_COMPAT(libc, GLIBC_2_0)
1097 compat_symbol (libc, __nldbl__IO_printf, _IO_printf, GLIBC_2_0);
1098 compat_symbol (libc, __nldbl__IO_sprintf, _IO_sprintf, GLIBC_2_0);
1099 compat_symbol (libc, __nldbl__IO_vfprintf, _IO_vfprintf, GLIBC_2_0);
1100 compat_symbol (libc, __nldbl__IO_vsprintf, _IO_vsprintf, GLIBC_2_0);
1101 compat_symbol (libc, __nldbl_dprintf, dprintf, GLIBC_2_0);
1102 compat_symbol (libc, __nldbl_fprintf, fprintf, GLIBC_2_0);
1103 compat_symbol (libc, __nldbl_printf, printf, GLIBC_2_0);
1104 compat_symbol (libc, __nldbl_sprintf, sprintf, GLIBC_2_0);
1105 compat_symbol (libc, __nldbl_vfprintf, vfprintf, GLIBC_2_0);
1106 compat_symbol (libc, __nldbl_vprintf, vprintf, GLIBC_2_0);
1107 compat_symbol (libc, __nldbl__IO_fprintf, _IO_fprintf, GLIBC_2_0);
1108 compat_symbol (libc, __nldbl___vsnprintf, __vsnprintf, GLIBC_2_0);
1109 compat_symbol (libc, __nldbl_asprintf, asprintf, GLIBC_2_0);
1110 compat_symbol (libc, __nldbl_obstack_printf, obstack_printf, GLIBC_2_0);
1111 compat_symbol (libc, __nldbl_obstack_vprintf, obstack_vprintf, GLIBC_2_0);
1112 compat_symbol (libc, __nldbl_snprintf, snprintf, GLIBC_2_0);
1113 compat_symbol (libc, __nldbl_vasprintf, vasprintf, GLIBC_2_0);
1114 compat_symbol (libc, __nldbl_vdprintf, vdprintf, GLIBC_2_0);
1115 compat_symbol (libc, __nldbl_vsnprintf, vsnprintf, GLIBC_2_0);
1116 compat_symbol (libc, __nldbl_vsprintf, vsprintf, GLIBC_2_0);
1117 compat_symbol (libc, __nldbl__IO_sscanf, _IO_sscanf, GLIBC_2_0);
1118 compat_symbol (libc, __nldbl___vfscanf, __vfscanf, GLIBC_2_0);
1119 compat_symbol (libc, __nldbl___vsscanf, __vsscanf, GLIBC_2_0);
1120 compat_symbol (libc, __nldbl_fscanf, fscanf, GLIBC_2_0);
1121 compat_symbol (libc, __nldbl_scanf, scanf, GLIBC_2_0);
1122 compat_symbol (libc, __nldbl_sscanf, sscanf, GLIBC_2_0);
1123 compat_symbol (libc, __nldbl_vfscanf, vfscanf, GLIBC_2_0);
1124 compat_symbol (libc, __nldbl_vscanf, vscanf, GLIBC_2_0);
1125 compat_symbol (libc, __nldbl_vsscanf, vsscanf, GLIBC_2_0);
1126 compat_symbol (libc, __nldbl___printf_fp, __printf_fp, GLIBC_2_0);
1127 compat_symbol (libc, __nldbl_strfmon, strfmon, GLIBC_2_0);
1128 compat_symbol (libc, __nldbl_syslog, syslog, GLIBC_2_0);
1129 compat_symbol (libc, __nldbl_vsyslog, vsyslog, GLIBC_2_0);
1130 /* This function is not in public headers, but was exported until
1131 version 2.29. For platforms that are newer than that, there's no
1132 need to expose the symbol. */
1133 # if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_29)
1134 compat_symbol (libc, __nldbl__IO_vfscanf, _IO_vfscanf, GLIBC_2_0);
1135 # endif
1136 #endif
1137 #if LONG_DOUBLE_COMPAT(libc, GLIBC_2_1)
1138 compat_symbol (libc, __nldbl___asprintf, __asprintf, GLIBC_2_1);
1139 compat_symbol (libc, __nldbl_printf_size, printf_size, GLIBC_2_1);
1140 compat_symbol (libc, __nldbl___strfmon_l, __strfmon_l, GLIBC_2_1);
1141 #endif
1142 #if LONG_DOUBLE_COMPAT(libc, GLIBC_2_2)
1143 compat_symbol (libc, __nldbl_swprintf, swprintf, GLIBC_2_2);
1144 compat_symbol (libc, __nldbl_vwprintf, vwprintf, GLIBC_2_2);
1145 compat_symbol (libc, __nldbl_wprintf, wprintf, GLIBC_2_2);
1146 compat_symbol (libc, __nldbl_fwprintf, fwprintf, GLIBC_2_2);
1147 compat_symbol (libc, __nldbl_vfwprintf, vfwprintf, GLIBC_2_2);
1148 compat_symbol (libc, __nldbl_vswprintf, vswprintf, GLIBC_2_2);
1149 compat_symbol (libc, __nldbl_fwscanf, fwscanf, GLIBC_2_2);
1150 compat_symbol (libc, __nldbl_swscanf, swscanf, GLIBC_2_2);
1151 compat_symbol (libc, __nldbl_vfwscanf, vfwscanf, GLIBC_2_2);
1152 compat_symbol (libc, __nldbl_vswscanf, vswscanf, GLIBC_2_2);
1153 compat_symbol (libc, __nldbl_vwscanf, vwscanf, GLIBC_2_2);
1154 compat_symbol (libc, __nldbl_wscanf, wscanf, GLIBC_2_2);
1155 #endif
1156 #if LONG_DOUBLE_COMPAT(libc, GLIBC_2_3)
1157 compat_symbol (libc, __nldbl_strfmon_l, strfmon_l, GLIBC_2_3);
1158 #endif
1159 #if LONG_DOUBLE_COMPAT(libc, GLIBC_2_3_4)
1160 compat_symbol (libc, __nldbl___sprintf_chk, __sprintf_chk, GLIBC_2_3_4);
1161 compat_symbol (libc, __nldbl___vsprintf_chk, __vsprintf_chk, GLIBC_2_3_4);
1162 compat_symbol (libc, __nldbl___snprintf_chk, __snprintf_chk, GLIBC_2_3_4);
1163 compat_symbol (libc, __nldbl___vsnprintf_chk, __vsnprintf_chk, GLIBC_2_3_4);
1164 compat_symbol (libc, __nldbl___printf_chk, __printf_chk, GLIBC_2_3_4);
1165 compat_symbol (libc, __nldbl___fprintf_chk, __fprintf_chk, GLIBC_2_3_4);
1166 compat_symbol (libc, __nldbl___vprintf_chk, __vprintf_chk, GLIBC_2_3_4);
1167 compat_symbol (libc, __nldbl___vfprintf_chk, __vfprintf_chk, GLIBC_2_3_4);
1168 #endif
1169