author | Jon Tibble <meths@btinternet.com> |
Thu, 09 Dec 2010 22:32:39 +0100 | |
changeset 13255 | 4afa820d78b9 |
parent 6812 | febeba71273d |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
5 |
* Common Development and Distribution License (the "License"). |
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
6 |
* You may not use this file except in compliance with the License. |
0 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
21 |
|
0 | 22 |
/* |
6812 | 23 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
0 | 24 |
* Use is subject to license terms. |
25 |
*/ |
|
26 |
||
27 |
/* Copyright (c) 1988 AT&T */ |
|
28 |
/* All Rights Reserved */ |
|
29 |
||
6812 | 30 |
#pragma ident "%Z%%M% %I% %E% SMI" |
31 |
||
0 | 32 |
/* |
33 |
* seekdir -- C library extension routine |
|
34 |
*/ |
|
35 |
||
36 |
#include <sys/feature_tests.h> |
|
37 |
||
38 |
#if !defined(_LP64) |
|
6812 | 39 |
#pragma weak _seekdir64 = seekdir64 |
0 | 40 |
#endif |
6812 | 41 |
#pragma weak _seekdir = seekdir |
0 | 42 |
|
6812 | 43 |
#include "lint.h" |
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
44 |
#include "libc.h" |
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
45 |
#include <mtlib.h> |
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
46 |
#include <dirent.h> |
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
47 |
#include <fcntl.h> |
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
48 |
#include <unistd.h> |
0 | 49 |
|
50 |
#ifdef _LP64 |
|
51 |
||
52 |
void |
|
53 |
seekdir(DIR *dirp, long loc) |
|
54 |
{ |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
55 |
private_DIR *pdirp = (private_DIR *)dirp; |
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
56 |
dirent_t *dp; |
0 | 57 |
off_t off = 0; |
58 |
||
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
59 |
lmutex_lock(&pdirp->dd_lock); |
0 | 60 |
if (lseek(dirp->dd_fd, 0, SEEK_CUR) != 0) { |
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
61 |
dp = (dirent_t *)(uintptr_t)&dirp->dd_buf[dirp->dd_loc]; |
0 | 62 |
off = dp->d_off; |
63 |
} |
|
64 |
if (off != loc) { |
|
65 |
dirp->dd_loc = 0; |
|
66 |
(void) lseek(dirp->dd_fd, loc, SEEK_SET); |
|
67 |
dirp->dd_size = 0; |
|
68 |
||
69 |
/* |
|
70 |
* Save seek offset in d_off field, in case telldir |
|
71 |
* follows seekdir with no intervening call to readdir |
|
72 |
*/ |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
73 |
((dirent_t *)(uintptr_t)&dirp->dd_buf[0])->d_off = loc; |
0 | 74 |
} |
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
75 |
lmutex_unlock(&pdirp->dd_lock); |
0 | 76 |
} |
77 |
||
78 |
#else /* _LP64 */ |
|
79 |
||
4292
d7beef35913b
6518331 Eliminate duplicate addresses from ON ELF symbol sort sections
ab196087
parents:
3453
diff
changeset
|
80 |
/* |
d7beef35913b
6518331 Eliminate duplicate addresses from ON ELF symbol sort sections
ab196087
parents:
3453
diff
changeset
|
81 |
* Note: Instead of making this function static, we reduce it to local |
d7beef35913b
6518331 Eliminate duplicate addresses from ON ELF symbol sort sections
ab196087
parents:
3453
diff
changeset
|
82 |
* scope in the mapfile. That allows the linker to prevent it from |
d7beef35913b
6518331 Eliminate duplicate addresses from ON ELF symbol sort sections
ab196087
parents:
3453
diff
changeset
|
83 |
* appearing in the .SUNW_dynsymsort section. |
d7beef35913b
6518331 Eliminate duplicate addresses from ON ELF symbol sort sections
ab196087
parents:
3453
diff
changeset
|
84 |
*/ |
d7beef35913b
6518331 Eliminate duplicate addresses from ON ELF symbol sort sections
ab196087
parents:
3453
diff
changeset
|
85 |
void |
0 | 86 |
seekdir64(DIR *dirp, off64_t loc) |
87 |
{ |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
88 |
private_DIR *pdirp = (private_DIR *)(uintptr_t)dirp; |
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
89 |
dirent64_t *dp64; |
0 | 90 |
off64_t off = 0; |
91 |
||
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
92 |
lmutex_lock(&pdirp->dd_lock); |
0 | 93 |
if (lseek64(dirp->dd_fd, 0, SEEK_CUR) != 0) { |
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
94 |
dp64 = (dirent64_t *)(uintptr_t)&dirp->dd_buf[dirp->dd_loc]; |
0 | 95 |
/* was converted by readdir and needs to be reversed */ |
96 |
if (dp64->d_ino == (ino64_t)-1) { |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
97 |
dirent_t *dp32; |
0 | 98 |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
99 |
dp32 = (dirent_t *)((uintptr_t)dp64 + sizeof (ino64_t)); |
0 | 100 |
dp64->d_ino = (ino64_t)dp32->d_ino; |
101 |
dp64->d_off = (off64_t)dp32->d_off; |
|
102 |
dp64->d_reclen = (unsigned short)(dp32->d_reclen + |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
103 |
((char *)&dp64->d_off - (char *)dp64)); |
0 | 104 |
} |
105 |
off = dp64->d_off; |
|
106 |
} |
|
107 |
if (off != loc) { |
|
108 |
dirp->dd_loc = 0; |
|
109 |
(void) lseek64(dirp->dd_fd, loc, SEEK_SET); |
|
110 |
dirp->dd_size = 0; |
|
111 |
||
112 |
/* |
|
113 |
* Save seek offset in d_off field, in case telldir |
|
114 |
* follows seekdir with no intervening call to readdir |
|
115 |
*/ |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
116 |
((dirent64_t *)(uintptr_t)&dirp->dd_buf[0])->d_off = loc; |
0 | 117 |
} |
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
118 |
lmutex_unlock(&pdirp->dd_lock); |
0 | 119 |
} |
120 |
||
121 |
void |
|
122 |
seekdir(DIR *dirp, long loc) |
|
123 |
{ |
|
4382
46ce842d3d9d
6372775 NFS cookies with bit 31 and up set can trigger various tell/seekdir(3c) issues
fvdl
parents:
4292
diff
changeset
|
124 |
seekdir64(dirp, (off64_t)(uint32_t)loc); |
0 | 125 |
} |
126 |
||
127 |
#endif /* _LP64 */ |