From owner-svn-src-stable@freebsd.org Tue Jun 5 13:53:38 2018 Return-Path: Delivered-To: svn-src-stable@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 CAEF4FDE5E9; Tue, 5 Jun 2018 13:53:38 +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 7C5AB79C7B; Tue, 5 Jun 2018 13:53:38 +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 446121D541; Tue, 5 Jun 2018 13:53:38 +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 w55DrchR087345; Tue, 5 Jun 2018 13:53:38 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w55Drb7X087344; Tue, 5 Jun 2018 13:53:37 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201806051353.w55Drb7X087344@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 5 Jun 2018 13:53:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r334655 - stable/11/lib/libc/stdio X-SVN-Group: stable-11 X-SVN-Commit-Author: kib X-SVN-Commit-Paths: stable/11/lib/libc/stdio X-SVN-Commit-Revision: 334655 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jun 2018 13:53:39 -0000 Author: kib Date: Tue Jun 5 13:53:37 2018 New Revision: 334655 URL: https://svnweb.freebsd.org/changeset/base/334655 Log: MFC r334031: Implement printf(3) family %m format string extension. Modified: stable/11/lib/libc/stdio/printf.3 stable/11/lib/libc/stdio/vfprintf.c Directory Properties: stable/11/ (props changed) Modified: stable/11/lib/libc/stdio/printf.3 ============================================================================== --- stable/11/lib/libc/stdio/printf.3 Tue Jun 5 13:46:18 2018 (r334654) +++ stable/11/lib/libc/stdio/printf.3 Tue Jun 5 13:53:37 2018 (r334655) @@ -32,7 +32,7 @@ .\" @(#)printf.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd December 2, 2009 +.Dd May 22, 2018 .Dt PRINTF 3 .Os .Sh NAME @@ -642,6 +642,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 % @@ -749,6 +755,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 @@ -786,9 +798,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 @@ -841,6 +855,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: stable/11/lib/libc/stdio/vfprintf.c ============================================================================== --- stable/11/lib/libc/stdio/vfprintf.c Tue Jun 5 13:46:18 2018 (r334654) +++ stable/11/lib/libc/stdio/vfprintf.c Tue Jun 5 13:53:37 2018 (r334655) @@ -315,6 +315,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 */ @@ -464,6 +465,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; @@ -774,6 +776,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