2 * This Cplant(TM) source code is the property of Sandia National
5 * This Cplant(TM) source code is copyrighted by Sandia National
8 * The redistribution of this Cplant(TM) source code is subject to the
9 * terms of the GNU Lesser General Public License
10 * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
12 * Cplant(TM) Copyright 1998-2004 Sandia Corporation.
13 * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
14 * license for use of this work by or on behalf of the US Government.
15 * Export of this program may require a license from the United States
20 * #############################################################################
22 * # This Cplant(TM) source code is the property of Sandia National
25 * # This Cplant(TM) source code is copyrighted by Sandia National
28 * # The redistribution of this Cplant(TM) source code is subject to the
29 * # terms of the GNU Lesser General Public License
30 * # (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
32 * # Cplant(TM) Copyright 1998-2004 Sandia Corporation.
33 * # Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
34 * # license for use of this work by or on behalf of the US Government.
35 * # Export of this program may require a license from the United States
38 * #############################################################################
42 * This library is free software; you can redistribute it and/or
43 * modify it under the terms of the GNU Lesser General Public
44 * License as published by the Free Software Foundation; either
45 * version 2.1 of the License, or (at your option) any later version.
47 * This library is distributed in the hope that it will be useful,
48 * but WITHOUT ANY WARRANTY; without even the implied warranty of
49 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
50 * Lesser General Public License for more details.
52 * You should have received a copy of the GNU Lesser General Public
53 * License along with this library; if not, write to the Free Software
54 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
56 * Questions or comments about this library should be sent to:
59 * Sandia National Laboratories, New Mexico
61 * Albuquerque, NM 87185-1110
73 #include <sys/types.h>
76 #include <sys/queue.h>
81 #include "sysio-symbols.h"
88 filldirents(struct file *fil,
89 char *buf, size_t nbytes,
90 _SYSIO_OFF_T *__restrict basep)
95 if (!S_ISDIR(fil->f_ino->i_stbuf.st_mode))
100 (*fil->f_ino->i_ops.inop_filldirentries)(fil->f_ino,
110 PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries64))(int fd,
113 _SYSIO_OFF_T * __restrict
118 SYSIO_INTERFACE_DISPLAY_BLOCK;
120 SYSIO_INTERFACE_ENTER;
122 fil = _sysio_fd_find(fd);
123 if (!(fil && fil->f_ino))
126 cc = filldirents(fil, buf, nbytes, basep);
127 SYSIO_INTERFACE_RETURN(cc < 0 ? -1 : cc, cc < 0 ? (int )cc : 0);
130 #if _LARGEFILE64_SOURCE
131 #undef getdirentries64
132 sysio_sym_strong_alias(PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries64)),
133 SYSIO_INTERFACE_NAME(getdirentries64))
138 #ifndef DIRENT64_IS_NATURAL
141 #define EOVERFLOW ERANGE
144 #ifdef _DIRENT_HAVE_D_NAMLEN
145 #define _namlen(dp) ((dp)->d_namlen)
147 #define _namlen(dp) (strlen((dp)->d_name))
151 #define _rndup(n, boundary) \
152 ((((n) + (boundary) - 1 ) / (boundary)) * (boundary))
155 #define _dbaselen ((size_t )&((struct dirent *)0)->d_name[0])
158 #define _dreclen(namlen) \
159 ((_dbaselen + (namlen) + __alignof__ (struct dirent)) & \
160 ~(__alignof__ (struct dirent) - 1))
161 #else /* !defined(__GLIBC__) */
162 #define _dreclen(namlen) \
163 _rndup(_dbaselen + (namlen) + 1, sizeof(int))
168 SYSIO_INTERFACE_NAME(getdirentries)(int fd,
171 off_t * __restrict basep)
174 SYSIO_INTERFACE_NAME(getdirentries)(int fd,
177 long * __restrict basep)
183 struct dirent64 *d64p, d64;
188 SYSIO_INTERFACE_DISPLAY_BLOCK;
190 SYSIO_INTERFACE_ENTER;
192 fil = _sysio_fd_find(fd);
193 if (!(fil && fil->f_ino))
196 count = cc = filldirents(fil, buf, nbytes, &b);
202 reclen = _dreclen(n);
203 d64.d_ino = d64p->d_ino;
204 d64.d_off = d64p->d_off;
205 d64.d_type = d64p->d_type;
206 d64.d_reclen = d64p->d_reclen;
210 (void )memcpy(dp->d_name, d64p->d_name, n);
214 dp->d_ino = d64.d_ino;
215 dp->d_off = d64.d_off;
216 if (dp->d_ino != d64.d_ino ||
217 dp->d_off != d64.d_off) {
219 * If conversion failure then we are done.
223 * Couldn't process any entries. We return
230 fil->f_pos = dp->d_off;
231 dp->d_type = d64.d_type;
232 dp->d_reclen = reclen;
234 * Fill the remainder with zeros.
236 p = (char *)dp + dp->d_reclen;
243 } while (cp < (char *)p);
249 d64p = (struct dirent64 *)((char *)d64p + d64.d_reclen);
253 SYSIO_INTERFACE_RETURN(-1, cc);
254 cc = (char *)dp - buf;
256 SYSIO_INTERFACE_RETURN(cc, 0);
258 #else /* !defined(DIRENT64_IS_NATURAL) */
259 sysio_sym_strong_alias(PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries64),
260 SYSIO_INTERFACE_NAME(getdirentries)))
264 #undef __getdirentries
265 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(getdirentries),
266 PREPEND(__, SYSIO_INTERFACE_NAME(getdirentries)))
268 #if defined(BSD) || defined(REDSTORM)
269 #undef _getdirentries
270 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(getdirentries),
271 PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries)))