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 PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries64))(int fd,
91 _SYSIO_OFF_T * __restrict
96 SYSIO_INTERFACE_DISPLAY_BLOCK;
98 SYSIO_INTERFACE_ENTER;
100 fil = _sysio_fd_find(fd);
101 if (!(fil && fil->f_ino))
102 SYSIO_INTERFACE_RETURN(-1, -EBADF);
104 if (!S_ISDIR(fil->f_ino->i_stbuf.st_mode))
105 SYSIO_INTERFACE_RETURN(-1, -ENOTDIR);
108 (*fil->f_ino->i_ops.inop_getdirentries)(fil->f_ino,
112 SYSIO_INTERFACE_RETURN(cc < 0 ? -1 : cc, cc < 0 ? (int )cc : 0);
115 #if _LARGEFILE64_SOURCE
116 #undef getdirentries64
117 sysio_sym_strong_alias(PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries64)),
118 SYSIO_INTERFACE_NAME(getdirentries64))
123 #ifndef DIRENT64_IS_NATURAL
126 #define EOVERFLOW ERANGE
129 #ifdef _DIRENT_HAVE_D_NAMLEN
130 #define _namlen(dp) ((dp)->d_namlen)
132 #define _namlen(dp) (strlen((dp)->d_name))
136 #define _rndup(n, boundary) \
137 ((((n) + (boundary) - 1 ) / (boundary)) * (boundary))
142 SYSIO_INTERFACE_NAME(getdirentries)(int fd,
145 off_t * __restrict basep)
148 SYSIO_INTERFACE_NAME(getdirentries)(int fd,
151 long * __restrict basep)
158 struct dirent *dp, *nxtdp;
162 struct intnl_dirent *od64p, *d64p;
166 SYSIO_INTERFACE_DISPLAY_BLOCK;
168 #define _dbaselen ((size_t )&((struct dirent *)0)->d_name[0])
171 #define _dreclen(namlen) \
172 ((_dbaselen + (namlen) + __alignof__ (struct dirent)) & \
173 ~(__alignof__ (struct dirent) - 1))
174 #else /* !defined(__GLIBC__) */
175 #define _dreclen(namlen) \
176 _rndup(_dbaselen + (namlen) + 1, sizeof(int))
179 #if defined(__GLIBC__)
180 #define _fast_alloc(n) alloca(n)
181 #define _fast_free(p)
182 #else /* !defined(__GLIBC__) */
183 #define _fast_alloc(n) malloc(n)
184 #define _fast_free(p) free(p)
187 SYSIO_INTERFACE_ENTER;
190 SYSIO_INTERFACE_RETURN(-1, -EINVAL);
194 if (inbytes > 8 * 1024) {
200 ibuf = _fast_alloc(inbytes);
202 SYSIO_INTERFACE_RETURN(-1, -ENOMEM);
204 dp = (struct dirent *)buf;
208 PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries64))(fd,
216 *basep = (off_t )ibase;
217 if (sizeof(*basep) != sizeof(ibase) && *basep != ibase) {
233 n = strlen(d64p->d_name);
235 reclen = _dreclen(n);
236 if (reclen >= (unsigned )nbytes)
238 dp->d_ino = (ino_t )d64p->d_ino;
240 dp->d_off = (off_t )d64p->d_off;
242 if ((sizeof(dp->d_ino) != sizeof(d64p->d_ino) &&
243 dp->d_ino != d64p->d_ino)
246 (sizeof(dp->d_off) != sizeof(d64p->d_off) &&
247 dp->d_off != d64p->d_off)
249 (off + (int )reclen < off)
255 dp->d_type = d64p->d_type;
256 dp->d_reclen = reclen;
257 nxtdp = (struct dirent *)((char *)dp + dp->d_reclen);
258 (void )memcpy(dp->d_name, d64p->d_name, n);
259 for (cp = dp->d_name + n; cp < (char *)nxtdp; *cp++ = '\0')
261 cc -= d64p->d_reclen;
263 d64p = (struct dirent64 *)((char *)d64p + d64p->d_reclen);
274 if (dp == (struct dirent *)buf && cc < 0)
275 SYSIO_INTERFACE_RETURN(-1, (int )cc);
276 cc = (char *)dp - buf;
284 SYSIO_INTERFACE_RETURN(cc, 0);
293 #else /* !defined(DIRENT64_IS_NATURAL) */
294 sysio_sym_strong_alias(PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries64),
295 SYSIO_INTERFACE_NAME(getdirentries)))
299 #undef __getdirentries
300 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(getdirentries),
301 PREPEND(__, SYSIO_INTERFACE_NAME(getdirentries)))
303 #if defined(BSD) || defined(REDSTORM)
304 #undef _getdirentries
305 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(getdirentries),
306 PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries)))