WARNS=2 cleanup.

Tested on:	i386, alpha
MFC after:	2 weeks
This commit is contained in:
Maxim Sobolev 2001-10-10 06:58:42 +00:00
parent f8bb49cd4f
commit d100deb8cc
27 changed files with 184 additions and 175 deletions

View File

@ -5,6 +5,8 @@ SRCS= main.c perform.c futil.c extract.c
CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib
WARNS?= 2
DPADD= ${LIBINSTALL} ${LIBFETCH} ${LIBMD}
LDADD= ${LIBINSTALL} -lfetch -lmd

View File

@ -38,7 +38,7 @@ extern char FirstPen[];
extern add_mode_t AddMode;
int make_hierarchy(char *);
void extract_plist(char *, Package *);
void apply_perms(char *, char *);
void extract_plist(const char *, Package *);
void apply_perms(const char *, const char *);
#endif /* _INST_ADD_H_INCLUDE */

View File

@ -29,17 +29,17 @@ static const char rcsid[] =
#define STARTSTRING "tar cf - "
#define TOOBIG(str) ((strlen(str) + FILENAME_MAX + where_count > maxargs) \
|| (strlen(str) + FILENAME_MAX + perm_count > maxargs))
#define TOOBIG(str) (((int)strlen(str) + FILENAME_MAX + where_count > maxargs) \
|| ((int)strlen(str) + FILENAME_MAX + perm_count > maxargs))
#define PUSHOUT(todir) /* push out string */ \
if (where_count > sizeof(STARTSTRING)-1) { \
if (where_count > (int)sizeof(STARTSTRING)-1) { \
strcat(where_args, "|tar --unlink -xf - -C "); \
strcat(where_args, todir); \
if (system(where_args)) { \
cleanup(0); \
errx(2, __FUNCTION__ ": can not invoke %d byte tar pipeline: %s", \
strlen(where_args), where_args); \
errx(2, __FUNCTION__ ": can not invoke %ld byte tar pipeline: %s", \
(long)strlen(where_args), where_args); \
} \
strcpy(where_args, STARTSTRING); \
where_count = sizeof(STARTSTRING)-1; \
@ -51,10 +51,11 @@ static const char rcsid[] =
}
static void
rollback(char *name, char *home, PackingList start, PackingList stop)
rollback(const char *name, const char *home, PackingList start, PackingList stop)
{
PackingList q;
char try[FILENAME_MAX], bup[FILENAME_MAX], *dir;
char try[FILENAME_MAX], bup[FILENAME_MAX];
const char *dir;
dir = home;
for (q = start; q != stop; q = q->next) {
@ -77,7 +78,7 @@ rollback(char *name, char *home, PackingList start, PackingList stop)
}
void
extract_plist(char *home, Package *pkg)
extract_plist(const char *home, Package *pkg)
{
PackingList p = pkg->head;
char *last_file;
@ -109,7 +110,7 @@ extract_plist(char *home, Package *pkg)
Group = NULL;
Mode = NULL;
last_file = NULL;
Directory = home;
(const char *)Directory = home;
/* Do it */
while (p) {
@ -207,7 +208,7 @@ extract_plist(char *home, Package *pkg)
Directory = p->name;
}
else
Directory = home;
(const char *)Directory = home;
break;
case PLIST_CMD:

View File

@ -70,9 +70,9 @@ make_hierarchy(char *dir)
/* Using permission defaults, apply them as necessary */
void
apply_perms(char *dir, char *arg)
apply_perms(const char *dir, const char *arg)
{
char *cd_to;
const char *cd_to;
if (!dir || *arg == '/') /* absolute path? */
cd_to = "/";

View File

@ -159,7 +159,7 @@ main(int argc, char **argv)
errx(1, "package name too long");
}
if (!strcmp(*argv, "-")) /* stdin? */
pkgs[ch] = "-";
(const char *)pkgs[ch] = "-";
else if (isURL(*argv)) { /* preserve URLs */
if (strlcpy(pkgnames[ch], *argv, sizeof(pkgnames[ch]))
>= sizeof(pkgnames[ch]))

View File

@ -136,7 +136,7 @@ pkg_do(char *pkg)
}
Home = make_playpen(playpen, sb.st_size * 4);
if (!Home)
errx(1, "unable to make playpen for %qd bytes", sb.st_size * 4);
errx(1, "unable to make playpen for %qd bytes", (long long)sb.st_size * 4);
where_to = Home;
/* Since we can call ourselves recursively, keep notes on where we came from */
if (!getenv("_TOP"))
@ -192,7 +192,7 @@ pkg_do(char *pkg)
if (!inPlace && min_free(playpen) < sb.st_size * 4) {
warnx("projected size of %qd exceeds available free space.\n"
"Please set your PKG_TMPDIR variable to point to a location with more\n"
"free space and try again", sb.st_size * 4);
"free space and try again", (long long)sb.st_size * 4);
warnx("not extracting %s\ninto %s, sorry!",
pkg_fullname, where_to);
goto bomb;
@ -232,7 +232,7 @@ pkg_do(char *pkg)
setenv(PKG_PREFIX_VNAME, (p = find_plist(&Plist, PLIST_CWD)) ? p->name : ".", 1);
/* Protect against old packages with bogus @name fields */
PkgName = (p = find_plist(&Plist, PLIST_NAME)) ? p->name : "anonymous";
(const char *)PkgName = (p = find_plist(&Plist, PLIST_NAME)) ? p->name : "anonymous";
/* See if we're already registered */
sprintf(LogDir, "%s/%s", LOG_DIR, PkgName);
@ -391,7 +391,7 @@ pkg_do(char *pkg)
/* Time to record the deed? */
if (!NoRecord && !Fake) {
char contents[FILENAME_MAX];
FILE *cfile;
FILE *contfile;
if (getuid() != 0)
warnx("not running as root - trying to record install anyway");
@ -430,14 +430,14 @@ pkg_do(char *pkg)
if (fexists(MTREE_FNAME))
move_file(".", MTREE_FNAME, LogDir);
sprintf(contents, "%s/%s", LogDir, CONTENTS_FNAME);
cfile = fopen(contents, "w");
if (!cfile) {
contfile = fopen(contents, "w");
if (!contfile) {
warnx("can't open new contents file '%s'! can't register pkg",
contents);
goto success; /* can't log, but still keep pkg */
}
write_plist(&Plist, cfile);
fclose(cfile);
write_plist(&Plist, contfile);
fclose(contfile);
for (p = Plist.head; p ; p = p->next) {
if (p->type != PLIST_PKGDEP)
continue;
@ -445,13 +445,13 @@ pkg_do(char *pkg)
printf("Attempting to record dependency on package '%s'\n", p->name);
sprintf(contents, "%s/%s/%s", LOG_DIR, basename(p->name),
REQUIRED_BY_FNAME);
cfile = fopen(contents, "a");
if (!cfile)
contfile = fopen(contents, "a");
if (!contfile)
warnx("can't open dependency file '%s'!\n"
"dependency registration is incomplete", contents);
else {
fprintf(cfile, "%s\n", PkgName);
if (fclose(cfile) == EOF)
fprintf(contfile, "%s\n", PkgName);
if (fclose(contfile) == EOF)
warnx("cannot properly close file %s", contents);
}
}

View File

@ -5,6 +5,8 @@ SRCS= main.c perform.c pl.c
CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib
WARNS?= 2
DPADD= ${LIBINSTALL} ${LIBFETCH} ${LIBMD}
LDADD= ${LIBINSTALL} -lfetch -lmd

View File

@ -44,8 +44,8 @@ extern int Dereference;
extern int PlistOnly;
extern int UseBzip2;
void check_list(char *, Package *);
void check_list(const char *, Package *);
int pkg_perform(char **);
void copy_plist(char *, Package *);
void copy_plist(const char *, Package *);
#endif /* _INST_CREATE_H_INCLUDE */

View File

@ -34,8 +34,8 @@ static const char rcsid[] =
#include <unistd.h>
static void sanity_check(void);
static void make_dist(char *, char *, char *, Package *);
static int create_from_installed(char *, char *);
static void make_dist(const char *, const char *, const char *, Package *);
static int create_from_installed(const char *, const char *);
static char *home;
@ -47,7 +47,7 @@ pkg_perform(char **pkgs)
FILE *pkg_in, *fp;
Package plist;
int len;
char *suf;
const char *suf;
int compress = TRUE; /* default is to compress packages */
/* Preliminary setup */
@ -258,29 +258,29 @@ pkg_perform(char **pkgs)
}
static void
make_dist(char *home, char *pkg, char *suffix, Package *plist)
make_dist(const char *homedir, const char *pkg, const char *suff, Package *plist)
{
char tball[FILENAME_MAX];
PackingList p;
int ret;
char *args[50]; /* Much more than enough. */
const char *args[50]; /* Much more than enough. */
int nargs = 0;
int pipefds[2];
FILE *totar;
pid_t pid;
char *cname;
const char *cname;
args[nargs++] = "tar"; /* argv[0] */
if (*pkg == '/')
snprintf(tball, FILENAME_MAX, "%s.%s", pkg, suffix);
snprintf(tball, FILENAME_MAX, "%s.%s", pkg, suff);
else
snprintf(tball, FILENAME_MAX, "%s/%s.%s", home, pkg, suffix);
snprintf(tball, FILENAME_MAX, "%s/%s.%s", homedir, pkg, suff);
args[nargs++] = "-c";
args[nargs++] = "-f";
args[nargs++] = tball;
if (strchr(suffix, 'z')) { /* Compress/gzip/bzip2? */
if (strchr(suff, 'z')) { /* Compress/gzip/bzip2? */
if (UseBzip2) {
args[nargs++] = "-y";
cname = "bzip'd ";
@ -318,7 +318,7 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist)
dup2(pipefds[0], 0);
close(pipefds[0]);
close(pipefds[1]);
execv("/usr/bin/tar", args);
execv("/usr/bin/tar", (char * const *)(uintptr_t)args);
cleanup(0);
errx(2, __FUNCTION__ ": failed to execute tar command");
}
@ -400,18 +400,18 @@ cleanup(int sig)
}
static int
create_from_installed(char *pkg, char *suf)
create_from_installed(const char *pkg, const char *suf)
{
FILE *fp;
Package plist;
char home[MAXPATHLEN], log_dir[FILENAME_MAX];
char homedir[MAXPATHLEN], log_dir[FILENAME_MAX];
snprintf(log_dir, sizeof(log_dir), "%s/%s", LOG_DIR, InstalledPkg);
if (!fexists(log_dir)) {
warnx("can't find package '%s' installed!", InstalledPkg);
return 1;
}
getcwd(home, sizeof(home));
getcwd(homedir, sizeof(homedir));
if (chdir(log_dir) == FAIL) {
warnx("can't change directory to '%s'!", log_dir);
return 1;
@ -427,7 +427,7 @@ create_from_installed(char *pkg, char *suf)
read_plist(&plist, fp);
fclose(fp);
make_dist(home, pkg, suf, &plist);
make_dist(homedir, pkg, suf, &plist);
free_plist(&plist);
return TRUE;

View File

@ -31,10 +31,10 @@ static const char rcsid[] =
/* Check a list for files that require preconversion */
void
check_list(char *home, Package *pkg)
check_list(const char *home, Package *pkg)
{
char *where = home;
char *there = NULL;
const char *where = home;
const char *there = NULL;
char *cp, name[FILENAME_MAX], buf[33];
PackingList p;
@ -86,9 +86,9 @@ trylink(const char *from, const char *to)
}
#define STARTSTRING "tar cf -"
#define TOOBIG(str) strlen(str) + 6 + strlen(home) + where_count > maxargs
#define TOOBIG(str) (int)strlen(str) + 6 + (int)strlen(home) + where_count > maxargs
#define PUSHOUT() /* push out string */ \
if (where_count > sizeof(STARTSTRING)-1) { \
if (where_count > (int)sizeof(STARTSTRING)-1) { \
strcat(where_args, "|tar xpf -"); \
if (system(where_args)) { \
cleanup(0); \
@ -105,12 +105,13 @@ trylink(const char *from, const char *to)
* have already been copied in an earlier pass through the list.
*/
void
copy_plist(char *home, Package *plist)
copy_plist(const char *home, Package *plist)
{
PackingList p = plist->head;
char *where = home;
char *there = NULL, *mythere;
char *where_args, *last_chdir, *root = "/";
const char *where = home;
const char *there = NULL, *mythere;
char *where_args;
const char *last_chdir, *root = "/";
int maxargs, where_count = 0, add_count;
struct stat stb;
dev_t curdir;

View File

@ -5,6 +5,8 @@ SRCS= main.c perform.c
CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib
WARNS?= 2
DPADD= ${LIBINSTALL} ${LIBFETCH} ${LIBMD}
LDADD= ${LIBINSTALL} -lfetch -lmd

View File

@ -47,7 +47,7 @@ main(int argc, char **argv)
int ch, error;
char **pkgs, **start;
char *pkgs_split;
char *tmp;
const char *tmp;
struct stat stat_s;
pkgs = start = argv;

View File

@ -5,6 +5,8 @@ SRCS= main.c perform.c show.c
CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib
WARNS?= 2
DPADD= ${LIBINSTALL} ${LIBFETCH} ${LIBMD}
LDADD= ${LIBINSTALL} -lfetch -lmd

View File

@ -65,12 +65,12 @@ extern char *CheckPkg;
extern match_t MatchType;
extern struct which_head *whead;
extern void show_file(char *, char *);
extern void show_plist(char *, Package *, plist_t);
extern void show_files(char *, Package *);
extern void show_index(char *, char *);
extern void show_size(char *, Package *);
extern void show_cksum(char *, Package *);
extern void show_origin(char *, Package *);
extern void show_file(const char *, const char *);
extern void show_plist(const char *, Package *, plist_t, Boolean);
extern void show_files(const char *, Package *);
extern void show_index(const char *, const char *);
extern void show_size(const char *, Package *);
extern void show_cksum(const char *, Package *);
extern void show_origin(const char *, Package *);
#endif /* _INST_INFO_H_INCLUDE */

View File

@ -33,7 +33,7 @@ static char Options[] = "acdDe:fgGhiIkl:LmopqrRst:vW:x";
int Flags = 0;
match_t MatchType = MATCH_GLOB;
Boolean Quiet = FALSE;
char *InfoPrefix = "";
char *InfoPrefix = (char *)(uintptr_t)"";
char PlayPen[FILENAME_MAX];
char *CheckPkg = NULL;
struct which_head *whead;

View File

@ -29,14 +29,15 @@ static const char rcsid[] =
#include <signal.h>
static int pkg_do(char *);
static int find_pkg(char *, struct which_head *);
static int find_pkg(const char *, struct which_head *);
static int cmp_path(const char *, const char *, const char *);
static char *abspath(const char *);
int
pkg_perform(char **pkgs)
{
char **matched;
char *tmp;
const char *tmp;
int err_cnt = 0;
int i, errcode;
@ -184,7 +185,7 @@ pkg_do(char *pkg)
if (Flags & SHOW_COMMENT)
show_file("Comment:\n", COMMENT_FNAME);
if (Flags & SHOW_REQUIRE)
show_plist("Depends on:\n", &plist, PLIST_PKGDEP);
show_plist("Depends on:\n", &plist, PLIST_PKGDEP, FALSE);
if ((Flags & SHOW_REQBY) && !isemptyfile(REQUIRED_BY_FNAME))
show_file("Required by:\n", REQUIRED_BY_FNAME);
if (Flags & SHOW_DESC)
@ -192,7 +193,7 @@ pkg_do(char *pkg)
if ((Flags & SHOW_DISPLAY) && fexists(DISPLAY_FNAME))
show_file("Install notice:\n", DISPLAY_FNAME);
if (Flags & SHOW_PLIST)
show_plist("Packing list:\n", &plist, (plist_t)-1);
show_plist("Packing list:\n", &plist, (plist_t)0, TRUE);
if ((Flags & SHOW_INSTALL) && fexists(INSTALL_FNAME))
show_file("Install script:\n", INSTALL_FNAME);
if ((Flags & SHOW_INSTALL) && fexists(POST_INSTALL_FNAME))
@ -204,7 +205,7 @@ pkg_do(char *pkg)
if ((Flags & SHOW_MTREE) && fexists(MTREE_FNAME))
show_file("mtree file:\n", MTREE_FNAME);
if (Flags & SHOW_PREFIX)
show_plist("Prefix(s):\n", &plist, PLIST_CWD);
show_plist("Prefix(s):\n", &plist, PLIST_CWD, FALSE);
if (Flags & SHOW_FILES)
show_files("Files:\n", &plist);
if ((Flags & SHOW_SIZE) && installed)
@ -242,7 +243,7 @@ cleanup(int sig)
* /'s, as realpath() would, but without resolving symlinks, because that can
* potentially screw up our comparisons later.
*/
char *
static char *
abspath(const char *pathname)
{
char *tmp, *tmp1, *resolved_path;
@ -316,14 +317,14 @@ cmp_path(const char *target, const char *current, const char *cwd)
* packages installed the files in which_list.
*/
static int
find_pkg(char *db_dir, struct which_head *which_list)
find_pkg(const char *db_dir, struct which_head *which_list)
{
char **installed;
int errcode, i;
struct which_entry *wp;
TAILQ_FOREACH(wp, which_list, next) {
char *msg = "file cannot be found";
const char *msg = "file cannot be found";
char *tmp;
wp->skip = TRUE;

View File

@ -32,7 +32,7 @@ static const char rcsid[] =
#include <md5.h>
void
show_file(char *title, char *fname)
show_file(const char *title, const char *fname)
{
FILE *fp;
char line[1024];
@ -52,7 +52,7 @@ show_file(char *title, char *fname)
}
void
show_index(char *title, char *fname)
show_index(const char *title, const char *fname)
{
FILE *fp;
char line[MAXINDEXSIZE+2];
@ -73,9 +73,9 @@ show_index(char *title, char *fname)
fclose(fp);
}
/* Show a packing list item type. If type is -1, show all */
/* Show a packing list item type. If showall is TRUE, show all */
void
show_plist(char *title, Package *plist, plist_t type)
show_plist(const char *title, Package *plist, plist_t type, Boolean showall)
{
PackingList p;
Boolean ign = FALSE;
@ -84,7 +84,7 @@ show_plist(char *title, Package *plist, plist_t type)
printf("%s%s", InfoPrefix, title);
p = plist->head;
while (p) {
if (p->type != type && type != -1) {
if (p->type != type && showall != TRUE) {
p = p->next;
continue;
}
@ -180,11 +180,11 @@ show_plist(char *title, Package *plist, plist_t type)
/* Show all files in the packing list (except ignored ones) */
void
show_files(char *title, Package *plist)
show_files(const char *title, Package *plist)
{
PackingList p;
Boolean ign = FALSE;
char *dir = ".";
const char *dir = ".";
if (!Quiet)
printf("%s%s", InfoPrefix, title);
@ -215,11 +215,11 @@ show_files(char *title, Package *plist)
/* Calculate and show size of all installed package files (except ignored ones) */
void
show_size(char *title, Package *plist)
show_size(const char *title, Package *plist)
{
PackingList p;
Boolean ign = FALSE;
char *dir = ".";
const char *dir = ".";
struct stat sb;
char tmp[FILENAME_MAX];
unsigned long size = 0;
@ -265,10 +265,10 @@ show_size(char *title, Package *plist)
/* Show files that don't match the recorded checksum */
void
show_cksum(char *title, Package *plist)
show_cksum(const char *title, Package *plist)
{
PackingList p;
char *dir = ".";
const char *dir = ".";
char tmp[FILENAME_MAX];
if (!Quiet)
@ -295,7 +295,7 @@ show_cksum(char *title, Package *plist)
/* Show an "origin" path (usually category/portname) */
void
show_origin(char *title, Package *plist)
show_origin(const char *title, Package *plist)
{
PackingList p;

View File

@ -7,6 +7,8 @@ SRCS= file.c msg.c plist.c str.c exec.c global.c pen.c match.c deps.c
CFLAGS+= ${DEBUG}
WARNS?= 2
install:
@echo -n

View File

@ -80,7 +80,7 @@ sortdeps(char **pkgs)
* Returns 1 if depends, 0 if not, and -1 if error occured.
*/
int
chkifdepends(char *pkgname1, char *pkgname2)
chkifdepends(const char *pkgname1, const char *pkgname2)
{
char pkgdir[FILENAME_MAX];
int errcode;

View File

@ -106,4 +106,3 @@ vpipe(const char *fmt, ...)
}
return rp;
}

View File

@ -32,7 +32,7 @@ static const char rcsid[] =
/* Quick check to see if a file exists */
Boolean
fexists(char *fname)
fexists(const char *fname)
{
struct stat dummy;
if (!lstat(fname, &dummy))
@ -42,7 +42,7 @@ fexists(char *fname)
/* Quick check to see if something is a directory or symlink to a directory */
Boolean
isdir(char *fname)
isdir(const char *fname)
{
struct stat sb;
@ -56,7 +56,7 @@ isdir(char *fname)
/* Check to see if file is a dir or symlink to a dir, and is empty */
Boolean
isemptydir(char *fname)
isemptydir(const char *fname)
{
if (isdir(fname)) {
DIR *dirp;
@ -82,7 +82,7 @@ isemptydir(char *fname)
* file
*/
Boolean
isfile(char *fname)
isfile(const char *fname)
{
struct stat sb;
if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode))
@ -96,7 +96,7 @@ isfile(char *fname)
* zero sized.
*/
Boolean
isemptyfile(char *fname)
isemptyfile(const char *fname)
{
struct stat sb;
if (stat(fname, &sb) != FAIL && S_ISREG(sb.st_mode)) {
@ -108,7 +108,7 @@ isemptyfile(char *fname)
/* Returns TRUE if file is a symbolic link. */
Boolean
issymlink(char *fname)
issymlink(const char *fname)
{
struct stat sb;
if (lstat(fname, &sb) != FAIL && S_ISLNK(sb.st_mode))
@ -118,7 +118,7 @@ issymlink(char *fname)
/* Returns TRUE if file is a URL specification */
Boolean
isURL(char *fname)
isURL(const char *fname)
{
/*
* I'm sure there are other types of URL specifications that I could
@ -140,7 +140,7 @@ isURL(char *fname)
* it's unpacked, if successful.
*/
char *
fileGetURL(char *base, char *spec)
fileGetURL(const char *base, const char *spec)
{
char *cp, *rp;
char fname[FILENAME_MAX];
@ -148,8 +148,7 @@ fileGetURL(char *base, char *spec)
char buf[8192];
FILE *ftp;
pid_t tpid;
int pfd[2], pstat;
size_t r, w;
int pfd[2], pstat, r, w;
char *hint;
int fd;
@ -236,10 +235,10 @@ fileGetURL(char *base, char *spec)
if ((w = write(pfd[1], buf, r)) != r)
break;
}
if (ferror(ftp))
warn("warning: error reading from server");
fclose(ftp);
close(pfd[1]);
if (r == -1)
warn("warning: error reading from server");
if (w == -1)
warn("warning: error writing to tar");
tpid = waitpid(tpid, &pstat, 0);
@ -251,11 +250,11 @@ fileGetURL(char *base, char *spec)
}
char *
fileFindByPath(char *base, char *fname)
fileFindByPath(const char *base, const char *fname)
{
static char tmp[FILENAME_MAX];
char *cp;
char *suffixes[] = {".tgz", ".tar", ".tbz2", NULL};
const char *suffixes[] = {".tgz", ".tar", ".tbz2", NULL};
int i;
if (fexists(fname) && isfile(fname)) {
@ -295,7 +294,7 @@ fileFindByPath(char *base, char *fname)
}
char *
fileGetContents(char *fname)
fileGetContents(const char *fname)
{
char *contents;
struct stat sb;
@ -315,7 +314,7 @@ fileGetContents(char *fname)
if (read(fd, contents, sb.st_size) != sb.st_size) {
cleanup(0);
errx(2, __FUNCTION__ ": short read on '%s' - did not get %qd bytes",
fname, sb.st_size);
fname, (long long)sb.st_size);
}
close(fd);
contents[sb.st_size] = '\0';
@ -327,7 +326,7 @@ fileGetContents(char *fname)
* canonical "preserve" name for it.
*/
Boolean
make_preserve_name(char *try, int max, char *name, char *file)
make_preserve_name(char *try, int max, const char *name, const char *file)
{
int len, i;
@ -359,10 +358,10 @@ make_preserve_name(char *try, int max, char *name, char *file)
/* Write the contents of "str" to a file */
void
write_file(char *name, char *str)
write_file(const char *name, const char *str)
{
FILE *fp;
int len;
size_t len;
fp = fopen(name, "w");
if (!fp) {
@ -372,7 +371,7 @@ write_file(char *name, char *str)
len = strlen(str);
if (fwrite(str, 1, len, fp) != len) {
cleanup(0);
errx(2, __FUNCTION__ ": short fwrite on '%s', tried to write %d bytes", name, len);
errx(2, __FUNCTION__ ": short fwrite on '%s', tried to write %ld bytes", name, (long)len);
}
if (fclose(fp)) {
cleanup(0);
@ -381,7 +380,7 @@ write_file(char *name, char *str)
}
void
copy_file(char *dir, char *fname, char *to)
copy_file(const char *dir, const char *fname, const char *to)
{
char cmd[FILENAME_MAX];
@ -396,7 +395,7 @@ copy_file(char *dir, char *fname, char *to)
}
void
move_file(char *dir, char *fname, char *to)
move_file(const char *dir, const char *fname, const char *to)
{
char cmd[FILENAME_MAX];
@ -419,7 +418,7 @@ move_file(char *dir, char *fname, char *to)
* without me having to write some big hairy routine to do it.
*/
void
copy_hierarchy(char *dir, char *fname, Boolean to)
copy_hierarchy(const char *dir, const char *fname, Boolean to)
{
char cmd[FILENAME_MAX * 3];
@ -444,9 +443,9 @@ copy_hierarchy(char *dir, char *fname, Boolean to)
/* Unpack a tar file */
int
unpack(char *pkg, char *flist)
unpack(const char *pkg, const char *flist)
{
char args[10], suffix[80], *cp;
char args[10], suff[80], *cp;
args[0] = '\0';
/*
@ -456,9 +455,9 @@ unpack(char *pkg, char *flist)
if (strcmp(pkg, "-")) {
cp = strrchr(pkg, '.');
if (cp) {
strcpy(suffix, cp + 1);
if (strchr(suffix, 'z') || strchr(suffix, 'Z')) {
if (strchr(suffix, 'b'))
strcpy(suff, cp + 1);
if (strchr(suff, 'z') || strchr(suff, 'Z')) {
if (strchr(suff, 'b'))
strcpy(args, "-y");
else
strcpy(args, "-z");
@ -487,7 +486,7 @@ unpack(char *pkg, char *flist)
*
*/
void
format_cmd(char *buf, char *fmt, char *dir, char *name)
format_cmd(char *buf, const char *fmt, const char *dir, const char *name)
{
char *cp, scratch[FILENAME_MAX * 2];

View File

@ -123,39 +123,39 @@ STAILQ_HEAD(reqr_by_head, reqr_by_entry);
int vsystem(const char *, ...);
char *vpipe(const char *, ...);
void cleanup(int);
char *make_playpen(char *, size_t);
char *make_playpen(char *, off_t);
char *where_playpen(void);
void leave_playpen(void);
off_t min_free(char *);
off_t min_free(const char *);
/* String */
char *get_dash_string(char **);
char *copy_string(char *);
Boolean suffix(char *, char *);
char *copy_string(const char *);
Boolean suffix(const char *, const char *);
void nuke_suffix(char *);
void str_lowercase(char *);
char *strconcat(char *, char *);
char *strconcat(const char *, const char *);
char *get_string(char *, int, FILE *);
/* File */
Boolean fexists(char *);
Boolean isdir(char *);
Boolean isemptydir(char *fname);
Boolean isemptyfile(char *fname);
Boolean isfile(char *);
Boolean isempty(char *);
Boolean issymlink(char *);
Boolean isURL(char *);
char *fileGetURL(char *, char *);
char *fileFindByPath(char *, char *);
char *fileGetContents(char *);
void write_file(char *, char *);
void copy_file(char *, char *, char *);
void move_file(char *, char *, char *);
void copy_hierarchy(char *, char *, Boolean);
int delete_hierarchy(char *, Boolean, Boolean);
int unpack(char *, char *);
void format_cmd(char *, char *, char *, char *);
Boolean fexists(const char *);
Boolean isdir(const char *);
Boolean isemptydir(const char *fname);
Boolean isemptyfile(const char *fname);
Boolean isfile(const char *);
Boolean isempty(const char *);
Boolean issymlink(const char *);
Boolean isURL(const char *);
char *fileGetURL(const char *, const char *);
char *fileFindByPath(const char *, const char *);
char *fileGetContents(const char *);
void write_file(const char *, const char *);
void copy_file(const char *, const char *, const char *);
void move_file(const char *, const char *, const char *);
void copy_hierarchy(const char *, const char *, Boolean);
int delete_hierarchy(const char *, Boolean, Boolean);
int unpack(const char *, const char *);
void format_cmd(char *, const char *, const char *, const char *);
/* Msg */
void upchuck(const char *);
@ -167,19 +167,19 @@ Boolean y_or_n(Boolean, const char *, ...);
PackingList new_plist_entry(void);
PackingList last_plist(Package *);
PackingList find_plist(Package *, plist_t);
char *find_plist_option(Package *, char *name);
void plist_delete(Package *, Boolean, plist_t, char *);
char *find_plist_option(Package *, const char *name);
void plist_delete(Package *, Boolean, plist_t, const char *);
void free_plist(Package *);
void mark_plist(Package *);
void csum_plist_entry(char *, PackingList);
void add_plist(Package *, plist_t, char *);
void add_plist_top(Package *, plist_t, char *);
void delete_plist(Package *pkg, Boolean all, plist_t type, char *name);
void add_plist(Package *, plist_t, const char *);
void add_plist_top(Package *, plist_t, const char *);
void delete_plist(Package *pkg, Boolean all, plist_t type, const char *name);
void write_plist(Package *, FILE *);
void read_plist(Package *, FILE *);
int plist_cmd(char *, char **);
int plist_cmd(const char *, char **);
int delete_package(Boolean, Boolean, Package *);
Boolean make_preserve_name(char *, int, char *, char *);
Boolean make_preserve_name(char *, int, const char *, const char *);
/* For all */
int pkg_perform(char **);
@ -189,7 +189,7 @@ char **matchinstalled(match_t, char **, int *);
/* Dependencies */
int sortdeps(char **);
int chkifdepends(char *, char *);
int chkifdepends(const char *, const char *);
int requiredby(const char *, struct reqr_by_head **, Boolean, Boolean);
/* Externs */

View File

@ -39,7 +39,7 @@ struct store {
char **store;
};
static int rex_match(char *, char *);
static int rex_match(const char *, const char *);
static int storeappend(struct store *, const char *);
static int fname_cmp(const FTSENT **, const FTSENT **);
@ -58,8 +58,8 @@ char **
matchinstalled(match_t MatchType, char **patterns, int *retval)
{
int i, errcode, len;
char *tmp, *matched;
char *paths[2];
char *matched;
const char *paths[2] = {LOG_DIR, NULL};
static struct store *store = NULL;
FTS *ftsp;
FTSENT *f;
@ -85,8 +85,7 @@ matchinstalled(match_t MatchType, char **patterns, int *retval)
if (retval != NULL)
*retval = 0;
tmp = LOG_DIR;
if (!isdir(tmp)) {
if (!isdir(paths[0])) {
if (retval != NULL)
*retval = 1;
return NULL;
@ -109,9 +108,7 @@ matchinstalled(match_t MatchType, char **patterns, int *retval)
for (i = 0; i < len; i++)
lmatched[i] = FALSE;
paths[0] = tmp;
paths[1] = NULL;
ftsp = fts_open(paths, FTS_LOGICAL | FTS_NOCHDIR | FTS_NOSTAT, fname_cmp);
ftsp = fts_open((char * const *)(uintptr_t)paths, FTS_LOGICAL | FTS_NOCHDIR | FTS_NOSTAT, fname_cmp);
if (ftsp != NULL) {
while ((f = fts_read(ftsp)) != NULL) {
if (f->fts_info == FTS_D && f->fts_level == 1) {
@ -173,7 +170,7 @@ matchinstalled(match_t MatchType, char **patterns, int *retval)
* engine reported an error (usually invalid syntax).
*/
static int
rex_match(char *pattern, char *pkgname)
rex_match(const char *pattern, const char *pkgname)
{
char errbuf[128];
int errcode;

View File

@ -30,10 +30,10 @@ static const char rcsid[] =
/* Die a relatively simple death */
void
upchuck(const char *err)
upchuck(const char *message)
{
cleanup(0);
errx(1, "fatal error during execution: %s", err);
errx(1, "fatal error during execution: %s", message);
}
/*

View File

@ -41,7 +41,7 @@ where_playpen(void)
/* Find a good place to play. */
static char *
find_play_pen(char *pen, size_t sz)
find_play_pen(char *pen, off_t sz)
{
char *cp;
struct stat sb;
@ -62,8 +62,8 @@ find_play_pen(char *pen, size_t sz)
cleanup(0);
errx(2, __FUNCTION__
": can't find enough temporary space to extract the files, please set your\n"
"PKG_TMPDIR environment variable to a location with at least %d bytes\n"
"free", sz);
"PKG_TMPDIR environment variable to a location with at least %ld bytes\n"
"free", (long)sz);
return NULL;
}
return pen;
@ -74,7 +74,7 @@ static char *pstack[MAX_STACK];
static int pdepth = -1;
static void
pushPen(char *pen)
pushPen(const char *pen)
{
if (++pdepth == MAX_STACK)
errx(2, __FUNCTION__ ": stack overflow.\n");
@ -97,7 +97,7 @@ popPen(char *pen)
* pathname of previous working directory.
*/
char *
make_playpen(char *pen, size_t sz)
make_playpen(char *pen, off_t sz)
{
if (!find_play_pen(pen, sz))
return NULL;
@ -113,7 +113,7 @@ make_playpen(char *pen, size_t sz)
if (Verbose) {
if (sz)
fprintf(stderr, "Requested space: %d bytes, free space: %qd bytes in %s\n", (int)sz, min_free(pen), pen);
fprintf(stderr, "Requested space: %d bytes, free space: %qd bytes in %s\n", (int)sz, (long long)min_free(pen), pen);
}
if (min_free(pen) < sz) {
@ -165,7 +165,7 @@ leave_playpen()
}
off_t
min_free(char *tmpdir)
min_free(const char *tmpdir)
{
struct statfs buf;

View File

@ -29,7 +29,7 @@ static const char rcsid[] =
/* Add an item to a packing list */
void
add_plist(Package *p, plist_t type, char *arg)
add_plist(Package *p, plist_t type, const char *arg)
{
PackingList tmp;
@ -47,7 +47,7 @@ add_plist(Package *p, plist_t type, char *arg)
}
void
add_plist_top(Package *p, plist_t type, char *arg)
add_plist_top(Package *p, plist_t type, const char *arg)
{
PackingList tmp;
@ -99,7 +99,7 @@ find_plist(Package *pkg, plist_t type)
/* Look for a specific boolean option argument in the list */
char *
find_plist_option(Package *pkg, char *name)
find_plist_option(Package *pkg, const char *name)
{
PackingList p = pkg->head;
@ -116,7 +116,7 @@ find_plist_option(Package *pkg, char *name)
* too.) If 'all' is set, delete all items, not just the first occurance.
*/
void
delete_plist(Package *pkg, Boolean all, plist_t type, char *name)
delete_plist(Package *pkg, Boolean all, plist_t type, const char *name)
{
PackingList p = pkg->head;
@ -175,10 +175,11 @@ free_plist(Package *pkg)
* optionally its argument(s)
*/
int
plist_cmd(char *s, char **arg)
plist_cmd(const char *s, char **arg)
{
char cmd[FILENAME_MAX + 20]; /* 20 == fudge for max cmd len */
char *cp, *sp;
char *cp;
const char *sp;
strcpy(cmd, s);
str_lowercase(cmd);
@ -194,7 +195,7 @@ plist_cmd(char *s, char **arg)
++cp, ++sp;
}
if (arg)
*arg = sp;
(const char *)*arg = sp;
if (!strcmp(cmd, "cwd"))
return PLIST_CWD;
else if (!strcmp(cmd, "srcdir"))
@ -355,7 +356,7 @@ int
delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
{
PackingList p;
char *Where = ".", *last_file = "";
const char *Where = ".", *last_file = "";
Boolean fail = SUCCESS;
Boolean preserve;
char tmp[FILENAME_MAX], *name = NULL;
@ -464,11 +465,11 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
/* Selectively delete a hierarchy */
int
delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
delete_hierarchy(const char *dir, Boolean ign_err, Boolean nukedirs)
{
char *cp1, *cp2;
cp1 = cp2 = dir;
cp1 = cp2 = strdup(dir);
if (!fexists(dir)) {
if (!ign_err)
warnx("%s '%s' doesn't really exist",
@ -503,7 +504,7 @@ delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
}
/* back up the pathname one component */
if (cp2) {
cp1 = dir;
cp1 = strdup(dir);
}
}
return 0;

View File

@ -26,7 +26,7 @@ static const char rcsid[] =
#include "lib.h"
char *
strconcat(char *s1, char *s2)
strconcat(const char *s1, const char *s2)
{
static char tmp[FILENAME_MAX];
@ -52,14 +52,14 @@ get_dash_string(char **str)
/* Rather Obvious */
char *
copy_string(char *str)
copy_string(const char *str)
{
return (str ? strdup(str) : NULL);
}
/* Return TRUE if 'str' ends in suffix 'suff' */
Boolean
suffix(char *str, char *suff)
suffix(const char *str, const char *suff)
{
char *idx;
Boolean ret = FALSE;