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 |
* telldir -- C library extension routine |
|
34 |
*/ |
|
35 |
||
36 |
#include <sys/isa_defs.h> |
|
37 |
||
38 |
#if !defined(_LP64) |
|
6812 | 39 |
#pragma weak _telldir64 = telldir64 |
0 | 40 |
#endif |
6812 | 41 |
#pragma weak _telldir = telldir |
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" |
0 | 45 |
#include <mtlib.h> |
46 |
#include <dirent.h> |
|
47 |
#include <errno.h> |
|
48 |
#include <limits.h> |
|
49 |
#include <fcntl.h> |
|
50 |
#include <unistd.h> |
|
51 |
||
52 |
#ifdef _LP64 |
|
53 |
||
54 |
long |
|
55 |
telldir(DIR *dirp) |
|
56 |
{ |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
57 |
private_DIR *pdirp = (private_DIR *)dirp; |
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
58 |
dirent_t *dp; |
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
59 |
off_t off = 0; |
0 | 60 |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
61 |
lmutex_lock(&pdirp->dd_lock); |
0 | 62 |
/* if at beginning of dir, return 0 */ |
63 |
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
|
64 |
dp = (dirent_t *)(uintptr_t)(&dirp->dd_buf[dirp->dd_loc]); |
0 | 65 |
off = dp->d_off; |
66 |
} |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
67 |
lmutex_unlock(&pdirp->dd_lock); |
0 | 68 |
return (off); |
69 |
} |
|
70 |
||
71 |
#else |
|
72 |
||
4292
d7beef35913b
6518331 Eliminate duplicate addresses from ON ELF symbol sort sections
ab196087
parents:
3453
diff
changeset
|
73 |
/* |
d7beef35913b
6518331 Eliminate duplicate addresses from ON ELF symbol sort sections
ab196087
parents:
3453
diff
changeset
|
74 |
* 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
|
75 |
* 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
|
76 |
* appearing in the .SUNW_dynsymsort section. |
d7beef35913b
6518331 Eliminate duplicate addresses from ON ELF symbol sort sections
ab196087
parents:
3453
diff
changeset
|
77 |
*/ |
d7beef35913b
6518331 Eliminate duplicate addresses from ON ELF symbol sort sections
ab196087
parents:
3453
diff
changeset
|
78 |
off64_t |
0 | 79 |
telldir64(DIR *dirp) |
80 |
{ |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
81 |
private_DIR *pdirp = (private_DIR *)(uintptr_t)dirp; |
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
82 |
dirent64_t *dp64; |
0 | 83 |
off64_t off = 0; |
84 |
||
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
85 |
lmutex_lock(&pdirp->dd_lock); |
0 | 86 |
/* if at beginning of dir, return 0 */ |
87 |
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
|
88 |
dp64 = (dirent64_t *)(uintptr_t)(&dirp->dd_buf[dirp->dd_loc]); |
0 | 89 |
/* was converted by readdir and needs to be reversed */ |
90 |
if (dp64->d_ino == (ino64_t)-1) { |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
91 |
dirent_t *dp32; |
0 | 92 |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
93 |
dp32 = (dirent_t *)((uintptr_t)dp64 + sizeof (ino64_t)); |
0 | 94 |
dp64->d_ino = (ino64_t)dp32->d_ino; |
95 |
dp64->d_off = (off64_t)dp32->d_off; |
|
96 |
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
|
97 |
((char *)&dp64->d_off - (char *)dp64)); |
0 | 98 |
} |
99 |
off = dp64->d_off; |
|
100 |
} |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
101 |
lmutex_unlock(&pdirp->dd_lock); |
0 | 102 |
return (off); |
103 |
} |
|
104 |
||
105 |
long |
|
106 |
telldir(DIR *dirp) |
|
107 |
{ |
|
108 |
off64_t off; |
|
109 |
||
110 |
off = telldir64(dirp); |
|
111 |
||
112 |
/* |
|
113 |
* Make sure that the offset fits in 32 bits. |
|
114 |
*/ |
|
3453
bc3a776612a0
6513772 readdir_r() and associates should use per-DIR locking
raf
parents:
0
diff
changeset
|
115 |
if ((long)off != off && (uint64_t)off > (uint64_t)UINT32_MAX) { |
0 | 116 |
errno = EOVERFLOW; |
117 |
return (-1); |
|
118 |
} |
|
119 |
return ((long)off); |
|
120 |
} |
|
121 |
||
122 |
#endif /* _LP64 */ |