git.annexia.org
/
libguestfs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
lib: Make pcre, libmagic and hivex libraries optional.
[libguestfs.git]
/
fish
/
tilde.c
diff --git
a/fish/tilde.c
b/fish/tilde.c
index
13e6cd8
..
83aa70d
100644
(file)
--- a/
fish/tilde.c
+++ b/
fish/tilde.c
@@
-22,7
+22,6
@@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <ctype.h>
#include <assert.h>
#include <pwd.h>
#include <sys/types.h>
#include <assert.h>
#include <pwd.h>
#include <sys/types.h>
@@
-30,7
+29,7
@@
#include "fish.h"
static char *expand_home (const char *);
#include "fish.h"
static char *expand_home (const char *);
-static const char *find_home_for_username (const char *,
in
t);
+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).
/* 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 {
* username from the password file.
*/
else {
- int len;
const char *home, *rest;
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);
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) {
len = strlen (home) + strlen (rest);
str = malloc (len);
if (str == NULL) {
- perror ("malloc");
-
exit (1
);
+
perror ("malloc");
+
exit (EXIT_FAILURE
);
}
strcpy (str, home);
strcat (str, rest);
}
strcpy (str, home);
strcat (str, rest);
@@
-88,11
+85,11
@@
expand_home (const char *append)
home = getenv ("HOME");
if (!home) home = "~";
home = getenv ("HOME");
if (!home) home = "~";
- len = strlen (home) + (append ? strlen (append) : 0);
+ len = strlen (home) + (append ? strlen (append) : 0)
+ 1
;
str = malloc (len);
if (str == NULL) {
perror ("malloc");
str = malloc (len);
if (str == NULL) {
perror ("malloc");
- exit (
1
);
+ exit (
EXIT_FAILURE
);
}
strcpy (str, home);
}
strcpy (str, home);
@@
-106,14
+103,14
@@
expand_home (const char *append)
* or NULL if not found.
*/
static const char *
* or NULL if not found.
*/
static const char *
-find_home_for_username (const char *username,
in
t 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 &&
{
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;
}
return pw->pw_dir;
}