From owner-svn-src-all@freebsd.org Tue May 22 11:05:41 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 77623EF16D9; Tue, 22 May 2018 11:05:41 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 22CD46EEF8; Tue, 22 May 2018 11:05:41 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id F36BC13300; Tue, 22 May 2018 11:05:40 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w4MB5e21032117; Tue, 22 May 2018 11:05:40 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w4MB5ep3032115; Tue, 22 May 2018 11:05:40 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201805221105.w4MB5ep3032115@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 22 May 2018 11:05:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334031 - head/lib/libc/stdio X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: head/lib/libc/stdio X-SVN-Commit-Revision: 334031 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 May 2018 11:05:41 -0000 Author: kib Date: Tue May 22 11:05:40 2018 New Revision: 334031 URL: https://svnweb.freebsd.org/changeset/base/334031 Log: Implement printf(3) family %m format string extension. Reviewed by: ed, dim (code only) Sponsored by: Mellanox Technologies MFC after: 1 week Modified: head/lib/libc/stdio/printf.3 head/lib/libc/stdio/vfprintf.c Modified: head/lib/libc/stdio/printf.3 ============================================================================== --- head/lib/libc/stdio/printf.3 Tue May 22 10:31:06 2018 (r334030) +++ head/lib/libc/stdio/printf.3 Tue May 22 11:05:40 2018 (r334031) @@ -32,7 +32,7 @@ .\" @(#)printf.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd July 30, 2016 +.Dd May 22, 2018 .Dt PRINTF 3 .Os .Sh NAME @@ -651,6 +651,12 @@ integer indicated by the .Vt "int *" (or variant) pointer argument. No argument is converted. +.It Cm m +Print the string representation of the error code stored in the +.Dv errno +variable at the beginning of the call, as returned by +.Xr strerror 3 . +No argument is taken. .It Cm % A .Ql % @@ -730,6 +736,12 @@ and .Cm \&%U are not standard and are provided only for backward compatibility. +The conversion format +.Cm \&%m +is also not standard and provides the popular extension from the +.Tn GNU C +library. +.Pp The effect of padding the .Cm %p format with zeros (either by the @@ -767,9 +779,11 @@ or the return value would be too large to be represent .El .Sh SEE ALSO .Xr printf 1 , +.Xr errno 2 , .Xr fmtcheck 3 , .Xr scanf 3 , .Xr setlocale 3 , +.Xr strerror 3 , .Xr wprintf 3 .Sh STANDARDS Subject to the caveats noted in the @@ -822,6 +836,12 @@ and .Fn vdprintf functions were added in .Fx 8.0 . +The +.Cm \&%m +format extension first appeared in the +.Tn GNU C +library, and was implemented in +.Fx 12.0 . .Sh BUGS The .Nm Modified: head/lib/libc/stdio/vfprintf.c ============================================================================== --- head/lib/libc/stdio/vfprintf.c Tue May 22 10:31:06 2018 (r334030) +++ head/lib/libc/stdio/vfprintf.c Tue May 22 11:05:40 2018 (r334031) @@ -317,6 +317,7 @@ __vfprintf(FILE *fp, locale_t locale, const char *fmt0 int ret; /* return value accumulator */ int width; /* width from format (%8d), or 0 */ int prec; /* precision from format; <0 for N/A */ + int saved_errno; char sign; /* sign prefix (' ', '+', '-', or \0) */ struct grouping_state gs; /* thousands' grouping info */ @@ -466,6 +467,7 @@ __vfprintf(FILE *fp, locale_t locale, const char *fmt0 savserr = fp->_flags & __SERR; fp->_flags &= ~__SERR; + saved_errno = errno; convbuf = NULL; fmt = (char *)fmt0; argtable = NULL; @@ -776,6 +778,11 @@ fp_common: } break; #endif /* !NO_FLOATING_POINT */ + case 'm': + cp = strerror(saved_errno); + size = (prec >= 0) ? strnlen(cp, prec) : strlen(cp); + sign = '\0'; + break; case 'n': /* * Assignment-like behavior is specified if the