From bcac9d59b1c709715ee9a9d1aa6246381ce113ff Mon Sep 17 00:00:00 2001 From: guenther Date: Wed, 7 Aug 2024 05:15:28 +0000 Subject: [PATCH] asprintf() and vasprintf() are in POSIX-2024. Update #include visibility and manpages and add restrict qualifiers in all the specified places to the *printf family. ok millert@ --- include/stdio.h | 34 +++++++++++++++++++--------------- lib/libc/stdio/printf.3 | 32 +++++++++++++++++--------------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/include/stdio.h b/include/stdio.h index 0db964f3409..74bcd6ff3e3 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -1,4 +1,4 @@ -/* $OpenBSD: stdio.h,v 1.55 2022/01/05 20:57:27 millert Exp $ */ +/* $OpenBSD: stdio.h,v 1.56 2024/08/07 05:15:28 guenther Exp $ */ /* $NetBSD: stdio.h,v 1.18 1996/04/25 18:29:21 jtc Exp $ */ /*- @@ -217,7 +217,7 @@ int fgetpos(FILE *, fpos_t *); char *fgets(char *, int, FILE *) __attribute__((__bounded__ (__string__,1,2))); FILE *fopen(const char *, const char *); -int fprintf(FILE *, const char *, ...); +int fprintf(FILE *, const char * __restrict, ...); int fputc(int, FILE *); int fputs(const char *, FILE *); size_t fread(void *, size_t, size_t, FILE *) @@ -246,7 +246,7 @@ extern int sys_nerr; /* perror(3) external variables */ extern char *sys_errlist[]; #endif void perror(const char *); -int printf(const char *, ...); +int printf(const char * __restrict, ...); int putc(int, FILE *); int putchar(int); int puts(const char *); @@ -259,14 +259,14 @@ void rewind(FILE *); int scanf(const char *, ...); void setbuf(FILE *, char *); int setvbuf(FILE *, char *, int, size_t); -int sprintf(char *, const char *, ...); +int sprintf(char * __restrict, const char * __restrict, ...); int sscanf(const char *, const char *, ...); FILE *tmpfile(void); char *tmpnam(char *); int ungetc(int, FILE *); -int vfprintf(FILE *, const char *, __va_list); -int vprintf(const char *, __va_list); -int vsprintf(char *, const char *, __va_list); +int vfprintf(FILE *, const char * __restrict, __va_list); +int vprintf(const char * __restrict, __va_list); +int vsprintf(char * __restrict, const char * __restrict, __va_list); #if __POSIX_VISIBLE >= 200809 int vdprintf(int, const char * __restrict, __va_list) __attribute__((__format__ (printf, 2, 0))) @@ -274,11 +274,12 @@ int vdprintf(int, const char * __restrict, __va_list) #endif #if __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE >= 500 || __BSD_VISIBLE -int snprintf(char *, size_t, const char *, ...) +int snprintf(char * __restrict, size_t, const char * __restrict, ...) __attribute__((__format__ (printf, 3, 4))) __attribute__((__nonnull__ (3))) __attribute__((__bounded__ (__string__,1,2))); -int vsnprintf(char *, size_t, const char *, __va_list) +int vsnprintf(char * __restrict, size_t, const char * __restrict, + __va_list) __attribute__((__format__ (printf, 3, 0))) __attribute__((__nonnull__ (3))) __attribute__((__bounded__(__string__,1,2))); @@ -338,6 +339,15 @@ FILE *open_memstream(char **, size_t *); #if __XPG_VISIBLE char *tempnam(const char *, const char *); #endif + +#if __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE +int asprintf(char ** __restrict, const char * __restrict, ...) + __attribute__((__format__ (printf, 2, 3))) + __attribute__((__nonnull__ (2))); +int vasprintf(char ** __restrict, const char * __restrict, __va_list) + __attribute__((__format__ (printf, 2, 0))) + __attribute__((__nonnull__ (2))); +#endif /* __POSIX_VISIBLE >= 202405 || __BSD_VISIBLE */ __END_DECLS #endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */ @@ -347,18 +357,12 @@ __END_DECLS */ #if __BSD_VISIBLE __BEGIN_DECLS -int asprintf(char **, const char *, ...) - __attribute__((__format__ (printf, 2, 3))) - __attribute__((__nonnull__ (2))); char *fgetln(FILE *, size_t *); int fpurge(FILE *); int getw(FILE *); int putw(int, FILE *); void setbuffer(FILE *, char *, int); int setlinebuf(FILE *); -int vasprintf(char **, const char *, __va_list) - __attribute__((__format__ (printf, 2, 0))) - __attribute__((__nonnull__ (2))); __END_DECLS /* diff --git a/lib/libc/stdio/printf.3 b/lib/libc/stdio/printf.3 index 2e09cc82442..7984acbc8c4 100644 --- a/lib/libc/stdio/printf.3 +++ b/lib/libc/stdio/printf.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: printf.3,v 1.93 2022/08/04 06:20:24 jsg Exp $ +.\" $OpenBSD: printf.3,v 1.94 2024/08/07 05:15:28 guenther Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,7 @@ .\" .\" @(#)printf.3 8.1 (Berkeley) 6/4/93 .\" -.Dd $Mdocdate: August 4 2022 $ +.Dd $Mdocdate: August 7 2024 $ .Dt PRINTF 3 .Os .Sh NAME @@ -53,29 +53,29 @@ .Sh SYNOPSIS .In stdio.h .Ft int -.Fn printf "const char *format" ... +.Fn printf "const char * restrict format" ... .Ft int -.Fn fprintf "FILE *stream" "const char *format" ... +.Fn fprintf "FILE *stream" "const char * restrict format" ... .Ft int -.Fn sprintf "char *str" "const char *format" ... +.Fn sprintf "char * restrict str" "const char * restrict format" ... .Ft int -.Fn snprintf "char *str" "size_t size" "const char *format" ... +.Fn snprintf "char * restrict str" "size_t size" "const char * restrict format" ... .Ft int -.Fn asprintf "char **ret" "const char *format" ... +.Fn asprintf "char ** restrict ret" "const char * restrict format" ... .Ft int .Fn dprintf "int fd" "const char * restrict format" ... .In stdarg.h .In stdio.h .Ft int -.Fn vprintf "const char *format" "va_list ap" +.Fn vprintf "const char * restrict format" "va_list ap" .Ft int -.Fn vfprintf "FILE *stream" "const char *format" "va_list ap" +.Fn vfprintf "FILE *stream" "const char * restrict format" "va_list ap" .Ft int -.Fn vsprintf "char *str" "const char *format" "va_list ap" +.Fn vsprintf "char * restrict str" "const char * restrict format" "va_list ap" .Ft int -.Fn vsnprintf "char *str" "size_t size" "const char *format" "va_list ap" +.Fn vsnprintf "char * restrict str" "size_t size" "const char * restrict format" "va_list ap" .Ft int -.Fn vasprintf "char **ret" "const char *format" "va_list ap" +.Fn vasprintf "char ** restrict ret" "const char * restrict format" "va_list ap" .Ft int .Fn vdprintf "int fd" "const char * restrict format" "va_list ap" .Sh DESCRIPTION @@ -906,11 +906,13 @@ and functions conform to .St -isoC-99 . The -.Fn dprintf +.Fn dprintf , +.Fn vdprintf , +.Fn asprintf , and -.Fn vdprintf +.Fn vasprintf functions conform to -.St -p1003.1-2008 . +.St -p1003.1-2024 . .Sh HISTORY The predecessors .Fn ftoa -- 2.20.1