From cdb92ab985da815edb3ed6f156cc138ef8c69b25 Mon Sep 17 00:00:00 2001 From: jkh Date: Sun, 22 Oct 2000 09:53:27 +0000 Subject: 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 --- usr.sbin/pkg_install/lib/file.c | 22 +++++++++++----------- usr.sbin/pkg_install/lib/pen.c | 16 ++++++++-------- usr.sbin/pkg_install/lib/plist.c | 6 +++--- usr.sbin/pkg_install/lib/str.c | 4 ++-- 4 files changed, 24 insertions(+), 24 deletions(-) (limited to 'usr.sbin/pkg_install/lib') diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c index a54df9e..eebe4d2 100644 --- a/usr.sbin/pkg_install/lib/file.c +++ b/usr.sbin/pkg_install/lib/file.c @@ -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"); } } diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c index 9aad685..687d6bb 100644 --- a/usr.sbin/pkg_install/lib/pen.c +++ b/usr.sbin/pkg_install/lib/pen.c @@ -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'; } diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c index 88f6876..0e6da6e 100644 --- a/usr.sbin/pkg_install/lib/plist.c +++ b/usr.sbin/pkg_install/lib/plist.c @@ -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; diff --git a/usr.sbin/pkg_install/lib/str.c b/usr.sbin/pkg_install/lib/str.c index 815d7c1..67a5e64 100644 --- a/usr.sbin/pkg_install/lib/str.c +++ b/usr.sbin/pkg_install/lib/str.c @@ -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! */ } -- cgit v1.1