The branch main has been updated by obiwac: URL: https://cgit.FreeBSD.org/src/commit/?id=dc24f31b67f5b0bac35cb93470f6f2d065d99f6f
commit dc24f31b67f5b0bac35cb93470f6f2d065d99f6f Author: Aymeric Wibo <[email protected]> AuthorDate: 2026-06-19 14:21:12 +0000 Commit: Aymeric Wibo <[email protected]> CommitDate: 2026-06-19 14:21:16 +0000 ctermid(3): Fix return values section ctermid() doesn't, and has never, set errno. While here, add ctermid_r to the name section and align the parameter name in the source file. Reviewed by: bnovkov Approved by: bnovkov MFC after: 3 days Obtained from: https://github.com/apple-oss-distributions/libc Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D57396 --- lib/libc/gen/ctermid.3 | 25 +++++++++++++++---------- lib/libc/gen/ctermid.c | 14 +++++++------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/libc/gen/ctermid.3 b/lib/libc/gen/ctermid.3 index 2a53412f1b29..daf59f32c157 100644 --- a/lib/libc/gen/ctermid.3 +++ b/lib/libc/gen/ctermid.3 @@ -25,11 +25,12 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd October 1, 2011 +.Dd June 2, 2026 .Dt CTERMID 3 .Os .Sh NAME -.Nm ctermid +.Nm ctermid , +.Nm ctermid_r .Nd generate terminal pathname .Sh LIBRARY .Lb libc @@ -78,14 +79,18 @@ If no suitable lookup of the controlling terminal name can be performed, this implementation returns .Ql /dev/tty . .Sh RETURN VALUES -Upon successful completion, a -.Pf non- Dv NULL -pointer is returned. -Otherwise, a -.Dv NULL -pointer is returned and the global variable -.Va errno -is set to indicate the error. +The +.Fn ctermid +function returns +.Fa buf +if it is +.Pf non- Dv NULL , +otherwise it returns the address of a static buffer. +The +.Fn ctermid_r +function always returns +.Fa buf , +even if it is the NULL pointer. .Sh ERRORS The current implementation detects no error conditions. .Sh SEE ALSO diff --git a/lib/libc/gen/ctermid.c b/lib/libc/gen/ctermid.c index fb117b3c8ded..1ca2401f0c1d 100644 --- a/lib/libc/gen/ctermid.c +++ b/lib/libc/gen/ctermid.c @@ -39,32 +39,32 @@ #define LEN_PATH_DEV (sizeof(_PATH_DEV) - 1) char * -__ssp_real(ctermid)(char *s) +__ssp_real(ctermid)(char *buf) { static char def[sizeof(_PATH_DEV) + SPECNAMELEN]; struct stat sb; size_t dlen; int sverrno; - if (s == NULL) { - s = def; + if (buf == NULL) { + buf = def; dlen = sizeof(def) - LEN_PATH_DEV; } else dlen = L_ctermid - LEN_PATH_DEV; - strcpy(s, _PATH_TTY); + strcpy(buf, _PATH_TTY); /* Attempt to perform a lookup of the actual TTY pathname. */ sverrno = errno; if (stat(_PATH_TTY, &sb) == 0 && S_ISCHR(sb.st_mode)) - (void)sysctlbyname("kern.devname", s + LEN_PATH_DEV, + (void)sysctlbyname("kern.devname", buf + LEN_PATH_DEV, &dlen, &sb.st_rdev, sizeof(sb.st_rdev)); errno = sverrno; return (s); } char * -__ssp_real(ctermid_r)(char *s) +__ssp_real(ctermid_r)(char *buf) { - return (s != NULL ? ctermid(s) : NULL); + return (buf != NULL ? ctermid(buf) : NULL); }
