mirror of git://sourceware.org/git/glibc.git
DCIGETTEXT: Use getcwd, asprintf to construct absolute pathname
This commit is contained in:
parent
e535139e82
commit
9695dd0c93
|
@ -1,3 +1,8 @@
|
||||||
|
2017-06-21 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
|
* intl/dcigettext.c (DCIGETTEXT): Use getcwd (NULL, 0) and
|
||||||
|
asprintf to construct an absolute pathname.
|
||||||
|
|
||||||
2017-06-21 Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
2017-06-21 Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
||||||
|
|
||||||
* misc/tst-preadvwritev2-common.c: New file.
|
* misc/tst-preadvwritev2-common.c: New file.
|
||||||
|
|
|
@ -59,6 +59,7 @@ extern int errno;
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#if defined HAVE_UNISTD_H || defined _LIBC
|
#if defined HAVE_UNISTD_H || defined _LIBC
|
||||||
|
@ -495,6 +496,7 @@ DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2,
|
||||||
const char *categoryname;
|
const char *categoryname;
|
||||||
const char *categoryvalue;
|
const char *categoryvalue;
|
||||||
const char *dirname;
|
const char *dirname;
|
||||||
|
char *xdirname = NULL;
|
||||||
char *xdomainname;
|
char *xdomainname;
|
||||||
char *single_locale;
|
char *single_locale;
|
||||||
char *retval;
|
char *retval;
|
||||||
|
@ -624,35 +626,17 @@ DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2,
|
||||||
if (!IS_ABSOLUTE_PATH (dirname))
|
if (!IS_ABSOLUTE_PATH (dirname))
|
||||||
{
|
{
|
||||||
/* We have a relative path. Make it absolute now. */
|
/* We have a relative path. Make it absolute now. */
|
||||||
size_t dirname_len = strlen (dirname) + 1;
|
char *cwd = getcwd (NULL, 0);
|
||||||
size_t path_max;
|
if (cwd == NULL)
|
||||||
char *resolved_dirname;
|
/* We cannot get the current working directory. Don't
|
||||||
char *ret;
|
signal an error but simply return the default
|
||||||
|
string. */
|
||||||
path_max = (unsigned int) PATH_MAX;
|
|
||||||
path_max += 2; /* The getcwd docs say to do this. */
|
|
||||||
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
resolved_dirname = (char *) alloca (path_max + dirname_len);
|
|
||||||
ADD_BLOCK (block_list, tmp_dirname);
|
|
||||||
|
|
||||||
__set_errno (0);
|
|
||||||
ret = getcwd (resolved_dirname, path_max);
|
|
||||||
if (ret != NULL || errno != ERANGE)
|
|
||||||
break;
|
|
||||||
|
|
||||||
path_max += path_max / 2;
|
|
||||||
path_max += PATH_INCR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret == NULL)
|
|
||||||
/* We cannot get the current working directory. Don't signal an
|
|
||||||
error but simply return the default string. */
|
|
||||||
goto return_untranslated;
|
goto return_untranslated;
|
||||||
|
int ret = __asprintf (&xdirname, "%s/%s", cwd, dirname);
|
||||||
stpcpy (stpcpy (strchr (resolved_dirname, '\0'), "/"), dirname);
|
free (cwd);
|
||||||
dirname = resolved_dirname;
|
if (ret < 0)
|
||||||
|
return NULL;
|
||||||
|
dirname = xdirname;
|
||||||
}
|
}
|
||||||
#ifndef IN_LIBGLOCALE
|
#ifndef IN_LIBGLOCALE
|
||||||
}
|
}
|
||||||
|
@ -767,6 +751,7 @@ DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2,
|
||||||
{
|
{
|
||||||
/* Found the translation of MSGID1 in domain DOMAIN:
|
/* Found the translation of MSGID1 in domain DOMAIN:
|
||||||
starting at RETVAL, RETLEN bytes. */
|
starting at RETVAL, RETLEN bytes. */
|
||||||
|
free (xdirname);
|
||||||
FREE_BLOCKS (block_list);
|
FREE_BLOCKS (block_list);
|
||||||
if (foundp == NULL)
|
if (foundp == NULL)
|
||||||
{
|
{
|
||||||
|
@ -850,6 +835,7 @@ DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2,
|
||||||
|
|
||||||
return_untranslated:
|
return_untranslated:
|
||||||
/* Return the untranslated MSGID. */
|
/* Return the untranslated MSGID. */
|
||||||
|
free (xdirname);
|
||||||
FREE_BLOCKS (block_list);
|
FREE_BLOCKS (block_list);
|
||||||
gl_rwlock_unlock (_nl_state_lock);
|
gl_rwlock_unlock (_nl_state_lock);
|
||||||
#ifdef _LIBC
|
#ifdef _LIBC
|
||||||
|
|
Loading…
Reference in New Issue