1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

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.
This commit is contained in:
Werner Koch 2014-04-15 16:40:48 +02:00
parent ffa39be5eb
commit 1a87edab66
3 changed files with 32 additions and 25 deletions

View File

@ -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. */

View File

@ -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);

View File

@ -212,30 +212,6 @@ my_strusage( int level )
}
static char *
gnu_getcwd (void)
{
char *buffer;
size_t size = 100;
for (;;)
{
buffer = xmalloc (size+1);
#ifdef HAVE_W32CE_SYSTEM
strcpy (buffer, "/");
return buffer;
#else
if (getcwd (buffer, size) == buffer)
return buffer;
xfree (buffer);
if (errno != ERANGE)
return NULL;
size *= 2;
#endif
}
}
/* Unescape STRING and returned the malloced result. The surrounding
quotes must already be removed from STRING. */
static char *
@ -568,7 +544,7 @@ get_var_ext (const char *name)
s++;
if (!strcmp (s, "cwd"))
{
result = gnu_getcwd ();
result = gnupg_getcwd ();
if (!result)
log_error ("getcwd failed: %s\n", strerror (errno));
}