4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
43 * readdir -- C library extension routine
46 #include <sys/feature_tests.h>
49 #pragma weak _readdir64 = readdir64
51 #pragma weak _readdir = readdir
65 dirent_t
*dp
; /* -> directory data */
68 if (dirp
->dd_size
!= 0) {
69 dp
= (dirent_t
*)(uintptr_t)&dirp
->dd_buf
[dirp
->dd_loc
];
70 saveloc
= dirp
->dd_loc
; /* save for possible EOF */
71 dirp
->dd_loc
+= (int)dp
->d_reclen
;
73 if (dirp
->dd_loc
>= dirp
->dd_size
)
74 dirp
->dd_loc
= dirp
->dd_size
= 0;
76 if (dirp
->dd_size
== 0 && /* refill buffer */
77 (dirp
->dd_size
= getdents(dirp
->dd_fd
,
78 (dirent_t
*)(uintptr_t)dirp
->dd_buf
, DIRBUF
)) <= 0) {
79 if (dirp
->dd_size
== 0) /* This means EOF */
80 dirp
->dd_loc
= saveloc
; /* so save for telldir */
81 return (NULL
); /* error or EOF */
84 return ((dirent_t
*)(uintptr_t)&dirp
->dd_buf
[dirp
->dd_loc
]);
90 * Welcome to the complicated world of large files on a small system.
96 dirent64_t
*dp64
; /* -> directory data */
99 if (dirp
->dd_size
!= 0) {
100 dp64
= (dirent64_t
*)(uintptr_t)&dirp
->dd_buf
[dirp
->dd_loc
];
101 /* was converted by readdir and needs to be reversed */
102 if (dp64
->d_ino
== (ino64_t
)-1) {
105 dp32
= (dirent_t
*)(&dp64
->d_off
);
106 dp64
->d_ino
= (ino64_t
)dp32
->d_ino
;
107 dp64
->d_off
= (off64_t
)dp32
->d_off
;
108 dp64
->d_reclen
= (unsigned short)(dp32
->d_reclen
+
109 ((char *)&dp64
->d_off
- (char *)dp64
));
111 saveloc
= dirp
->dd_loc
; /* save for possible EOF */
112 dirp
->dd_loc
+= (int)dp64
->d_reclen
;
114 if (dirp
->dd_loc
>= dirp
->dd_size
)
115 dirp
->dd_loc
= dirp
->dd_size
= 0;
117 if (dirp
->dd_size
== 0 && /* refill buffer */
118 (dirp
->dd_size
= getdents64(dirp
->dd_fd
,
119 (dirent64_t
*)(uintptr_t)dirp
->dd_buf
, DIRBUF
)) <= 0) {
120 if (dirp
->dd_size
== 0) /* This means EOF */
121 dirp
->dd_loc
= saveloc
; /* so save for telldir */
122 return (NULL
); /* error or EOF */
125 dp64
= (dirent64_t
*)(uintptr_t)&dirp
->dd_buf
[dirp
->dd_loc
];