diff options
author | Werner Koch <[email protected]> | 2014-04-15 14:40:48 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2014-04-22 13:02:05 +0000 |
commit | 1a87edab6657a257876ab2f8790f2937feba7066 (patch) | |
tree | 5dc04c43a71388a9437dbfc5d1686d69556210b0 /common/sysutils.c | |
parent | gpg: Print a warning if GKR has hijacked gpg-agent. (diff) | |
download | gnupg-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/sysutils.c')
-rw-r--r-- | common/sysutils.c | 30 |
1 files changed, 30 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. */ |