From owner-svn-src-all@freebsd.org Thu Jul 28 16:20:28 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AA19CBA7C0B; Thu, 28 Jul 2016 16:20:28 +0000 (UTC) (envelope-from ed@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 mx1.freebsd.org (Postfix) with ESMTPS id 855B11E05; Thu, 28 Jul 2016 16:20:28 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u6SGKRNB027764; Thu, 28 Jul 2016 16:20:27 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u6SGKRAp027759; Thu, 28 Jul 2016 16:20:27 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201607281620.u6SGKRAp027759@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Thu, 28 Jul 2016 16:20:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r303451 - in head: include lib/libc/gen X-SVN-Group: head 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.22 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: Thu, 28 Jul 2016 16:20:28 -0000 Author: ed Date: Thu Jul 28 16:20:27 2016 New Revision: 303451 URL: https://svnweb.freebsd.org/changeset/base/303451 Log: Fix up prototypes of basename(3) and dirname(3) to comply to POSIX. POSIX allows these functions to be implemented in a way that the resulting string is stored in the input buffer. Though some may find this annoying, this has the advantage that it makes it possible to implement this function in a thread-safe way. It also means that they can be implemented in a way that they work for paths of arbitrary length, as the output string of these functions is never longer than max(1, len(input)). Portable code already needs to be written with this in mind, so in my opinion it makes very little sense to allow the existing behaviour. Prevent the base system from falling back to this by switching over to POSIX prototypes. I'm not going to bump the __FreeBSD_version for this. The reason is that it's possible to account for this change in a portable way, without depending on a specific version of FreeBSD. An exp-run was done some time ago. As far as I know, all regressions as a result of this have already been fixed. I'll give this change some time to settle. In the long run I want to replace our copies by ones that are thread-safe and don't depend on PATH_MAX/MAXPATHLEN. Modified: head/include/libgen.h head/lib/libc/gen/basename.3 head/lib/libc/gen/basename.c head/lib/libc/gen/dirname.3 head/lib/libc/gen/dirname.c Modified: head/include/libgen.h ============================================================================== --- head/include/libgen.h Thu Jul 28 16:06:37 2016 (r303450) +++ head/include/libgen.h Thu Jul 28 16:20:27 2016 (r303451) @@ -34,9 +34,9 @@ #include __BEGIN_DECLS -char *basename(const char *); +char *basename(char *); char *basename_r(const char *, char *); -char *dirname(const char *); +char *dirname(char *); __END_DECLS #endif /* !_LIBGEN_H_ */ Modified: head/lib/libc/gen/basename.3 ============================================================================== --- head/lib/libc/gen/basename.3 Thu Jul 28 16:06:37 2016 (r303450) +++ head/lib/libc/gen/basename.3 Thu Jul 28 16:20:27 2016 (r303451) @@ -16,7 +16,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 31, 2010 +.Dd July 28, 2016 .Dt BASENAME 3 .Os .Sh NAME @@ -25,7 +25,7 @@ .Sh SYNOPSIS .In libgen.h .Ft char * -.Fn basename "const char *path" +.Fn basename "char *path" .Ft char * .Fn basename_r "const char *path" "char *bname" .Sh DESCRIPTION Modified: head/lib/libc/gen/basename.c ============================================================================== --- head/lib/libc/gen/basename.c Thu Jul 28 16:06:37 2016 (r303450) +++ head/lib/libc/gen/basename.c Thu Jul 28 16:20:27 2016 (r303451) @@ -66,7 +66,7 @@ basename_r(const char *path, char *bname } char * -basename(const char *path) +basename(char *path) { static char *bname = NULL; Modified: head/lib/libc/gen/dirname.3 ============================================================================== --- head/lib/libc/gen/dirname.3 Thu Jul 28 16:06:37 2016 (r303450) +++ head/lib/libc/gen/dirname.3 Thu Jul 28 16:20:27 2016 (r303451) @@ -16,7 +16,7 @@ .\" .\" $FreeBSD$ .\" -.Dd October 12, 2006 +.Dd July 28, 2016 .Dt DIRNAME 3 .Os .Sh NAME @@ -25,7 +25,7 @@ .Sh SYNOPSIS .In libgen.h .Ft char * -.Fn dirname "const char *path" +.Fn dirname "char *path" .Sh DESCRIPTION The .Fn dirname Modified: head/lib/libc/gen/dirname.c ============================================================================== --- head/lib/libc/gen/dirname.c Thu Jul 28 16:06:37 2016 (r303450) +++ head/lib/libc/gen/dirname.c Thu Jul 28 16:20:27 2016 (r303451) @@ -26,7 +26,7 @@ __FBSDID("$FreeBSD$"); #include char * -dirname(const char *path) +dirname(char *path) { static char *dname = NULL; size_t len;