]>
Commit | Line | Data |
---|---|---|
1f2f436a A |
1 | --- telldir.c.orig 2009-11-08 14:02:31.000000000 -0800 |
2 | +++ telldir.c 2009-11-08 14:02:24.000000000 -0800 | |
3 | @@ -50,7 +50,9 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/tel | |
3d9156a7 A |
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 | |
1f2f436a | 13 | @@ -61,14 +63,41 @@ telldir(dirp) |
3d9156a7 A |
14 | { |
15 | struct ddloc *lp; | |
16 | ||
17 | +#if __DARWIN_UNIX03 | |
18 | + if (__isthreaded) | |
1f2f436a | 19 | + _pthread_mutex_lock(&dirp->dd_lock); |
3d9156a7 | 20 | + LIST_FOREACH(lp, &dirp->dd_td->td_locq, loc_lqe) { |
224c7076 A |
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)) | |
3d9156a7 A |
28 | + goto found; |
29 | + } | |
30 | + if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL) { | |
31 | + if (__isthreaded) | |
1f2f436a | 32 | + _pthread_mutex_unlock(&dirp->dd_lock); |
3d9156a7 A |
33 | + return (-1); |
34 | + } | |
35 | +#else /* !__DARWIN_UNIX03 */ | |
36 | if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL) | |
37 | return (-1); | |
38 | if (__isthreaded) | |
1f2f436a | 39 | _pthread_mutex_lock(&dirp->dd_lock); |
3d9156a7 A |
40 | +#endif /* __DARWIN_UNIX03 */ |
41 | lp->loc_index = dirp->dd_td->td_loccnt++; | |
224c7076 A |
42 | +#if __DARWIN_64_BIT_INO_T |
43 | + lp->loc_seek = dirp->dd_td->seekoff; | |
44 | +#else /* !__DARWIN_64_BIT_INO_T */ | |
3d9156a7 | 45 | lp->loc_seek = dirp->dd_seek; |
224c7076 | 46 | +#endif /* __DARWIN_64_BIT_INO_T */ |
3d9156a7 A |
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) | |
1f2f436a | 53 | _pthread_mutex_unlock(&dirp->dd_lock); |
3d9156a7 | 54 | return (lp->loc_index); |
1f2f436a | 55 | @@ -92,23 +121,34 @@ _seekdir(dirp, loc) |
224c7076 A |
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) { | |
1f2f436a | 76 | dp = _readdir_unlocked(dirp, 0); |
3d9156a7 A |
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 | */ | |
1f2f436a | 92 | @@ -127,3 +167,4 @@ _reclaim_telldir(dirp) |
3d9156a7 A |
93 | } |
94 | LIST_INIT(&dirp->dd_td->td_locq); | |
95 | } | |
96 | +#endif /* !BUILDING_VARIANT */ |