diff options
author | obrien <obrien@FreeBSD.org> | 2001-08-13 04:18:30 +0000 |
---|---|---|
committer | obrien <obrien@FreeBSD.org> | 2001-08-13 04:18:30 +0000 |
commit | 49568467b45dc390f37ede6491d231082f2aa6b7 (patch) | |
tree | 1dfd5b2f52680c0cb2ea02ec33b3ce27b5c368f4 | |
parent | 260a2ab3624fd4dd1837cf5edcdf4a9fd946ea60 (diff) | |
download | FreeBSD-src-49568467b45dc390f37ede6491d231082f2aa6b7.zip FreeBSD-src-49568467b45dc390f37ede6491d231082f2aa6b7.tar.gz |
Reduce private "lesser known" function redirection to improve clarity.
Approved by: jkh
-rw-r--r-- | usr.sbin/pkg_install/add/main.c | 45 | ||||
-rw-r--r-- | usr.sbin/pkg_install/add/perform.c | 2 | ||||
-rw-r--r-- | usr.sbin/pkg_install/create/perform.c | 2 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/lib.h | 3 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/str.c | 38 |
5 files changed, 31 insertions, 59 deletions
diff --git a/usr.sbin/pkg_install/add/main.c b/usr.sbin/pkg_install/add/main.c index 2844bf9..d884d60 100644 --- a/usr.sbin/pkg_install/add/main.c +++ b/usr.sbin/pkg_install/add/main.c @@ -111,7 +111,7 @@ main(int argc, char **argv) break; case 't': - if (s_strlcpy(FirstPen, optarg, sizeof(FirstPen))) + if (strlcpy(FirstPen, optarg, sizeof(FirstPen)) >= sizeof(FirstPen)) errx(1, "-t Argument too long."); break; @@ -145,27 +145,30 @@ main(int argc, char **argv) if (Remote) { if ((packagesite = getpackagesite()) == NULL) errx(1, "package name too long"); - if (s_strlcpy(temppackageroot, packagesite, - sizeof(temppackageroot))) + if (strlcpy(temppackageroot, packagesite, + sizeof(temppackageroot)) >= sizeof(temppackageroot)) errx(1, "package name too long"); - if (s_strlcat(temppackageroot, *argv, - sizeof(temppackageroot))) + if (strlcat(temppackageroot, *argv, sizeof(temppackageroot)) + >= sizeof(temppackageroot)) errx(1, "package name too long"); remotepkg = temppackageroot; if (!((ptr = strrchr(remotepkg, '.')) && ptr[1] == 't' && ptr[2] == 'g' && ptr[3] == 'z' && !ptr[4])) - if (s_strlcat(remotepkg, ".tgz", sizeof(temppackageroot))) + if (strlcat(remotepkg, ".tgz", sizeof(temppackageroot)) + >= sizeof(temppackageroot)) errx(1, "package name too long"); } if (!strcmp(*argv, "-")) /* stdin? */ pkgs[ch] = "-"; else if (isURL(*argv)) { /* preserve URLs */ - if (s_strlcpy(pkgnames[ch], *argv, sizeof(pkgnames[ch]))) + if (strlcpy(pkgnames[ch], *argv, sizeof(pkgnames[ch])) + >= sizeof(pkgnames[ch])) errx(1, "package name too long"); pkgs[ch] = pkgnames[ch]; } else if ((Remote) && isURL(remotepkg)) { - if (s_strlcpy(pkgnames[ch], remotepkg, sizeof(pkgnames[ch]))) + if (strlcpy(pkgnames[ch], remotepkg, sizeof(pkgnames[ch])) + >= sizeof(pkgnames[ch])) errx(1, "package name too long"); pkgs[ch] = pkgnames[ch]; } else { /* expand all pathnames to fullnames */ @@ -174,11 +177,13 @@ main(int argc, char **argv) else { /* look for the file in the expected places */ if (!(cp = fileFindByPath(NULL, *argv))) { /* let pkg_do() fail later, so that error is reported */ - if (s_strlcpy(pkgnames[ch], *argv, sizeof(pkgnames[ch]))) + if (strlcpy(pkgnames[ch], *argv, sizeof(pkgnames[ch])) + >= sizeof(pkgnames[ch])) errx(1, "package name too long"); pkgs[ch] = pkgnames[ch]; } else { - if (s_strlcpy(pkgnames[ch], cp, sizeof(pkgnames[ch]))) + if (strlcpy(pkgnames[ch], cp, sizeof(pkgnames[ch])) + >= sizeof(pkgnames[ch])) errx(1, "package name too long"); pkgs[ch] = pkgnames[ch]; } @@ -220,37 +225,41 @@ getpackagesite(void) struct utsname u; if (getenv("PACKAGESITE")) { - if (s_strlcpy(sitepath, getenv("PACKAGESITE"), - sizeof(sitepath))) + if (strlcpy(sitepath, getenv("PACKAGESITE"), sizeof(sitepath)) + >= sizeof(sitepath)) return NULL; return sitepath; } if (getenv("PACKAGEROOT")) { - if (s_strlcpy(sitepath, getenv("PACKAGEROOT"), sizeof(sitepath))) + if (strlcpy(sitepath, getenv("PACKAGEROOT"), sizeof(sitepath)) + >= sizeof(sitepath)) return NULL; } else { - if (s_strlcat(sitepath, "ftp://ftp.freebsd.org", sizeof(sitepath))) + if (strlcat(sitepath, "ftp://ftp.freebsd.org", sizeof(sitepath)) + >= sizeof(sitepath)) return NULL; } - if (s_strlcat(sitepath, "/pub/FreeBSD/ports/", sizeof(sitepath))) + if (strlcat(sitepath, "/pub/FreeBSD/ports/", sizeof(sitepath)) + >= sizeof(sitepath)) return NULL; uname(&u); - if (s_strlcat(sitepath, u.machine, sizeof(sitepath))) + if (strlcat(sitepath, u.machine, sizeof(sitepath)) >= sizeof(sitepath)) return NULL; reldate = getosreldate(); for(i = 0; releases[i].directory != NULL; i++) { if (reldate >= releases[i].lowver && reldate <= releases[i].hiver) { - if (s_strlcat(sitepath, releases[i].directory, sizeof(sitepath))) + if (strlcat(sitepath, releases[i].directory, sizeof(sitepath)) + >= sizeof(sitepath)) return NULL; break; } } - if (s_strlcat(sitepath, "/Latest/", sizeof(sitepath))) + if (strlcat(sitepath, "/Latest/", sizeof(sitepath)) >= sizeof(sitepath)) return NULL; return sitepath; diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c index 06c5028..910a38d 100644 --- a/usr.sbin/pkg_install/add/perform.c +++ b/usr.sbin/pkg_install/add/perform.c @@ -440,7 +440,7 @@ pkg_do(char *pkg) continue; if (Verbose) printf("Attempting to record dependency on package '%s'\n", p->name); - sprintf(contents, "%s/%s/%s", LOG_DIR, basename_of(p->name), + sprintf(contents, "%s/%s/%s", LOG_DIR, basename(p->name), REQUIRED_BY_FNAME); cfile = fopen(contents, "a"); if (!cfile) diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c index 0c32ea6..252a457 100644 --- a/usr.sbin/pkg_install/create/perform.c +++ b/usr.sbin/pkg_install/create/perform.c @@ -154,7 +154,7 @@ pkg_perform(char **pkgs) * at the top. */ if (find_plist(&plist, PLIST_NAME) == NULL) - add_plist_top(&plist, PLIST_NAME, basename_of(pkg)); + add_plist_top(&plist, PLIST_NAME, basename(pkg)); /* * We're just here for to dump out a revised plist for the FreeBSD ports diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index f8965a0..fc41c66 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -127,11 +127,8 @@ char *copy_string(char *); Boolean suffix(char *, char *); void nuke_suffix(char *); void str_lowercase(char *); -char *basename_of(char *); char *strconcat(char *, char *); char *get_string(char *, int, FILE *); -int s_strlcpy(char *, const char *, size_t); -int s_strlcat(char *, const char *, size_t); /* File */ Boolean fexists(char *); diff --git a/usr.sbin/pkg_install/lib/str.c b/usr.sbin/pkg_install/lib/str.c index 55ff782..b2b68c0 100644 --- a/usr.sbin/pkg_install/lib/str.c +++ b/usr.sbin/pkg_install/lib/str.c @@ -25,24 +25,13 @@ static const char rcsid[] = #include "lib.h" -/* Return the filename portion of a path */ -char * -basename_of(char *str) -{ - char *basename = str + strlen(str) - 1; - - while (basename != str && basename[-1] != '/') - --basename; - return basename; -} - char * strconcat(char *s1, char *s2) { static char tmp[FILENAME_MAX]; tmp[0] = '\0'; - strncpy(tmp, s1 ? s1 : s2, FILENAME_MAX); + strncpy(tmp, s1 ? s1 : s2, FILENAME_MAX); /* XXX: what if both are NULL? */ if (s1 && s2) strncat(tmp, s2, FILENAME_MAX - strlen(tmp)); return tmp; @@ -61,33 +50,11 @@ get_dash_string(char **str) return *str; } -/* Do a strlcpy and test for overflow */ -int -s_strlcpy(char *dst, const char *src, size_t size) -{ - return (strlcpy(dst, src, size) >= size); -} - -/* Do a strlcat and test for overflow */ -int -s_strlcat(char *dst, const char *src, size_t size) -{ - return (strlcat(dst, src, size) >= size); -} - /* Rather Obvious */ char * copy_string(char *str) { - char *ret; - - if (!str) - ret = NULL; - else { - ret = (char *)malloc(strlen(str) + 1); - strcpy(ret, str); - } - return ret; + return (str ? strdup(str) : NULL); } /* Return TRUE if 'str' ends in suffix 'suff' */ @@ -141,4 +108,3 @@ get_string(char *str, int max, FILE *fp) } return NULL; } - |