From owner-svn-src-all@FreeBSD.ORG Sun Dec 13 16:45:46 2009 Return-Path: Delivered-To: svn-src-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7E71C1065670; Sun, 13 Dec 2009 16:45:46 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail01.syd.optusnet.com.au (mail01.syd.optusnet.com.au [211.29.132.182]) by mx1.freebsd.org (Postfix) with ESMTP id 144798FC15; Sun, 13 Dec 2009 16:45:45 +0000 (UTC) Received: from c220-239-235-116.carlnfd3.nsw.optusnet.com.au (c220-239-235-116.carlnfd3.nsw.optusnet.com.au [220.239.235.116]) by mail01.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id nBDGjgW6005647 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 14 Dec 2009 03:45:43 +1100 Date: Mon, 14 Dec 2009 03:45:42 +1100 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Xin LI In-Reply-To: <200912130334.nBD3YJbO072556@svn.freebsd.org> Message-ID: <20091214031938.E33347@delplex.bde.org> References: <200912130334.nBD3YJbO072556@svn.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org Subject: Re: svn commit: r200465 - head/usr.bin/xinstall X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Dec 2009 16:45:46 -0000 On Sun, 13 Dec 2009, Xin LI wrote: > Log: > Staticify internal functions and make usage() a prototype. Please actually declare them static. > Modified: head/usr.bin/xinstall/xinstall.c > ============================================================================== > --- head/usr.bin/xinstall/xinstall.c Sun Dec 13 03:29:05 2009 (r200464) > +++ head/usr.bin/xinstall/xinstall.c Sun Dec 13 03:34:19 2009 (r200465) > @@ -86,16 +86,16 @@ int dobackup, docompare, dodir, dopreser > mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; > const char *suffix = BACKUP_SUFFIX; > > -void copy(int, const char *, int, const char *, off_t); > -int compare(int, const char *, size_t, int, const char *, size_t); > -int create_newfile(const char *, int, struct stat *); > -int create_tempfile(const char *, char *, size_t); > -void install(const char *, const char *, u_long, u_int); > -void install_dir(char *); > -u_long numeric_id(const char *, const char *); > -void strip(const char *); > -int trymmap(int); > -void usage(void); > +static void copy(int, const char *, int, const char *, off_t); > +static int compare(int, const char *, size_t, int, const char *, size_t); Sorting errors like copy < compare could be fixed when making changes to all the prototypes like this. > +static int create_newfile(const char *, int, struct stat *); > +static int create_tempfile(const char *, char *, size_t); > +static void install(const char *, const char *, u_long, u_int); > +static void install_dir(char *); > +static u_long numeric_id(const char *, const char *); > +static void strip(const char *); > +static int trymmap(int); > +static void usage(void); > > int > main(int argc, char *argv[]) > @@ -771,7 +771,7 @@ install_dir(char *path) > * print a usage message and die > */ > void > -usage() > +usage(void) > { > (void)fprintf(stderr, > "usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]\n" It is a good obfuscation to declare functions as static only in the prototype, so that you can't see the static for the actual function. The reverse obfuscation (with static only in the function definition) would make more sense, but is a constraint error. (C99 allows building up a declaration by accumulating type or linkage details in some cases but not here. Last time I checked, gcc didn't understand this, and warns about "redundant redeclarations" for non-redundant non-re declarations.) With C90 function definitions (not prototypes!) and almost all functions staticized, most of foward declarations involving prototypes are unnecessary. We couldn't agree if style requires having them (it is sometimes useful to have a complete list of static functions as prototypes near the top of the file). We should agree before large staicization sweeps. The bad style of having everything extern, combined prototyping all extern functions, left us many thousands of lines of non-static prototypes near the tops of files. (In 4.4BSD, prototypes had to be done like that, using __P(()), even for static functions, since that was the only reasonable way to ifdef prototypes. After use of __P(()) was removed, extern prototypes still had to be done like that since -Wmissing-prototypes forces it at high WARNS even for functions that should be static and are defined before they are called. But static prototypes don't have to be done like that.) Bruce