util.c (bmake-20201101) | : | util.c (bmake-20201117) | ||
---|---|---|---|---|
/* $NetBSD: util.c,v 1.64 2020/10/06 21:51:33 rillig Exp $ */ | /* $NetBSD: util.c,v 1.68 2020/11/16 18:29:49 rillig Exp $ */ | |||
/* | /* | |||
* Missing stuff from OS's | * Missing stuff from OS's | |||
* | * | |||
* $Id: util.c,v 1.39 2020/10/10 19:42:02 sjg Exp $ | * $Id: util.c,v 1.41 2020/11/18 03:58:32 sjg Exp $ | |||
*/ | */ | |||
#include <sys/param.h> | #include <sys/param.h> | |||
#include <errno.h> | #include <errno.h> | |||
#include <time.h> | #include <time.h> | |||
#include <signal.h> | #include <signal.h> | |||
#include "make.h" | #include "make.h" | |||
MAKE_RCSID("$NetBSD: util.c,v 1.64 2020/10/06 21:51:33 rillig Exp $"); | MAKE_RCSID("$NetBSD: util.c,v 1.68 2020/11/16 18:29:49 rillig Exp $"); | |||
#if !defined(MAKE_NATIVE) && !defined(HAVE_STRERROR) | #if !defined(MAKE_NATIVE) && !defined(HAVE_STRERROR) | |||
extern int errno, sys_nerr; | extern int errno, sys_nerr; | |||
extern char *sys_errlist[]; | extern char *sys_errlist[]; | |||
char * | char * | |||
strerror(int e) | strerror(int e) | |||
{ | { | |||
static char buf[100]; | static char buf[100]; | |||
if (e < 0 || e >= sys_nerr) { | if (e < 0 || e >= sys_nerr) { | |||
snprintf(buf, sizeof(buf), "Unknown error %d", e); | snprintf(buf, sizeof buf, "Unknown error %d", e); | |||
return buf; | return buf; | |||
} | } else | |||
else | ||||
return sys_errlist[e]; | return sys_errlist[e]; | |||
} | } | |||
#endif | #endif | |||
#if !defined(HAVE_GETENV) || !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV) | #if !defined(HAVE_GETENV) || !defined(HAVE_SETENV) || !defined(HAVE_UNSETENV) | |||
extern char **environ; | extern char **environ; | |||
static char * | static char * | |||
findenv(const char *name, int *offset) | findenv(const char *name, int *offset) | |||
{ | { | |||
skipping to change at line 99 | skipping to change at line 98 | |||
const char *cc; | const char *cc; | |||
size_t l_value, size; | size_t l_value, size; | |||
int offset; | int offset; | |||
if (name == NULL || value == NULL) { | if (name == NULL || value == NULL) { | |||
errno = EINVAL; | errno = EINVAL; | |||
return -1; | return -1; | |||
} | } | |||
if (*value == '=') /* no `=' in value */ | if (*value == '=') /* no `=' in value */ | |||
++value; | value++; | |||
l_value = strlen(value); | l_value = strlen(value); | |||
/* find if already exists */ | /* find if already exists */ | |||
if ((c = findenv(name, &offset))) { | if ((c = findenv(name, &offset))) { | |||
if (!rewrite) | if (!rewrite) | |||
return 0; | return 0; | |||
if (strlen(c) >= l_value) /* old larger; copy over */ | if (strlen(c) >= l_value) /* old larger; copy over */ | |||
goto copy; | goto copy; | |||
} else { /* create new slot */ | } else { /* create new slot */ | |||
size = sizeof(char *) * (offset + 2); | size = sizeof(char *) * (offset + 2); | |||
skipping to change at line 292 | skipping to change at line 291 | |||
nextpathptr, strerror(errno)); | nextpathptr, strerror(errno)); | |||
return NULL; | return NULL; | |||
} | } | |||
/* look in the parent for the entry with the same inode */ | /* look in the parent for the entry with the same inode */ | |||
if (DEV_DEV_COMPARE(st_dotdot.st_dev, st_cur.st_dev)) { | if (DEV_DEV_COMPARE(st_dotdot.st_dev, st_cur.st_dev)) { | |||
/* Parent has same device. No need to stat every member */ | /* Parent has same device. No need to stat every member */ | |||
for (d = readdir(dp); d != NULL; d = readdir(dp)) | for (d = readdir(dp); d != NULL; d = readdir(dp)) | |||
if (d->d_fileno == st_cur.st_ino) | if (d->d_fileno == st_cur.st_ino) | |||
break; | break; | |||
} | } else { | |||
else { | ||||
/* | /* | |||
* Parent has a different device. This is a mount point so we | * Parent has a different device. This is a mount point so we | |||
* need to stat every member | * need to stat every member | |||
*/ | */ | |||
for (d = readdir(dp); d != NULL; d = readdir(dp)) { | for (d = readdir(dp); d != NULL; d = readdir(dp)) { | |||
if (ISDOT(d->d_name) || ISDOTDOT(d->d_name)) | if (ISDOT(d->d_name) || ISDOTDOT(d->d_name)) | |||
continue; | continue; | |||
(void)strcpy(cur_name_add, d->d_name); | (void)strcpy(cur_name_add, d->d_name); | |||
if (lstat(nextpathptr, &st_next) == -1) { | if (lstat(nextpathptr, &st_next) == -1) { | |||
(void)sprintf(pathname, | (void)sprintf(pathname, | |||
skipping to change at line 385 | skipping to change at line 383 | |||
{ | { | |||
#ifdef STRFLAG | #ifdef STRFLAG | |||
FILE fakebuf; | FILE fakebuf; | |||
fakebuf._flag = STRFLAG; | fakebuf._flag = STRFLAG; | |||
/* | /* | |||
* Some os's are char * _ptr, others are unsigned char *_ptr... | * Some os's are char * _ptr, others are unsigned char *_ptr... | |||
* We cast to void * to make everyone happy. | * We cast to void * to make everyone happy. | |||
*/ | */ | |||
fakebuf._ptr = (void *)s; | fakebuf._ptr = (void *)s; | |||
fakebuf._cnt = n-1; | fakebuf._cnt = n - 1; | |||
fakebuf._file = -1; | fakebuf._file = -1; | |||
_doprnt(fmt, args, &fakebuf); | _doprnt(fmt, args, &fakebuf); | |||
fakebuf._cnt++; | fakebuf._cnt++; | |||
putc('\0', &fakebuf); | putc('\0', &fakebuf); | |||
if (fakebuf._cnt<0) | if (fakebuf._cnt < 0) | |||
fakebuf._cnt = 0; | fakebuf._cnt = 0; | |||
return n-fakebuf._cnt-1; | return n - fakebuf._cnt - 1; | |||
#else | #else | |||
#ifndef _PATH_DEVNULL | #ifndef _PATH_DEVNULL | |||
# define _PATH_DEVNULL "/dev/null" | # define _PATH_DEVNULL "/dev/null" | |||
#endif | #endif | |||
/* | /* | |||
* Rats... we don't want to clobber anything... | * Rats... we don't want to clobber anything... | |||
* do a printf to /dev/null to see how much space we need. | * do a printf to /dev/null to see how much space we need. | |||
*/ | */ | |||
static FILE *nullfp; | static FILE *nullfp; | |||
int need = 0; /* XXX what's a useful error return? */ | int need = 0; /* XXX what's a useful error return? */ | |||
End of changes. 10 change blocks. | ||||
12 lines changed or deleted | 10 lines changed or added |