Re: [PATCH] hard-coded paths the second

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Aug 27, 2010 at 07:05:14PM +0200, Peter Reineke wrote:
> This should be more pleasant regarding to coding styles, and add the  
> missing paths '/usr/local/include' and '/usr/include' to the sourcedirs  
> as well.
>
> Reading PATH variable instead of relying on hard-coded binary paths
>
> Signed-off-by: Peter Reineke<preineke@xxxxxxx>
> ---
> diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c
> index 931ff77..3ba8abc 100644
> --- a/misc-utils/whereis.c
> +++ b/misc-utils/whereis.c
> @@ -57,62 +57,9 @@ void findv(char **, int, char *);
>  void find(char **, char *);
>  void findin(char *, char *);
>  int itsit(char *, char *);
> +char **get_path();
>
> -static char *bindirs[] = {
> -   "/bin",
> -   "/usr/bin",
> -   "/sbin",
> -   "/usr/sbin",
> -   "/etc",
> -   "/usr/etc",
> -   "/lib",
> -   "/usr/lib",
> -   "/lib64",
> -   "/usr/lib64",

 I have doubts that everyone has /sbin, /lib[64], /usr/lib[64] or
 /opt/*/bin in $PATH. 

> +**get_path()
> +{
> +	char *path;
> +	path = getenv("PATH");

 Please, use the current bindir[] as a template and modify the array
 according to the $PATH. 

> +        char *buf = strdup(path);

 if (!buf)
    err(EXIT_FAILURE, _("strdup failed"));

> +	char *cp;
> +	int count = 1; /* there is one entry more than there are colons */
> +	for(cp = buf;*cp;cp++)
> +		if (*cp == ':') count++;
> +	char **dirs = malloc(sizeof(char*) * (count + 1));
> +		/* another entry for the 0 */

 again, check malloc() return value

> +	char **dirp = dirs;
> +	*(dirp++) = buf;
> +	for(cp=buf;*cp;cp++)
> +		if (*cp == ':') {
> +			*cp = 0;
> +			*(dirp++) = cp + 1;
> +		}
> +	dirp = 0;	
> +	return dirs;
> +}

 Please, read http://www.kernel.org/doc/Documentation/CodingStyle
 or follow the current coding style in whereis.c


    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux