Commit Graph

11 Commits

Author SHA1 Message Date
Ed Schouten
34168b28e9 Replace basename(3) by a thread-safe implementation.
Now that the changes to the dirname(3) function had some time to settle,
let's go ahead and use the same approach for replacing basename(3) by a
simple implementation that modifies the input string, thereby making it
thread-safe and guaranteed to succeed.

Unlike dirname(3), this function already had a thread-safe variant
basename_r(3). This function had its own set of problems, like having an
upper bound on the pathname length. Keep this function around for
compatibility, but remove most references from the man page. Make the
man page more similar to that of dirname(3).

As the basename_r(3) function is only provided by FreeBSD (and Bionic),
depending on its use is even more implementation defined than assuming
that basename(3) is thread-safe.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D8382
2016-11-03 20:21:34 +00:00
Ed Schouten
938809f941 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.
2016-07-28 16:20:27 +00:00
Xin LI
488d6e0c3d Sync with OpenBSD, primarily make the code easier to read, and a license
change to standard OpenBSD ISC license.

Obtained from:	OpenBSD
MFC after:	2 weeks
2011-06-18 00:33:34 +00:00
Robert Watson
a502a84d5a Add basename_r(3) to complement basename(3). basename_r(3) which accepts
a caller-allocated buffer of at least MAXPATHLEN, rather than using a
global buffer.

MFC after:	1 month
Sponsored by:	Google
2009-10-06 14:05:57 +00:00
Marcel Moolenaar
2bc46a6452 Fix LP64 architectures and especially ia64. Functions that return
a pointer and lack a prototype will have the return value (assumed
to be an integer) zero-extended to a pointer. On ia64 this is
unconditionally fatal as it zeroes-out the region bits, forming an
invalid pointer. Fix the sigsegv by including <stdlib.h>.

Pointy hat: bbraun
2002-12-30 01:41:14 +00:00
Rob Braun
5fb691beab Reduce libc.so's memory footprint by lazily allocating memory used internally
by basename() and dirname().
Reviewed by: eric
2002-12-21 07:12:35 +00:00
David E. O'Brien
22626efa0f * Remove 'register'. (some functions had 7+ register functions...)
* Fix SCM ID's.
2002-02-01 01:08:48 +00:00
Bruce Evans
56bcbf00e2 Fixed world breakage due to missing include of <sys/cdefs.h> in previous
commit.

Fixed related style bugs:
basename.c: misplaced '#if 0'
dirname.c: misplaced '#if 0'
getgrent.c: missing '#if 0', and tab lossage in vendor id (the previous
            commit fixed the complete corruption of the vendor id but
	    lost a tab)
getpwent.c: missing '#if 0'
2002-01-31 12:58:36 +00:00
David E. O'Brien
135b57f906 Fix FreeBSD IDs. 2002-01-30 21:36:57 +00:00
Dima Dorfman
ff5f0dbc41 Fix a one-byte overrun.
PR:		28472
Submitted by:	David Xu <davidx@viasoft.com.cn>
Obtained from:	OpenBSD
2001-06-28 21:50:53 +00:00
Dag-Erling Smørgrav
1250db8139 Import XPG4-compliant basename(3) and dirname(3) from OpenBSD.
The man pages need some adjustments.

PR:		12960, 12962
Submitted by:	James Howard <howardjp@wam.umd.edu>
Obtained from:	OpenBSD
2000-08-31 15:56:15 +00:00