]> git.saurik.com Git - apple/libc.git/blob - gen/FreeBSD/telldir.c.patch
Libc-594.1.4.tar.gz
[apple/libc.git] / gen / FreeBSD / telldir.c.patch
1 --- telldir.c.orig 2007-01-24 14:10:41.000000000 -0800
2 +++ telldir.c 2007-01-27 02:51:57.000000000 -0800
3 @@ -54,7 +54,9 @@
4 * cookie may be used only once before it is freed. This option
5 * is used to avoid having memory usage grow without bound.
6 */
7 +#if !__DARWIN_UNIX03
8 #define SINGLEUSE
9 +#endif /* !__DARWIN_UNIX03 */
10
11 /*
12 * return a pointer into a directory
13 @@ -65,14 +67,41 @@
14 {
15 struct ddloc *lp;
16
17 +#if __DARWIN_UNIX03
18 + if (__isthreaded)
19 + _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock);
20 + LIST_FOREACH(lp, &dirp->dd_td->td_locq, loc_lqe) {
21 + if (
22 +#if __DARWIN_64_BIT_INO_T
23 + (lp->loc_seek == dirp->dd_td->seekoff)
24 +#else /* !__DARWIN_64_BIT_INO_T */
25 + (lp->loc_seek == dirp->dd_seek)
26 +#endif /* __DARWIN_64_BIT_INO_T */
27 + && (lp->loc_loc == dirp->dd_loc))
28 + goto found;
29 + }
30 + if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL) {
31 + if (__isthreaded)
32 + _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock);
33 + return (-1);
34 + }
35 +#else /* !__DARWIN_UNIX03 */
36 if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL)
37 return (-1);
38 if (__isthreaded)
39 _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock);
40 +#endif /* __DARWIN_UNIX03 */
41 lp->loc_index = dirp->dd_td->td_loccnt++;
42 +#if __DARWIN_64_BIT_INO_T
43 + lp->loc_seek = dirp->dd_td->seekoff;
44 +#else /* !__DARWIN_64_BIT_INO_T */
45 lp->loc_seek = dirp->dd_seek;
46 +#endif /* __DARWIN_64_BIT_INO_T */
47 lp->loc_loc = dirp->dd_loc;
48 LIST_INSERT_HEAD(&dirp->dd_td->td_locq, lp, loc_lqe);
49 +#if __DARWIN_UNIX03
50 +found:
51 +#endif /* __DARWIN_UNIX03 */
52 if (__isthreaded)
53 _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock);
54 return (lp->loc_index);
55 @@ -96,23 +125,34 @@
56 }
57 if (lp == NULL)
58 return;
59 - if (lp->loc_loc == dirp->dd_loc && lp->loc_seek == dirp->dd_seek)
60 + if (lp->loc_loc == dirp->dd_loc &&
61 +#if __DARWIN_64_BIT_INO_T
62 + lp->loc_seek == dirp->dd_td->seekoff
63 +#else /* !__DARWIN_64_BIT_INO_T */
64 + lp->loc_seek == dirp->dd_seek
65 +#endif /* __DARWIN_64_BIT_INO_T */
66 + )
67 goto found;
68 (void) lseek(dirp->dd_fd, (off_t)lp->loc_seek, SEEK_SET);
69 +#if __DARWIN_64_BIT_INO_T
70 + dirp->dd_td->seekoff = lp->loc_seek;
71 +#else /* !__DARWIN_64_BIT_INO_T */
72 dirp->dd_seek = lp->loc_seek;
73 +#endif /* __DARWIN_64_BIT_INO_T */
74 dirp->dd_loc = 0;
75 while (dirp->dd_loc < lp->loc_loc) {
76 dp = _readdir_unlocked(dirp);
77 if (dp == NULL)
78 break;
79 }
80 -found:
81 +found:;
82 #ifdef SINGLEUSE
83 LIST_REMOVE(lp, loc_lqe);
84 free((caddr_t)lp);
85 #endif
86 }
87
88 +#ifndef BUILDING_VARIANT
89 /*
90 * Reclaim memory for telldir cookies which weren't used.
91 */
92 @@ -131,3 +171,4 @@
93 }
94 LIST_INIT(&dirp->dd_td->td_locq);
95 }
96 +#endif /* !BUILDING_VARIANT */