[svn] GnuPG - r5132 - trunk/jnlib
svn author wk
cvs at cvs.gnupg.org
Wed Aug 26 11:24:04 CEST 2009
Author: wk
Date: 2009-08-26 11:24:04 +0200 (Wed, 26 Aug 2009)
New Revision: 5132
Modified:
trunk/jnlib/ChangeLog
trunk/jnlib/stringhelp.c
Log:
Refactor new code.
Modified: trunk/jnlib/ChangeLog
===================================================================
--- trunk/jnlib/ChangeLog 2009-08-26 08:55:57 UTC (rev 5131)
+++ trunk/jnlib/ChangeLog 2009-08-26 09:24:04 UTC (rev 5132)
@@ -1,5 +1,10 @@
2009-08-26 Werner Koch <wk at g10code.com>
+ * stringhelp.c (do_make_filename): Factor some code out to ..
+ (get_pwdir): .. new.
+
+2009-08-26 Werner Koch <wk at g10code.com>
+
* stringhelp.c [HAVE_PWD_H]: Include pwd.h.
(do_make_filename): New.
(make_filename, make_filename_try): Implement using the new
Modified: trunk/jnlib/stringhelp.c
===================================================================
--- trunk/jnlib/stringhelp.c 2009-08-26 08:55:57 UTC (rev 5131)
+++ trunk/jnlib/stringhelp.c 2009-08-26 09:24:04 UTC (rev 5132)
@@ -319,6 +319,38 @@
static char *
+get_pwdir (int xmode, const char *name)
+{
+ char *result = NULL;
+#ifdef HAVE_PWD_H
+ struct passwd *pwd = NULL;
+
+ if (name)
+ {
+#ifdef HAVE_GETPWNAM
+ /* Fixme: We should use getpwnam_r if available. */
+ pwd = getpwnam (name);
+#endif
+ }
+ else
+ {
+#ifdef HAVE_GETPWUID
+ /* Fixme: We should use getpwuid_r if available. */
+ pwd = getpwuid (getuid());
+#endif
+ }
+ if (pwd)
+ {
+ if (xmode)
+ result = jnlib_xstrdup (pwd->pw_dir);
+ else
+ result = jnlib_strdup (pwd->pw_dir);
+ }
+#endif /*HAVE_PWD_H*/
+ return result;
+}
+
+static char *
do_make_filename (int xmode, const char *first_part, va_list arg_ptr)
{
const char *argv[32];
@@ -351,37 +383,16 @@
{
/* This is the "~/" or "~" case. */
home = getenv("HOME");
-
-#if defined(HAVE_GETPWUID) && defined(HAVE_PWD_H)
if (!home)
- {
- struct passwd *pwd;
-
- pwd = getpwuid (getuid());
- if (pwd)
- {
- if (xmode)
- home_buffer = home = jnlib_xstrdup (pwd->pw_dir);
- else
- {
- home_buffer = home = jnlib_strdup (pwd->pw_dir);
- if (!home)
- return NULL;
- }
- }
- }
-#endif /* HAVE_GETPWUID && HAVE_PWD_H */
-
+ home = home_buffer = get_pwdir (xmode, NULL);
if (home && *home)
n += strlen (home);
}
-#if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
else
{
/* This is the "~username/" or "~username" case. */
char *user;
- struct passwd *pwd;
-
+
if (xmode)
user = jnlib_xstrdup (first_part+1);
else
@@ -394,27 +405,14 @@
if (p)
*p = 0;
skip = 1 + strlen (user);
-
- /* Fixme: Use getwpnam_r if available. */
- pwd = getpwnam (user);
+
+ home = home_buffer = get_pwdir (xmode, user);
jnlib_free (user);
- if (pwd)
- {
- if (xmode)
- home_buffer = home = jnlib_xstrdup (pwd->pw_dir);
- else
- {
- home_buffer = home = jnlib_strdup (pwd->pw_dir);
- if (!home)
- return NULL;
- }
- }
if (home)
n += strlen (home);
else
skip = 1;
}
-#endif /*HAVE_GETPWNAM && HAVE_PWD_H*/
}
if (xmode)
More information about the Gnupg-commits
mailing list