X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=fish%2Ftilde.c;h=64b5b399f0e5546abb3bdfdf48f5f5421828bb20;hp=13e6cd8ff2410e98421ee92b7cdc5e2b2f8ae75d;hb=3fc9951016d08e2467375e24094a468713637c1f;hpb=9449b0fce4145a56df9d43169d61e8b2c4e41b09 diff --git a/fish/tilde.c b/fish/tilde.c index 13e6cd8..64b5b39 100644 --- a/fish/tilde.c +++ b/fish/tilde.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -30,7 +29,7 @@ #include "fish.h" static char *expand_home (const char *); -static const char *find_home_for_username (const char *, int); +static const char *find_home_for_username (const char *, size_t); /* This is called from the script loop if we find a candidate for * ~username (tilde-expansion). @@ -52,10 +51,8 @@ try_tilde_expansion (char *str) * username from the password file. */ else { - int len; const char *home, *rest; - - len = strcspn (&str[1], "/"); + size_t len = strcspn (&str[1], "/"); rest = &str[1+len]; home = find_home_for_username (&str[1], len); @@ -64,8 +61,8 @@ try_tilde_expansion (char *str) len = strlen (home) + strlen (rest); str = malloc (len); if (str == NULL) { - perror ("malloc"); - exit (1); + perror ("malloc"); + exit (1); } strcpy (str, home); strcat (str, rest); @@ -106,14 +103,14 @@ expand_home (const char *append) * or NULL if not found. */ static const char * -find_home_for_username (const char *username, int ulen) +find_home_for_username (const char *username, size_t ulen) { struct passwd *pw; setpwent (); while ((pw = getpwent ()) != NULL) { if (strlen (pw->pw_name) == ulen && - strncmp (username, pw->pw_name, ulen) == 0) + STREQLEN (username, pw->pw_name, ulen)) return pw->pw_dir; }