aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2014-04-15 14:40:48 +0000
committerWerner Koch <[email protected]>2014-04-22 13:02:05 +0000
commit1a87edab6657a257876ab2f8790f2937feba7066 (patch)
tree5dc04c43a71388a9437dbfc5d1686d69556210b0 /common
parentgpg: Print a warning if GKR has hijacked gpg-agent. (diff)
downloadgnupg-1a87edab6657a257876ab2f8790f2937feba7066.tar.gz
gnupg-1a87edab6657a257876ab2f8790f2937feba7066.zip
common: Add function gnupg_getcwd.
* tools/gpg-connect-agent.c (gnu_getcwd): Move to ... * common/sysutils.c (gnupg_getcwd): .. here. * tools/gpg-connect-agent.c (get_var_ext): Use gnupg_getcwd.
Diffstat (limited to 'common')
-rw-r--r--common/sysutils.c30
-rw-r--r--common/sysutils.h1
2 files changed, 31 insertions, 0 deletions
diff --git a/common/sysutils.c b/common/sysutils.c
index 0d92741ec..95e0f8c0b 100644
--- a/common/sysutils.c
+++ b/common/sysutils.c
@@ -657,6 +657,36 @@ gnupg_unsetenv (const char *name)
#endif
}
+
+/* Return the current working directory as a malloced string. Return
+ NULL and sets ERRNo on error. */
+char *
+gnupg_getcwd (void)
+{
+ char *buffer;
+ size_t size = 100;
+
+ for (;;)
+ {
+ buffer = xtrymalloc (size+1);
+ if (!buffer)
+ return NULL;
+#ifdef HAVE_W32CE_SYSTEM
+ strcpy (buffer, "/"); /* Always "/". */
+ return buffer;
+#else
+ if (getcwd (buffer, size) == buffer)
+ return buffer;
+ xfree (buffer);
+ if (errno != ERANGE)
+ return NULL;
+ size *= 2;
+#endif
+ }
+}
+
+
+
#ifdef HAVE_W32CE_SYSTEM
/* There is a isatty function declaration in cegcc but it does not
make sense, thus we redefine it. */
diff --git a/common/sysutils.h b/common/sysutils.h
index da2c2509d..d139665ac 100644
--- a/common/sysutils.h
+++ b/common/sysutils.h
@@ -63,6 +63,7 @@ int gnupg_remove (const char *fname);
int gnupg_mkdir (const char *name, const char *modestr);
int gnupg_setenv (const char *name, const char *value, int overwrite);
int gnupg_unsetenv (const char *name);
+char *gnupg_getcwd (void);
#ifdef HAVE_W32_SYSTEM
void *w32_get_user_sid (void);