Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2010-03-09 23:38:18 +0300
committerJeff Johnston <jjohnstn@redhat.com>2010-03-09 23:38:18 +0300
commitfab7d5988a0518e7c33a69799676453385c876f5 (patch)
tree0ec5a26bf40e73b3fc53863452188e523e7cd81b
parente8190d8fbf0071f1ad596ae2adb6826ddaf21d9c (diff)
2010-03-09 Jeff Johnston <jjohnstn@redhat.com>
* libc/posix/telldir.c (dd_loccnt): Change start index to be 1 instead of 0. (_seekdir): A loc of 0 now means rewind dir.
-rw-r--r--newlib/ChangeLog6
-rw-r--r--newlib/libc/posix/telldir.c57
2 files changed, 38 insertions, 25 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 578e297d9..c52f7bb0b 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,9 @@
+2010-03-09 Jeff Johnston <jjohnstn@redhat.com>
+
+ * libc/posix/telldir.c (dd_loccnt): Change start index to be 1
+ instead of 0.
+ (_seekdir): A loc of 0 now means rewind dir.
+
2010-03-08 Craig Howland <howland@LGSInnovations.com>
* libm/common/s_rint.c: Fix error when integral part had 18 bits and
diff --git a/newlib/libc/posix/telldir.c b/newlib/libc/posix/telldir.c
index 2e3736995..f2b1c79bd 100644
--- a/newlib/libc/posix/telldir.c
+++ b/newlib/libc/posix/telldir.c
@@ -67,7 +67,7 @@ struct ddloc {
#define NDIRHASH 32 /* Num of hash lists, must be a power of 2 */
#define LOCHASH(i) ((i)&(NDIRHASH-1))
-static long dd_loccnt; /* Index of entry for sequential readdir's */
+static long dd_loccnt = 1; /* Index of entry for sequential readdir's */
static struct ddloc *dd_hash[NDIRHASH]; /* Hash list heads for ddlocs */
__LOCK_INIT(static, dd_hash_lock);
@@ -123,35 +123,42 @@ _DEFUN(_seekdir, (dirp, loc),
#ifdef HAVE_DD_LOCK
__lock_acquire(dd_hash_lock);
#endif
- prevlp = &dd_hash[LOCHASH(loc)];
- lp = *prevlp;
- while (lp != NULL) {
- if (lp->loc_index == loc)
- break;
- prevlp = &lp->loc_next;
- lp = lp->loc_next;
- }
- if (lp == NULL) {
+ if (loc != 0) {
+ prevlp = &dd_hash[LOCHASH(loc)];
+ lp = *prevlp;
+ while (lp != NULL) {
+ if (lp->loc_index == loc)
+ break;
+ prevlp = &lp->loc_next;
+ lp = lp->loc_next;
+ }
+ if (lp == NULL) {
#ifdef HAVE_DD_LOCK
- __lock_release(dd_hash_lock);
+ __lock_release(dd_hash_lock);
#endif
- return;
- }
- if (lp->loc_loc == dirp->dd_loc && lp->loc_seek == dirp->dd_seek)
- goto found;
- (void) lseek(dirp->dd_fd, lp->loc_seek, 0);
- dirp->dd_seek = lp->loc_seek;
- dirp->dd_loc = 0;
- while (dirp->dd_loc < lp->loc_loc) {
- dp = readdir(dirp);
- if (dp == NULL)
- break;
- }
+ return;
+ }
+ if (lp->loc_loc == dirp->dd_loc && lp->loc_seek == dirp->dd_seek)
+ goto found;
+ (void) lseek(dirp->dd_fd, lp->loc_seek, 0);
+ dirp->dd_seek = lp->loc_seek;
+ dirp->dd_loc = 0;
+ while (dirp->dd_loc < lp->loc_loc) {
+ dp = readdir(dirp);
+ if (dp == NULL)
+ break;
+ }
found:
#ifdef SINGLEUSE
- *prevlp = lp->loc_next;
- free((caddr_t)lp);
+ *prevlp = lp->loc_next;
+ free((caddr_t)lp);
#endif
+ } else {
+ // loc 0 means rewinding
+ (void) lseek(dirp->dd_fd, 0, 0);
+ dirp->dd_seek = 0;
+ dirp->dd_loc = 0;
+ }
#ifdef HAVE_DD_LOCK
__lock_release(dd_hash_lock);
#endif