Bug 238313 - printf(1) man page incorrect about \c in format string
Summary: printf(1) man page incorrect about \c in format string
Status: Closed FIXED
Alias: None
Product: Documentation
Classification: Unclassified
Component: Manual Pages (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Many People
Assignee: Jilles Tjoelker
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-03 17:36 UTC by Andras Farkas
Modified: 2019-08-05 20:29 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andras Farkas 2019-06-03 17:36:11 UTC
Incorrectly, the man page for printf(1) states that the \c escape works all the time.  In reality, on FreeBSD, (and according to POSIX too) the \c escape only works for text meant for the %b format specifier, but not in the format itself.

Actual behavior on FreeBSD (which is also correct POSIX behavior):
$ /usr/bin/printf 'foo\cbar\n'
foocbar
$ /usr/bin/printf '%b' 'foo\cbar\n'
foo$ 
# The above '$ ' in 'foo$ ' is from the shell, not printf.
$ uname -a
FreeBSD nyann.tanasinn.mochi 12.0-RELEASE-p4 FreeBSD 12.0-RELEASE-p4 GENERIC  amd64
$ freebsd-version
12.0-RELEASE-p5

The solution for this would be to move the info about \c to the section about the %b format, where its own special \0 handling is also specified.

Useful references:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html
https://www.freebsd.org/cgi/man.cgi?query=printf&apropos=0&sektion=0&manpath=FreeBSD+12.0-RELEASE+and+Ports&arch=default&format=html
Comment 1 commit-hook freebsd_committer freebsd_triage 2019-07-29 20:43:12 UTC
A commit references this bug:

Author: jilles
Date: Mon Jul 29 20:43:08 UTC 2019
New revision: 350425
URL: https://svnweb.freebsd.org/changeset/base/350425

Log:
  printf(1): Note that \c only works in %b strings

  PR:		238313
  Reported by:	Andras Farkas
  MFC after:	1 week

Changes:
  head/usr.bin/printf/printf.1
Comment 2 commit-hook freebsd_committer freebsd_triage 2019-08-05 20:19:53 UTC
A commit references this bug:

Author: jilles
Date: Mon Aug  5 20:19:38 UTC 2019
New revision: 350613
URL: https://svnweb.freebsd.org/changeset/base/350613

Log:
  MFC r350425: printf(1): Note that \c only works in %b strings

  PR:		238313

Changes:
_U  stable/12/
  stable/12/usr.bin/printf/printf.1
Comment 3 commit-hook freebsd_committer freebsd_triage 2019-08-05 20:21:56 UTC
A commit references this bug:

Author: jilles
Date: Mon Aug  5 20:21:35 UTC 2019
New revision: 350615
URL: https://svnweb.freebsd.org/changeset/base/350615

Log:
  MFC r350425: printf(1): Note that \c only works in %b strings

  PR:		238313

Changes:
_U  stable/11/
  stable/11/usr.bin/printf/printf.1
Comment 4 Jilles Tjoelker freebsd_committer freebsd_triage 2019-08-05 20:29:17 UTC
Fixed, thanks for the report.