commit bash-20071220 snapshot

This commit is contained in:
Chet Ramey
2011-12-07 09:16:47 -05:00
parent de00a87845
commit b246176e88
9 changed files with 138 additions and 28 deletions
+31
View File
@@ -62,6 +62,33 @@ extern int errno;
# define NULL 0
#endif
/* If the d_fileno member of a struct dirent doesn't return anything useful,
we need to check inode number equivalence the hard way. Return 1 if
the inode corresponding to PATH/DIR is identical to THISINO. */
#if defined (BROKEN_DIRENT_D_INO)
static int
_path_checkino (dotp, name, thisino)
char *dotp;
char *name;
ino_t thisino;
{
char *fullpath;
int r, e;
struct stat st;
e = errno;
fullpath = sh_makepath (dotp, name, MP_RMDOT);
if (stat (fullpath, &st) < 0)
{
errno = e;
return 0;
}
free (fullpath);
errno = e;
return (st.st_ino == thisino);
}
#endif
/* Get the pathname of the current working directory,
and put it in SIZE bytes of BUF. Returns NULL if the
directory couldn't be determined or SIZE was too small.
@@ -173,7 +200,11 @@ getcwd (buf, size)
(d->d_name[1] == '\0' ||
(d->d_name[1] == '.' && d->d_name[2] == '\0')))
continue;
#if !defined (BROKEN_DIRENT_D_INO)
if (mount_point || d->d_fileno == thisino)
#else
if (mount_point || _path_checkino (dotp, d->d_name, thisino))
#endif
{
char *name;
+41 -9
View File
@@ -62,6 +62,32 @@ extern int errno;
# define NULL 0
#endif
/* If the d_fileno member of a struct dirent doesn't return anything useful,
we need to check inode number equivalence the hard way. */
#if defined (BROKEN_DIRENT_D_INO)
static int
_path_checkino (dotp, name, thisino)
char *dotp;
char *name;
ino_t thisino;
{
char *fullpath;
int r, e;
struct stat st;
e = errno;
fullpath = sh_makepath (dotp, name, MP_RMDOT);
if (stat (fullpath, &st) < 0)
{
errno = e;
return 0;
}
free (fullpath);
errno = e;
return (st.st_ino == thisino);
}
#endif
/* Get the pathname of the current working directory,
and put it in SIZE bytes of BUF. Returns NULL if the
directory couldn't be determined or SIZE was too small.
@@ -173,7 +199,11 @@ getcwd (buf, size)
(d->d_name[1] == '\0' ||
(d->d_name[1] == '.' && d->d_name[2] == '\0')))
continue;
#if !defined (BROKEN_DIRENT_D_INO)
if (mount_point || d->d_fileno == thisino)
#else
if (mount_point || _path_checkino (dotp, d->d_name, thisino))
#endif
{
char *name;
@@ -255,19 +285,21 @@ getcwd (buf, size)
{
size_t len = pathbuf + pathsize - pathp;
if (buf == NULL)
{
if (len < (size_t) size)
len = size;
buf = (char *) malloc (len);
if (buf == NULL)
goto lose2;
}
else if ((size_t) size < len)
if (buf == NULL && size <= 0)
size = len;
if ((size_t) size < len)
{
errno = ERANGE;
goto lose2;
}
if (buf == NULL)
{
buf = (char *) malloc (size);
if (buf == NULL)
goto lose2;
}
(void) memcpy((PTR_T) buf, (PTR_T) pathp, len);
}