Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs24-19fa
git_rec_nano
Commits
a9a45f2b
Commit
a9a45f2b
authored
8 years ago
by
Mike Frysinger
Committed by
Benno Schulenberg
8 years ago
Browse files
Options
Download
Email Patches
Plain Diff
fix build on systems without pwd.h
Windows doesn't have *nix style account databases.
parent
a0fb5523
master
feature/match-parens
refactor/readbility
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
configure.ac
+1
-1
configure.ac
src/files.c
+14
-1
src/files.c
src/utils.c
+4
-0
src/utils.c
with
19 additions
and
2 deletions
+19
-2
configure.ac
View file @
a9a45f2b
...
...
@@ -57,7 +57,7 @@ AC_DEFINE_DIR([PKGDATADIR], [pkgdatadir], [Where data are placed to.])
dnl Checks for header files.
AC_CHECK_HEADERS(libintl.h limits.h sys/param.h)
AC_CHECK_HEADERS(libintl.h limits.h
pwd.h
sys/param.h)
dnl Checks for options.
...
...
This diff is collapsed.
Click to expand it.
src/files.c
View file @
a9a45f2b
...
...
@@ -29,7 +29,9 @@
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#include <libgen.h>
#define LOCKBUFSIZE 8192
...
...
@@ -168,6 +170,7 @@ void set_modified(void)
* Returns 1 on success, and 0 on failure (but continue anyway). */
int
write_lockfile
(
const
char
*
lockfilename
,
const
char
*
origfilename
,
bool
modified
)
{
#ifdef HAVE_PWD_H
int
cflags
,
fd
;
FILE
*
filestream
;
pid_t
mypid
;
...
...
@@ -284,6 +287,9 @@ int write_lockfile(const char *lockfilename, const char *origfilename, bool modi
free_the_data:
free
(
lockdata
);
return
0
;
#else
return
1
;
#endif
}
/* Delete the lockfile. Return -1 if unsuccessful, and 1 otherwise. */
...
...
@@ -2345,6 +2351,7 @@ char *real_dir_from_tilde(const char *buf)
get_homedir
();
tilde_dir
=
mallocstrcpy
(
NULL
,
homedir
);
}
else
{
#ifdef HAVE_PWD_H
const
struct
passwd
*
userdata
;
tilde_dir
=
mallocstrncpy
(
NULL
,
buf
,
i
+
1
);
...
...
@@ -2357,6 +2364,9 @@ char *real_dir_from_tilde(const char *buf)
endpwent
();
if
(
userdata
!=
NULL
)
tilde_dir
=
mallocstrcpy
(
tilde_dir
,
userdata
->
pw_dir
);
#else
tilde_dir
=
strdup
(
""
);
#endif
}
retval
=
charalloc
(
strlen
(
tilde_dir
)
+
strlen
(
buf
+
i
)
+
1
);
...
...
@@ -2447,12 +2457,14 @@ char **username_tab_completion(const char *buf, size_t *num_matches,
size_t
buf_len
)
{
char
**
matches
=
NULL
;
const
struct
passwd
*
userdata
;
assert
(
buf
!=
NULL
&&
num_matches
!=
NULL
&&
buf_len
>
0
);
*
num_matches
=
0
;
#ifdef HAVE_PWD_H
const
struct
passwd
*
userdata
;
while
((
userdata
=
getpwent
())
!=
NULL
)
{
if
(
strncmp
(
userdata
->
pw_name
,
buf
+
1
,
buf_len
-
1
)
==
0
)
{
/* Cool, found a match. Add it to the list. This makes a
...
...
@@ -2473,6 +2485,7 @@ char **username_tab_completion(const char *buf, size_t *num_matches,
}
}
endpwent
();
#endif
return
matches
;
}
...
...
This diff is collapsed.
Click to expand it.
src/utils.c
View file @
a9a45f2b
...
...
@@ -25,7 +25,9 @@
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#include <ctype.h>
#include <errno.h>
...
...
@@ -36,6 +38,7 @@ void get_homedir(void)
if
(
homedir
==
NULL
)
{
const
char
*
homenv
=
getenv
(
"HOME"
);
#ifdef HAVE_PWD_H
/* When HOME isn't set, or when we're root, get the home directory
* from the password file instead. */
if
(
homenv
==
NULL
||
geteuid
()
==
0
)
{
...
...
@@ -44,6 +47,7 @@ void get_homedir(void)
if
(
userage
!=
NULL
)
homenv
=
userage
->
pw_dir
;
}
#endif
/* Only set homedir if some home directory could be determined,
* otherwise keep homedir NULL. */
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help