libc - Adopt more linux-friendly basename() and dirname()
authorMatthew Dillon <dillon@apollo.backplane.com>
Sat, 4 Jan 2020 20:48:20 +0000 (12:48 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Sat, 4 Jan 2020 20:48:20 +0000 (12:48 -0800)
commit207ba6700e31c36bb4e38d4da221a4f86e466ee9
tree9bd76e22ee64b2d642d3e4a8be0caf26a6a6852b
parentd4379eb66bb7b7b22cb676f46d4bc304f9112775
libc - Adopt more linux-friendly basename() and dirname()

* Essentially take the FreeBSD basename() and dirname() code, changing
  the API to be more linux-friendly.  This reduces work required in dports.

* Adjust numerous cases in our base code that assumed the old prototypes
  and side effects.

* The passed-in string pointers are no longer const and can be modified
  in-place by the functions.  The returned value is no longer sometimes
  dynamically allocated and will instead either return a constant string,
  a portion of the passed in string, or a modified portion of the
  passed-in string.

  The API unfortunately has to be declared to return a char * instead of
  a const char *, even though it sometimes returns pointers to constant
  strings.

  The API is now thread-safe.

* The API is still a huge historical mess but at least the ports for
  the most part assume the above behavior now due to linux doing the
  same thing.

Reviewed-by: multiple people
12 files changed:
contrib/gdb-7/include/libiberty.h
include/libgen.h
lib/libc/gen/basename.c
lib/libc/gen/dirname.c
lib/libpam/libpam/pam_debug_log.c
lib/libutil/pw_util.c
sbin/devfsctl/devfsctl.c
sbin/hammer/cmd_pfs.c
usr.bin/evtranalyze/evtranalyze.c
usr.bin/newgrp/newgrp.c
usr.bin/shlock/shlock.c
usr.sbin/hotplugd/hotplugd.c