From 1a87edab6657a257876ab2f8790f2937feba7066 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 15 Apr 2014 16:40:48 +0200 Subject: 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. --- common/sysutils.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'common/sysutils.c') 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. */ -- cgit v1.2.3