projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
* crc.h: Include stddef.h, for size_t.
[gnulib.git]
/
lib
/
getcwd.c
diff --git
a/lib/getcwd.c
b/lib/getcwd.c
index
9990b50
..
3bc6e9a
100644
(file)
--- a/
lib/getcwd.c
+++ b/
lib/getcwd.c
@@
-1,5
+1,5
@@
-/* Copyright (C) 1991,92,93,94,95,96,97,98,99,2004
Free Software Foundation,
- Inc.
+/* Copyright (C) 1991,92,93,94,95,96,97,98,99,2004
,2005 Free Software
+
Foundation,
Inc.
This file is part of the GNU C Library.
This program is free software; you can redistribute it and/or modify
This file is part of the GNU C Library.
This program is free software; you can redistribute it and/or modify
@@
-14,10
+14,10
@@
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
- Inc., 5
9 Temple Place - Suite 330, Boston, MA 02111-1307
, USA. */
+ Inc., 5
1 Franklin Street, Fifth Floor, Boston, MA 02110-1301
, USA. */
-#ifdef HAVE_CONFIG_H
-# include
"config.h"
+#ifdef HAVE_CONFIG_H
+# include
<config.h>
#endif
#if !_LIBC
#endif
#if !_LIBC
@@
-30,9
+30,7
@@
#include <stdbool.h>
#include <stddef.h>
#include <stdbool.h>
#include <stddef.h>
-#if HAVE_FCNTL_H
-# include <fcntl.h> /* For AT_FDCWD on Solaris 9. */
-#endif
+#include <fcntl.h> /* For AT_FDCWD on Solaris 9. */
#ifndef __set_errno
# define __set_errno(val) (errno = (val))
#ifndef __set_errno
# define __set_errno(val) (errno = (val))
@@
-62,10
+60,7
@@
# define _D_ALLOC_NAMLEN(d) (_D_EXACT_NAMLEN (d) + 1)
#endif
# define _D_ALLOC_NAMLEN(d) (_D_EXACT_NAMLEN (d) + 1)
#endif
-#if HAVE_UNISTD_H || _LIBC
-# include <unistd.h>
-#endif
-
+#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
@@
-114,7
+109,7
@@
# define __readdir readdir
#endif
\f
# define __readdir readdir
#endif
\f
-/* Get the
path
name of the current working directory, and put it in SIZE
+/* Get the name 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. If successful, returns BUF. In GNU, if BUF is
NULL, an array is allocated with `malloc'; the array is SIZE bytes long,
bytes of BUF. Returns NULL if the directory couldn't be determined or
SIZE was too small. If successful, returns BUF. In GNU, if BUF is
NULL, an array is allocated with `malloc'; the array is SIZE bytes long,
@@
-147,8
+142,8
@@
__getcwd (char *buf, size_t size)
DIR *dirstream = NULL;
dev_t rootdev, thisdev;
ino_t rootino, thisino;
DIR *dirstream = NULL;
dev_t rootdev, thisdev;
ino_t rootino, thisino;
- char *
path
;
- register char *
path
p;
+ char *
dir
;
+ register char *
dir
p;
struct stat st;
size_t allocated = size;
size_t used;
struct stat st;
size_t allocated = size;
size_t used;
@@
-161,9
+156,9
@@
__getcwd (char *buf, size_t size)
So trust the system getcwd's results unless they look
suspicious. */
# undef getcwd
So trust the system getcwd's results unless they look
suspicious. */
# undef getcwd
-
path
= getcwd (buf, size);
- if (
path
|| (errno != ERANGE && !is_ENAMETOOLONG (errno) && errno != ENOENT))
- return
path
;
+
dir
= getcwd (buf, size);
+ if (
dir
|| (errno != ERANGE && !is_ENAMETOOLONG (errno) && errno != ENOENT))
+ return
dir
;
#endif
if (size == 0)
#endif
if (size == 0)
@@
-179,15
+174,15
@@
__getcwd (char *buf, size_t size)
if (buf == NULL)
{
if (buf == NULL)
{
-
path
= malloc (allocated);
- if (
path
== NULL)
+
dir
= malloc (allocated);
+ if (
dir
== NULL)
return NULL;
}
else
return NULL;
}
else
-
path
= buf;
+
dir
= buf;
-
pathp = path
+ allocated;
- *--
path
p = '\0';
+
dirp = dir
+ allocated;
+ *--
dir
p = '\0';
if (__lstat (".", &st) < 0)
goto lose;
if (__lstat (".", &st) < 0)
goto lose;
@@
-318,10
+313,10
@@
__getcwd (char *buf, size_t size)
}
else
{
}
else
{
- size_t
pathroom = pathp - path
;
+ size_t
dirroom = dirp - dir
;
size_t namlen = _D_EXACT_NAMLEN (d);
size_t namlen = _D_EXACT_NAMLEN (d);
- if (
path
room <= namlen)
+ if (
dir
room <= namlen)
{
if (size != 0)
{
{
if (size != 0)
{
@@
-335,20
+330,20
@@
__getcwd (char *buf, size_t size)
allocated += MAX (allocated, namlen);
if (allocated < oldsize
allocated += MAX (allocated, namlen);
if (allocated < oldsize
- || ! (tmp = realloc (
path
, allocated)))
+ || ! (tmp = realloc (
dir
, allocated)))
goto memory_exhausted;
/* Move current contents up to the end of the buffer.
This is guaranteed to be non-overlapping. */
goto memory_exhausted;
/* Move current contents up to the end of the buffer.
This is guaranteed to be non-overlapping. */
-
pathp = memcpy (tmp + allocated - (oldsize - path
room),
-
tmp + path
room,
-
oldsize - path
room);
-
path
= tmp;
+
dirp = memcpy (tmp + allocated - (oldsize - dir
room),
+
tmp + dir
room,
+
oldsize - dir
room);
+
dir
= tmp;
}
}
}
}
-
path
p -= namlen;
- memcpy (
path
p, d->d_name, namlen);
- *--
path
p = '/';
+
dir
p -= namlen;
+ memcpy (
dir
p, d->d_name, namlen);
+ *--
dir
p = '/';
}
thisdev = dotdev;
}
thisdev = dotdev;
@@
-361,25
+356,25
@@
__getcwd (char *buf, size_t size)
goto lose;
}
goto lose;
}
- if (
pathp == &path
[allocated - 1])
- *--
path
p = '/';
+ if (
dirp == &dir
[allocated - 1])
+ *--
dir
p = '/';
#ifndef AT_FDCWD
if (dotlist != dots)
free (dotlist);
#endif
#ifndef AT_FDCWD
if (dotlist != dots)
free (dotlist);
#endif
- used =
path + allocated - path
p;
- memmove (
path, path
p, used);
+ used =
dir + allocated - dir
p;
+ memmove (
dir, dir
p, used);
if (buf == NULL && size == 0)
/* Ensure that the buffer is only as large as necessary. */
if (buf == NULL && size == 0)
/* Ensure that the buffer is only as large as necessary. */
- buf = realloc (
path
, used);
+ buf = realloc (
dir
, used);
if (buf == NULL)
/* Either buf was NULL all along, or `realloc' failed but
we still have the original string. */
if (buf == NULL)
/* Either buf was NULL all along, or `realloc' failed but
we still have the original string. */
- buf =
path
;
+ buf =
dir
;
return buf;
return buf;
@@
-398,7
+393,7
@@
__getcwd (char *buf, size_t size)
free (dotlist);
#endif
if (buf == NULL)
free (dotlist);
#endif
if (buf == NULL)
- free (
path
);
+ free (
dir
);
__set_errno (save);
}
return NULL;
__set_errno (save);
}
return NULL;