summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2001-06-05 11:59:12 +0000
committerMarc Espie <espie@cvs.openbsd.org>2001-06-05 11:59:12 +0000
commit7d64392752053c3c94ba590f1bceaa3fab18ec30 (patch)
treeae87790fd2d192a48e35d9a3a0e83a13eb1619aa
parent50fd278686078d1ecb7465227e8fb43215f489a9 (diff)
Use Str_concat instead of fixed buffers and snprintf in building paths.
Replace MAXPATHLEN with PATH_MAX (synch with op-make). ok naddy@
-rw-r--r--usr.bin/make/Makefile3
-rw-r--r--usr.bin/make/arch.c18
-rw-r--r--usr.bin/make/config.h8
-rw-r--r--usr.bin/make/main.c78
4 files changed, 67 insertions, 40 deletions
diff --git a/usr.bin/make/Makefile b/usr.bin/make/Makefile
index 67d27fc3a6b..4123ad1cecc 100644
--- a/usr.bin/make/Makefile
+++ b/usr.bin/make/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.27 2001/05/23 12:34:39 espie Exp $
+# $OpenBSD: Makefile,v 1.28 2001/06/05 11:59:09 espie Exp $
PROG= make
CFLAGS+= -I${.OBJDIR} -I${.CURDIR} ${WARNINGS}
@@ -7,6 +7,7 @@ WARNINGS=-Wall -W -Wno-char-subscripts -Wstrict-prototypes -pedantic -Wmissing-p
CFLAGS+=-DUSE_TIMESPEC
CFLAGS+=-DHAS_BOOL_H
CFLAGS+=-DHAS_PATHS_H
+CFLAGS+=-DHAS_EXTENDED_GETCWD
.if (${MACHINE_ARCH} == "m88k")
CFLAGS+=-O0
.endif
diff --git a/usr.bin/make/arch.c b/usr.bin/make/arch.c
index 26bb6481682..4d055b5eb03 100644
--- a/usr.bin/make/arch.c
+++ b/usr.bin/make/arch.c
@@ -1,5 +1,5 @@
/* $OpenPackages$ */
-/* $OpenBSD: arch.c,v 1.47 2001/05/30 00:43:00 deraadt Exp $ */
+/* $OpenBSD: arch.c,v 1.48 2001/06/05 11:59:10 espie Exp $ */
/* $NetBSD: arch.c,v 1.17 1996/11/06 17:58:59 christos Exp $ */
/*
@@ -99,6 +99,14 @@
#include "timestamp.h"
#include "lst.h"
+#ifndef PATH_MAX
+# ifdef MAXPATHLEN
+# define PATH_MAX (MAXPATHLEN+1)
+# else
+# define PATH_MAX 1024
+# endif
+#endif
+
#ifdef TARGET_MACHINE
#undef MACHINE
#define MACHINE TARGET_MACHINE
@@ -436,7 +444,7 @@ read_archive(archive, end)
size_t n;
struct ar_hdr arh; /* Archive-member header for reading archive */
off_t size; /* Size of archive member */
- char buffer[MAXPATHLEN+1];
+ char buffer[PATH_MAX];
char *memName;
/* Current member name while hashing. */
char *cp; /* Useful character pointer */
@@ -499,7 +507,7 @@ read_archive(archive, end)
int elen = atoi(memName + sizeof(AR_EFMT1)-1);
- if (elen <= 0 || elen > MAXPATHLEN)
+ if (elen <= 0 || elen >= PATH_MAX)
break;
memName = buffer;
if (fread(memName, elen, 1, arch) != 1)
@@ -822,11 +830,11 @@ ArchFindMember(archive, member, arhPtr, mode)
* first <namelen> bytes of the file. */
if (memcmp(memName, AR_EFMT1, sizeof(AR_EFMT1) - 1) == 0 &&
isdigit(memName[sizeof(AR_EFMT1) - 1])) {
- char ename[MAXPATHLEN+1];
+ char ename[PATH_MAX];
int elen = atoi(memName + sizeof(AR_EFMT1)-1);
- if (elen <= 0 || elen > MAXPATHLEN)
+ if (elen <= 0 || elen >= PATH_MAX)
break;
if (fread(ename, elen, 1, arch) != 1)
break;
diff --git a/usr.bin/make/config.h b/usr.bin/make/config.h
index 76c7adaa050..a5f9e27af75 100644
--- a/usr.bin/make/config.h
+++ b/usr.bin/make/config.h
@@ -2,7 +2,7 @@
#define CONFIG_H
/* $OpenPackages$ */
-/* $OpenBSD: config.h,v 1.11 2001/05/23 12:34:41 espie Exp $ */
+/* $OpenBSD: config.h,v 1.12 2001/06/05 11:59:11 espie Exp $ */
/* $NetBSD: config.h,v 1.7 1996/11/06 17:59:03 christos Exp $ */
/*
@@ -114,6 +114,12 @@
# endif
#endif
+#ifdef HAS_EXTENDED_GETCWD
+#define dogetcwd() getcwd(NULL, 0)
+#else
+#define dogetcwd() getcwd(emalloc(PATH_MAX), PATH_MAX)
+#endif
+
#ifdef SYSVINCLUDE
#define DOFEATURE_SYSVINCLUDE FEATURE_SYSVINCLUDE
#else
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index 44194425161..45876e00565 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -1,5 +1,5 @@
/* $OpenPackages$ */
-/* $OpenBSD: main.c,v 1.52 2001/06/03 16:33:48 espie Exp $ */
+/* $OpenBSD: main.c,v 1.53 2001/06/05 11:59:11 espie Exp $ */
/* $NetBSD: main.c,v 1.34 1997/03/24 20:56:36 gwr Exp $ */
/*
@@ -70,6 +70,14 @@
#include "memory.h"
#include "make.h"
+#ifndef PATH_MAX
+# ifdef MAXPATHLEN
+# define PATH_MAX (MAXPATHLEN+1)
+# else
+# define PATH_MAX 1024
+# endif
+#endif
+
#ifndef DEFMAXLOCAL
#define DEFMAXLOCAL DEFMAXJOBS
#endif /* DEFMAXLOCAL */
@@ -99,7 +107,7 @@ bool oldVars; /* variable substitution style */
bool checkEnvFirst; /* -e flag */
static void MainParseArgs(int, char **);
-static char * chdir_verify_path(char *, char *);
+static char * chdir_verify_path(char *);
static int ReadMakefile(void *, void *);
static void add_dirpath(Lst, const char *);
static void usage(void);
@@ -398,9 +406,8 @@ Main_ParseArgLine(line)
}
char *
-chdir_verify_path(path, obpath)
+chdir_verify_path(path)
char *path;
- char *obpath;
{
struct stat sb;
@@ -410,12 +417,10 @@ chdir_verify_path(path, obpath)
path, strerror(errno));
return NULL;
} else {
- if (path[0] != '/') {
- (void)snprintf(obpath, MAXPATHLEN, "%s/%s", curdir, path);
- return obpath;
- }
+ if (path[0] != '/')
+ return Str_concat(curdir, path, '/');
else
- return path;
+ return estrdup(path);
}
}
@@ -470,9 +475,7 @@ main(argc, argv)
bool outOfDate = true; /* false if all targets up to date */
struct stat sb, sa;
char *p, *path, *pathp, *pwd;
- char mdpath[MAXPATHLEN + 1];
- char obpath[MAXPATHLEN + 1];
- char cdpath[MAXPATHLEN + 1];
+ char *mdpath;
char *machine = getenv("MACHINE");
char *machine_arch = getenv("MACHINE_ARCH");
const char *syspath = _PATH_DEFSYSPATH;
@@ -495,8 +498,7 @@ main(argc, argv)
* All this code is so that we know where we are when we start up
* on a different machine with pmake.
*/
- curdir = cdpath;
- if (getcwd(curdir, MAXPATHLEN) == NULL) {
+ if ((curdir = dogetcwd()) == NULL) {
(void)fprintf(stderr, "make: %s.\n", strerror(errno));
exit(2);
}
@@ -509,8 +511,10 @@ main(argc, argv)
if ((pwd = getenv("PWD")) != NULL) {
if (stat(pwd, &sb) == 0 && sa.st_ino == sb.st_ino &&
- sa.st_dev == sb.st_dev && strlen(pwd) <= MAXPATHLEN)
- (void)strcpy(curdir, pwd);
+ sa.st_dev == sb.st_dev) {
+ free(curdir);
+ curdir = estrdup(pwd);
+ }
}
/*
@@ -556,29 +560,29 @@ main(argc, argv)
* and modify the paths for the Makefiles apropriately. The
* current directory is also placed as a variable for make scripts.
*/
+ mdpath = NULL;
if (!(pathp = getenv("MAKEOBJDIRPREFIX"))) {
if (!(path = getenv("MAKEOBJDIR"))) {
path = _PATH_OBJDIR;
pathp = _PATH_OBJDIRPREFIX;
- (void)snprintf(mdpath, MAXPATHLEN, "%s.%s",
- path, machine);
- if (!(objdir = chdir_verify_path(mdpath, obpath)))
- if (!(objdir=chdir_verify_path(path, obpath))) {
- (void)snprintf(mdpath, MAXPATHLEN,
- "%s%s", pathp, curdir);
- if (!(objdir=chdir_verify_path(mdpath,
- obpath)))
+ mdpath = Str_concat(path, machine, '.');
+ if (!(objdir = chdir_verify_path(mdpath)))
+ if (!(objdir=chdir_verify_path(path))) {
+ free(mdpath);
+ mdpath = Str_concat(pathp, curdir, 0);
+ if (!(objdir=chdir_verify_path(mdpath)))
objdir = curdir;
}
}
- else if (!(objdir = chdir_verify_path(path, obpath)))
+ else if (!(objdir = chdir_verify_path(path)))
objdir = curdir;
}
else {
- (void)snprintf(mdpath, MAXPATHLEN, "%s%s", pathp, curdir);
- if (!(objdir = chdir_verify_path(mdpath, obpath)))
+ mdpath = Str_concat(pathp, curdir, 0);
+ if (!(objdir = chdir_verify_path(mdpath)))
objdir = curdir;
}
+ free(mdpath);
esetenv("PWD", objdir);
unsetenv("CDPATH");
@@ -781,6 +785,11 @@ main(argc, argv)
if (DEBUG(GRAPH2))
Targ_PrintGraph(2);
+#ifdef CLEANUP
+ if (objdir != curdir)
+ free(objdir);
+ free(curdir);
+#endif
if (queryFlag && outOfDate)
return 1;
else
@@ -804,7 +813,7 @@ ReadMakefile(p, q)
{
char *fname = p; /* makefile to read */
FILE *stream;
- char *name, path[MAXPATHLEN + 1];
+ char *name;
if (!strcmp(fname, "-")) {
Var_Set("MAKEFILE", "", VAR_GLOBAL);
@@ -814,11 +823,14 @@ ReadMakefile(p, q)
goto found;
/* if we've chdir'd, rebuild the path name */
if (curdir != objdir && *fname != '/') {
- (void)snprintf(path, sizeof path, "%s/%s", curdir,
- fname);
- if ((stream = fopen(path, "r")) != NULL) {
- fname = estrdup(path);
- goto found;
+ char *path;
+
+ path = Str_concat(curdir, fname, '/');
+ if ((stream = fopen(path, "r")) == NULL)
+ free(path);
+ else {
+ fname = path;
+ goto found;
}
}
/* look in -I and system include directories. */