From db800d7063722e8a1d418939f8877c1993822b00 Mon Sep 17 00:00:00 2001 From: pk Date: Wed, 8 Mar 1995 19:41:53 +0000 Subject: [PATCH] Use ${DESTDIR}. --- games/phantasia/Makefile | 2 +- games/phantasia/setup.c | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/games/phantasia/Makefile b/games/phantasia/Makefile index d34fc3574524..42fbf9d11db0 100644 --- a/games/phantasia/Makefile +++ b/games/phantasia/Makefile @@ -15,7 +15,7 @@ setup: phantglobs.o setup.o monsters.asc ${LIBM} beforeinstall: ./setup -m ${.CURDIR}/monsters.asc - chown games.bin /var/games/phantasia/* + chown games.bin ${DESTDIR}/var/games/phantasia/* # Make Phantasia map. Change the map commands reflect your installation. # PLOTDEVICE is used for plotting the map. Change as appropriate. diff --git a/games/phantasia/setup.c b/games/phantasia/setup.c index f916727fb694..da55980da898 100644 --- a/games/phantasia/setup.c +++ b/games/phantasia/setup.c @@ -2,7 +2,7 @@ * setup.c - set up all files for Phantasia */ #include "include.h" -#include +#include #include #include /* */ @@ -61,6 +61,7 @@ main(argc, argv) FILE *fp; /* for opening files */ struct stat fbuf; /* for getting files statistics */ int ch; + char path[MAXPATHLEN], *prefix; while ((ch = getopt(argc, argv, "m:")) != EOF) switch(ch) { @@ -78,12 +79,15 @@ main(argc, argv) umask(0117); /* only owner can read/write created files */ + prefix = getenv("DESTDIR"); + /* try to create data files */ filename = &files[0]; while (*filename != NULL) /* create each file */ { - if (stat(*filename, &fbuf) == 0) + snprintf(path, sizeof(path), "%s%s", prefix?prefix:"", *filename); + if (stat(path, &fbuf) == 0) /* file exists; remove it */ { if (!strcmp(*filename, _PATH_PEOPLE)) @@ -93,13 +97,13 @@ main(argc, argv) continue; } - if (unlink(*filename) < 0) - Error("Cannot unlink %s.\n", *filename); + if (unlink(path) < 0) + Error("Cannot unlink %s.\n", path); /*NOTREACHED*/ } - if ((fd = creat(*filename, 0660)) < 0) - Error("Cannot create %s.\n", *filename); + if ((fd = creat(path, 0660)) < 0) + Error("Cannot create %s.\n", path); /*NOTREACHED*/ close(fd); /* close newly created file */ @@ -111,8 +115,9 @@ main(argc, argv) Enrgyvoid.ev_active = TRUE; Enrgyvoid.ev_x = ROLL(-1.0e6, 2.0e6); Enrgyvoid.ev_y = ROLL(-1.0e6, 2.0e6); - if ((fp = fopen(_PATH_VOID, "w")) == NULL) - Error("Cannot update %s.\n", _PATH_VOID); + snprintf(path, sizeof(path), "%s%s", prefix?prefix:"", _PATH_VOID); + if ((fp = fopen(path, "w")) == NULL) + Error("Cannot update %s.\n", path); else { fwrite(&Enrgyvoid, SZ_VOIDSTRUCT, 1, fp); @@ -120,8 +125,9 @@ main(argc, argv) } /* create binary monster data base */ - if ((Monstfp = fopen(_PATH_MONST, "w")) == NULL) - Error("Cannot update %s.\n", _PATH_MONST); + snprintf(path, sizeof(path), "%s%s", prefix?prefix:"", _PATH_MONST); + if ((Monstfp = fopen(path, "w")) == NULL) + Error("Cannot update %s.\n", path); else { if ((fp = fopen(monsterfile, "r")) == NULL) @@ -160,8 +166,9 @@ main(argc, argv) printf("One line 'motd' ? "); if (fgets(Databuf, SZ_DATABUF, stdin) == NULL) Databuf[0] = '\0'; - if ((fp = fopen(_PATH_MOTD, "w")) == NULL) - Error("Cannot update %s.\n", _PATH_MOTD); + snprintf(path, sizeof(path), "%s%s", prefix?prefix:"", _PATH_MOTD); + if ((fp = fopen(path, "w")) == NULL) + Error("Cannot update %s.\n", path); else { fwrite(Databuf, sizeof(char), strlen(Databuf), fp);