Make code compile when basename() is POSIX compliant.

In addition to the previous change I made to ar.c, pull in another
basename() related fix. This change is similar to the one made to the
ELF Toolchain version of ar, with the difference that the ELF Toolchain
version lacks error handling for the strdup() call.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D6467
This commit is contained in:
Ed Schouten 2016-05-26 13:49:40 +00:00
parent 6dd81be2d2
commit 09a113491c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=300741

View File

@ -124,6 +124,7 @@ create_obj_from_file(struct bsdar *bsdar, const char *name, time_t mtime)
struct ar_obj *obj;
struct stat sb;
const char *bname;
char *tmpname;
if (name == NULL)
return (NULL);
@ -137,7 +138,10 @@ create_obj_from_file(struct bsdar *bsdar, const char *name, time_t mtime)
return (NULL);
}
if ((bname = basename(name)) == NULL)
tmpname = strdup(name);
if (tmpname == NULL)
bsdar_errc(bsdar, EX_SOFTWARE, errno, "strdup failed");
if ((bname = basename(tmpname)) == NULL)
bsdar_errc(bsdar, EX_SOFTWARE, errno, "basename failed");
if (bsdar->options & AR_TR && strlen(bname) > _TRUNCATE_LEN) {
if ((obj->name = malloc(_TRUNCATE_LEN + 1)) == NULL)
@ -147,6 +151,7 @@ create_obj_from_file(struct bsdar *bsdar, const char *name, time_t mtime)
} else
if ((obj->name = strdup(bname)) == NULL)
bsdar_errc(bsdar, EX_SOFTWARE, errno, "strdup failed");
free(tmpname);
if (fstat(obj->fd, &sb) < 0) {
bsdar_warnc(bsdar, errno, "can't fstat file: %s", obj->name);