Cause fatal error messages to be a little more helpful to the programmer

concerning where they're taking place.

Switch from [r]index() to str[r]chr() functions, which are more ISO
compliant.

Prompted by:	Edward Welbourne <eddy@vortigen.demon.co.uk>
This commit is contained in:
Jordan K. Hubbard 2000-10-22 09:53:27 +00:00
parent f38211c796
commit aed4d2d137
12 changed files with 58 additions and 58 deletions

View File

@ -38,7 +38,7 @@ static const char rcsid[] =
strcat(where_args, todir); \
if (system(where_args)) { \
cleanup(0); \
errx(2, "can not invoke %d byte tar pipeline: %s", \
errx(2, __FUNCTION__ ": can not invoke %d byte tar pipeline: %s", \
strlen(where_args), where_args); \
} \
strcpy(where_args, STARTSTRING); \
@ -89,12 +89,12 @@ extract_plist(char *home, Package *pkg)
where_args = alloca(maxargs);
if (!where_args) {
cleanup(0);
errx(2, "can't get argument list space");
errx(2, __FUNCTION__ ": can't get argument list space");
}
perm_args = alloca(maxargs);
if (!perm_args) {
cleanup(0);
errx(2, "can't get argument list space");
errx(2, __FUNCTION__ ": can't get argument list space");
}
strcpy(where_args, STARTSTRING);
@ -131,7 +131,7 @@ extract_plist(char *home, Package *pkg)
if (strrchr(p->name,'\'')) {
cleanup(0);
errx(2, "Bogus filename \"%s\"", p->name);
errx(2, __FUNCTION__ ": Bogus filename \"%s\"", p->name);
}
/* first try to rename it into place */
@ -160,7 +160,7 @@ extract_plist(char *home, Package *pkg)
add_count = snprintf(&perm_args[perm_count], maxargs - perm_count, "'%s' ", p->name);
if (add_count > maxargs - perm_count) {
cleanup(0);
errx(2, "oops, miscounted strings!");
errx(2, __FUNCTION__ ": oops, miscounted strings!");
}
perm_count += add_count;
}
@ -180,7 +180,7 @@ extract_plist(char *home, Package *pkg)
add_count = snprintf(&where_args[where_count], maxargs - where_count, " '%s'", p->name);
if (add_count > maxargs - where_count) {
cleanup(0);
errx(2, "oops, miscounted strings!");
errx(2, __FUNCTION__ ": oops, miscounted strings!");
}
where_count += add_count;
add_count = snprintf(&perm_args[perm_count],
@ -188,7 +188,7 @@ extract_plist(char *home, Package *pkg)
"'%s' ", p->name);
if (add_count > maxargs - perm_count) {
cleanup(0);
errx(2, "oops, miscounted strings!");
errx(2, __FUNCTION__ ": oops, miscounted strings!");
}
perm_count += add_count;
}
@ -202,7 +202,7 @@ extract_plist(char *home, Package *pkg)
if (strcmp(p->name, ".")) {
if (!Fake && make_hierarchy(p->name) == FAIL) {
cleanup(0);
errx(2, "unable to cwd to '%s'", p->name);
errx(2, __FUNCTION__ ": unable to cwd to '%s'", p->name);
}
Directory = p->name;
}
@ -214,11 +214,11 @@ extract_plist(char *home, Package *pkg)
if ((strstr(p->name, "%B") || strstr(p->name, "%F") ||
strstr(p->name, "%f")) && last_file == NULL) {
cleanup(0);
errx(2, "no last file specified for '%s' command", p->name);
errx(2, __FUNCTION__ ": no last file specified for '%s' command", p->name);
}
if (strstr(p->name, "%D") && Directory == NULL) {
cleanup(0);
errx(2, "no directory specified for '%s' command", p->name);
errx(2, __FUNCTION__ ": no directory specified for '%s' command", p->name);
}
format_cmd(cmd, p->name, Directory, last_file);
PUSHOUT(Directory);

View File

@ -42,7 +42,7 @@ make_hierarchy(char *dir)
else
cp1 = cp2 = dir;
while (cp2) {
if ((cp2 = index(cp1, '/')) !=NULL )
if ((cp2 = strchr(cp1, '/')) !=NULL )
*cp2 = '\0';
if (fexists(dir)) {
if (!isdir(dir)) {

View File

@ -60,7 +60,7 @@ pkg_perform(char **pkgs)
pkg_in = fopen(Contents, "r");
if (!pkg_in) {
cleanup(0);
errx(2, "unable to open contents file '%s' for input", Contents);
errx(2, __FUNCTION__ ": unable to open contents file '%s' for input", Contents);
}
}
plist.head = plist.tail = NULL;
@ -194,12 +194,12 @@ pkg_perform(char **pkgs)
fp = fopen(CONTENTS_FNAME, "w");
if (!fp) {
cleanup(0);
errx(2, "can't open file %s for writing", CONTENTS_FNAME);
errx(2, __FUNCTION__ ": can't open file %s for writing", CONTENTS_FNAME);
}
write_plist(&plist, fp);
if (fclose(fp)) {
cleanup(0);
errx(2, "error while closing %s", CONTENTS_FNAME);
errx(2, __FUNCTION__ ": error while closing %s", CONTENTS_FNAME);
}
/* And stick it into a tar ball */
@ -235,7 +235,7 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist)
args[nargs++] = "-c";
args[nargs++] = "-f";
args[nargs++] = tball;
if (index(suffix, 'z')) /* Compress/gzip? */
if (strchr(suffix, 'z')) /* Compress/gzip? */
args[nargs++] = "-z";
if (Dereference)
args[nargs++] = "-h";
@ -253,11 +253,11 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist)
/* Set up a pipe for passing the filenames, and fork off a tar process. */
if (pipe(pipefds) == -1) {
cleanup(0);
errx(2, "cannot create pipe");
errx(2, __FUNCTION__ ": cannot create pipe");
}
if ((pid = fork()) == -1) {
cleanup(0);
errx(2, "cannot fork process for tar");
errx(2, __FUNCTION__ ": cannot fork process for tar");
}
if (pid == 0) { /* The child */
dup2(pipefds[0], 0);
@ -265,14 +265,14 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist)
close(pipefds[1]);
execv("/usr/bin/tar", args);
cleanup(0);
errx(2, "failed to execute tar command");
errx(2, __FUNCTION__ ": failed to execute tar command");
}
/* Meanwhile, back in the parent process ... */
close(pipefds[0]);
if ((totar = fdopen(pipefds[1], "w")) == NULL) {
cleanup(0);
errx(2, "fdopen failed");
errx(2, __FUNCTION__ ": fdopen failed");
}
fprintf(totar, "%s\n", CONTENTS_FNAME);
@ -308,7 +308,7 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist)
/* assume either signal or bad exit is enough for us */
if (ret) {
cleanup(0);
errx(2, "tar command failed with code %d", ret);
errx(2, __FUNCTION__ ": tar command failed with code %d", ret);
}
}
@ -317,15 +317,15 @@ sanity_check()
{
if (!Comment) {
cleanup(0);
errx(2, "required package comment string is missing (-c comment)");
errx(2, __FUNCTION__ ": required package comment string is missing (-c comment)");
}
if (!Desc) {
cleanup(0);
errx(2, "required package description string is missing (-d desc)");
errx(2, __FUNCTION__ ": required package description string is missing (-d desc)");
}
if (!Contents) {
cleanup(0);
errx(2, "required package contents list is missing (-f [-]file)");
errx(2, __FUNCTION__ ": required package contents list is missing (-f [-]file)");
}
}

View File

@ -87,7 +87,7 @@ trylink(const char *from, const char *to)
strcat(where_args, "|tar xpf -"); \
if (system(where_args)) { \
cleanup(0); \
errx(2, "can't invoke tar pipeline"); \
errx(2, __FUNCTION__ ": can't invoke tar pipeline"); \
} \
memset(where_args, 0, maxargs); \
last_chdir = NULL; \
@ -116,7 +116,7 @@ copy_plist(char *home, Package *plist)
where_args = malloc(maxargs);
if (!where_args) {
cleanup(0);
errx(2, "can't get argument list space");
errx(2, __FUNCTION__ ": can't get argument list space");
}
memset(where_args, 0, maxargs);
@ -179,7 +179,7 @@ copy_plist(char *home, Package *plist)
}
if (add_count > maxargs - where_count) {
cleanup(0);
errx(2, "oops, miscounted strings!");
errx(2, __FUNCTION__ ": oops, miscounted strings!");
}
where_count += add_count;
}
@ -215,7 +215,7 @@ copy_plist(char *home, Package *plist)
p->name);
if (add_count > maxargs - where_count) {
cleanup(0);
errx(2, "oops, miscounted strings!");
errx(2, __FUNCTION__ ": oops, miscounted strings!");
}
where_count += add_count;
last_chdir = (mythere ? mythere : where);

View File

@ -87,7 +87,7 @@ main(int argc, char **argv)
/* Get all the remaining package names, if any */
while (*argv) {
while ((pkgs_split = rindex(*argv, (int)'/')) != NULL) {
while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) {
*pkgs_split++ = '\0';
/*
* If character after the '/' is alphanumeric, then we've found the

View File

@ -79,7 +79,7 @@ pkg_do(char *pkg)
if (!getcwd(home, FILENAME_MAX)) {
cleanup(0);
errx(2, "unable to get current working directory!");
errx(2, __FUNCTION__ ": unable to get current working directory!");
}
if (chdir(LogDir) == FAIL) {
@ -169,7 +169,7 @@ pkg_do(char *pkg)
if (chdir(home) == FAIL) {
cleanup(0);
errx(2, "unable to return to working directory %s!", home);
errx(2, __FUNCTION__ ": unable to return to working directory %s!", home);
}
if (!Fake) {
@ -200,7 +200,7 @@ pkg_do(char *pkg)
if (chdir(home) == FAIL) {
cleanup(0);
errx(2, "unable to return to working directory %s!", home);
errx(2, __FUNCTION__ ": unable to return to working directory %s!", home);
}
if (!Fake) {
@ -227,7 +227,7 @@ sanity_check(char *pkg)
{
if (!fexists(CONTENTS_FNAME)) {
cleanup(0);
errx(2, "installed package %s has no %s file!", pkg, CONTENTS_FNAME);
errx(2, __FUNCTION__ ": installed package %s has no %s file!", pkg, CONTENTS_FNAME);
}
}

View File

@ -149,7 +149,7 @@ main(int argc, char **argv)
/* Get all the remaining package names, if any */
while (*argv) {
while ((pkgs_split = rindex(*argv, (int)'/')) != NULL) {
while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) {
*pkgs_split++ = '\0';
/*
* If character after the '/' is alphanumeric, then we've found the

View File

@ -165,7 +165,7 @@ show_plist(char *title, Package *plist, plist_t type)
default:
cleanup(0);
errx(2, "unknown command type %d (%s)", p->type, p->name);
errx(2, __FUNCTION__ ": unknown command type %d (%s)", p->type, p->name);
break;
}
p = p->next;

View File

@ -269,18 +269,18 @@ fileGetContents(char *fname)
if (stat(fname, &sb) == FAIL) {
cleanup(0);
errx(2, "can't stat '%s'", fname);
errx(2, __FUNCTION__ ": can't stat '%s'", fname);
}
contents = (char *)malloc(sb.st_size + 1);
fd = open(fname, O_RDONLY, 0);
if (fd == FAIL) {
cleanup(0);
errx(2, "unable to open '%s' for reading", fname);
errx(2, __FUNCTION__ ": unable to open '%s' for reading", fname);
}
if (read(fd, contents, sb.st_size) != sb.st_size) {
cleanup(0);
errx(2, "short read on '%s' - did not get %qd bytes",
errx(2, __FUNCTION__ ": short read on '%s' - did not get %qd bytes",
fname, sb.st_size);
}
close(fd);
@ -332,16 +332,16 @@ write_file(char *name, char *str)
fp = fopen(name, "w");
if (!fp) {
cleanup(0);
errx(2, "cannot fopen '%s' for writing", name);
errx(2, __FUNCTION__ ": cannot fopen '%s' for writing", name);
}
len = strlen(str);
if (fwrite(str, 1, len, fp) != len) {
cleanup(0);
errx(2, "short fwrite on '%s', tried to write %d bytes", name, len);
errx(2, __FUNCTION__ ": short fwrite on '%s', tried to write %d bytes", name, len);
}
if (fclose(fp)) {
cleanup(0);
errx(2, "failure to fclose '%s'", name);
errx(2, __FUNCTION__ ": failure to fclose '%s'", name);
}
}
@ -356,7 +356,7 @@ copy_file(char *dir, char *fname, char *to)
snprintf(cmd, FILENAME_MAX, "cp -r %s/%s %s", dir, fname, to);
if (vsystem(cmd)) {
cleanup(0);
errx(2, "could not perform '%s'", cmd);
errx(2, __FUNCTION__ ": could not perform '%s'", cmd);
}
}
@ -371,7 +371,7 @@ move_file(char *dir, char *fname, char *to)
snprintf(cmd, FILENAME_MAX, "mv %s/%s %s", dir, fname, to);
if (vsystem(cmd)) {
cleanup(0);
errx(2, "could not perform '%s'", cmd);
errx(2, __FUNCTION__ ": could not perform '%s'", cmd);
}
}
@ -403,7 +403,7 @@ copy_hierarchy(char *dir, char *fname, Boolean to)
#endif
if (system(cmd)) {
cleanup(0);
errx(2, "copy_file: could not perform '%s'", cmd);
errx(2, __FUNCTION__ ": could not perform '%s'", cmd);
}
}
@ -419,10 +419,10 @@ unpack(char *pkg, char *flist)
* compressed.
*/
if (strcmp(pkg, "-")) {
cp = rindex(pkg, '.');
cp = strrchr(pkg, '.');
if (cp) {
strcpy(suffix, cp + 1);
if (index(suffix, 'z') || index(suffix, 'Z'))
if (strchr(suffix, 'z') || strchr(suffix, 'Z'))
strcpy(args, "-z");
}
}

View File

@ -60,8 +60,8 @@ find_play_pen(char *pen, size_t sz)
strcpy(pen, "/usr/tmp/instmp.XXXXXX");
else {
cleanup(0);
errx(2,
"can't find enough temporary space to extract the files, please set your\n"
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);
return NULL;
@ -77,7 +77,7 @@ static void
pushPen(char *pen)
{
if (++pdepth == MAX_STACK)
errx(2, "stack overflow in pushPen().\n");
errx(2, __FUNCTION__ ": stack overflow.\n");
pstack[pdepth] = strdup(pen);
}
@ -104,11 +104,11 @@ make_playpen(char *pen, size_t sz)
if (!mkdtemp(pen)) {
cleanup(0);
errx(2, "can't mktemp '%s'", pen);
errx(2, __FUNCTION__ ": can't mktemp '%s'", pen);
}
if (chmod(pen, 0755) == FAIL) {
cleanup(0);
errx(2, "can't mkdir '%s'", pen);
errx(2, __FUNCTION__ ": can't mkdir '%s'", pen);
}
if (Verbose) {
@ -119,7 +119,7 @@ make_playpen(char *pen, size_t sz)
if (min_free(pen) < sz) {
rmdir(pen);
cleanup(0);
errx(2, "not enough free space to create '%s'.\n"
errx(2, __FUNCTION__ ": not enough free space to create '%s'.\n"
"Please set your PKG_TMPDIR environment variable to a location\n"
"with more space and\ntry the command again", pen);
}
@ -131,7 +131,7 @@ make_playpen(char *pen, size_t sz)
if (chdir(pen) == FAIL) {
cleanup(0);
errx(2, "can't chdir to '%s'", pen);
errx(2, __FUNCTION__ ": can't chdir to '%s'", pen);
}
if (PenLocation[0])
@ -152,7 +152,7 @@ leave_playpen()
if (Previous[0]) {
if (chdir(Previous) == FAIL) {
cleanup(0);
errx(2, "can't chdir back to '%s'", Previous);
errx(2, __FUNCTION__ ": can't chdir back to '%s'", Previous);
}
Previous[0] = '\0';
}

View File

@ -252,7 +252,7 @@ read_plist(Package *pkg, FILE *fp)
cmd = plist_cmd(pline + 1, &cp);
if (cmd == FAIL) {
cleanup(0);
errx(2, "bad command '%s'", pline);
errx(2, __FUNCTION__ ": bad command '%s'", pline);
}
if (*cp == '\0')
cp = NULL;
@ -338,7 +338,7 @@ write_plist(Package *pkg, FILE *fp)
default:
cleanup(0);
errx(2, "unknown command type %d (%s)", plist->type, plist->name);
errx(2, __FUNCTION__ ": unknown command type %d (%s)", plist->type, plist->name);
break;
}
plist = plist->next;
@ -489,7 +489,7 @@ delete_hierarchy(char *dir, Boolean ign_err, Boolean nukedirs)
if (!nukedirs)
return 0;
while (cp2) {
if ((cp2 = rindex(cp1, '/')) != NULL)
if ((cp2 = strrchr(cp1, '/')) != NULL)
*cp2 = '\0';
if (!isemptydir(dir))
return 0;

View File

@ -83,7 +83,7 @@ suffix(char *str, char *suff)
char *idx;
Boolean ret = FALSE;
idx = rindex(str, '.');
idx = strrchr(str, '.');
if (idx && !strcmp(idx + 1, suff))
ret = TRUE;
return ret;
@ -95,7 +95,7 @@ nuke_suffix(char *str)
{
char *idx;
idx = rindex(str, '.');
idx = strrchr(str, '.');
if (idx)
*idx = '\0'; /* Yow! Don't try this on a const! */
}