Date: Sun, 2 Jan 2011 02:37:01 -0500 From: Eitan Adler <lists@eitanadler.com> To: hackers@freebsd.org, joe@freebsd.org, jkh@freebsd.org, phk@freebsd.org Subject: [patch] should crunchgen use basename(3) instead of homebrew code? Message-ID: <AANLkTimyXvm%2B6zyAobzxq-PCfBJus2ZMHvk5ztBOzufW@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
I'm not sure about this patch because of the behavior change of - slash = strrchr(path, '/'); - basename = slash? slash+1 : path; + bn = basename(slash); CCed to the last few people to touch the relevant code (via svn praise) Index: crunched_main.c =================================================================== --- crunched_main.c (revision 216884) +++ crunched_main.c (working copy) @@ -33,6 +33,7 @@ * or calls one of them based on argv[1]. This allows the testing of * the crunched binary without creating all the links. */ +#include <libgen.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -47,22 +48,21 @@ int main(int argc, char **argv, char **envp) { - char *slash, *basename; + char *slash, *bn; struct stub *ep; if(argv[0] == NULL || *argv[0] == '\0') crunched_usage(); - slash = strrchr(argv[0], '/'); - basename = slash? slash+1 : argv[0]; + bn = basename(argv[0]); for(ep=entry_points; ep->name != NULL; ep++) - if(!strcmp(basename, ep->name)) break; + if(!strcmp(bn, ep->name)) break; if(ep->name) return ep->f(argc, argv, envp); else { - fprintf(stderr, "%s: %s not compiled in\n", EXECNAME, basename); + fprintf(stderr, "%s: %s not compiled in\n", EXECNAME, bn); crunched_usage(); } } @@ -70,14 +70,13 @@ int crunched_here(char *path) { - char *slash, *basename; + char *slash, *bn; struct stub *ep; - slash = strrchr(path, '/'); - basename = slash? slash+1 : path; + bn = basename(slash); for(ep=entry_points; ep->name != NULL; ep++) - if(!strcmp(basename, ep->name)) + if(!strcmp(bn, ep->name)) return 1; return 0; } -- Eitan Adler
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTimyXvm%2B6zyAobzxq-PCfBJus2ZMHvk5ztBOzufW>