From owner-freebsd-hackers@FreeBSD.ORG Sun Jan 2 07:37:22 2011 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 550291065670; Sun, 2 Jan 2011 07:37:22 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-iy0-f182.google.com (mail-iy0-f182.google.com [209.85.210.182]) by mx1.freebsd.org (Postfix) with ESMTP id B3BDC8FC1E; Sun, 2 Jan 2011 07:37:21 +0000 (UTC) Received: by iyb26 with SMTP id 26so11830945iyb.13 for ; Sat, 01 Jan 2011 23:37:21 -0800 (PST) Received: by 10.231.17.205 with SMTP id t13mr19104624iba.80.1293953841250; Sat, 01 Jan 2011 23:37:21 -0800 (PST) MIME-Version: 1.0 Received: by 10.231.178.195 with HTTP; Sat, 1 Jan 2011 23:37:01 -0800 (PST) From: Eitan Adler Date: Sun, 2 Jan 2011 02:37:01 -0500 Message-ID: To: hackers@freebsd.org, joe@freebsd.org, jkh@freebsd.org, phk@freebsd.org Content-Type: text/plain; charset=UTF-8 Cc: Subject: [patch] should crunchgen use basename(3) instead of homebrew code? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Jan 2011 07:37:22 -0000 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 #include #include #include @@ -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