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 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 * Questions or comments about this library should be sent to:
37 * Sandia National Laboratories, New Mexico
39 * Albuquerque, NM 87185-1110
51 #include <sys/types.h>
54 #include <sys/queue.h>
59 #include "sysio-symbols.h"
66 filldirents(struct file *fil,
67 char *buf, size_t nbytes,
68 _SYSIO_OFF_T *__restrict basep)
73 if (!S_ISDIR(fil->f_ino->i_stbuf.st_mode))
78 (*fil->f_ino->i_ops.inop_filldirentries)(fil->f_ino,
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);
105 cc = filldirents(fil, buf, nbytes, basep);
106 SYSIO_INTERFACE_RETURN(cc < 0 ? -1 : cc, cc < 0 ? (int )cc : 0);
109 #ifdef _LARGEFILE64_SOURCE
110 #undef getdirentries64
111 sysio_sym_strong_alias(PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries64)),
112 SYSIO_INTERFACE_NAME(getdirentries64))
117 #ifndef DIRENT64_IS_NATURAL
120 #define EOVERFLOW ERANGE
123 #ifdef _DIRENT_HAVE_D_NAMLEN
124 #define _namlen(dp) ((dp)->d_namlen)
126 #define _namlen(dp) (strlen((dp)->d_name))
130 #define _rndup(n, boundary) \
131 ((((n) + (boundary) - 1 ) / (boundary)) * (boundary))
134 #define _dbaselen ((size_t )&((struct dirent *)0)->d_name[0])
137 #define _dreclen(namlen) \
138 ((_dbaselen + (namlen) + __alignof__ (struct dirent)) & \
139 ~(__alignof__ (struct dirent) - 1))
140 #else /* !defined(__GLIBC__) */
141 #define _dreclen(namlen) \
142 _rndup(_dbaselen + (namlen) + 1, sizeof(int))
147 SYSIO_INTERFACE_NAME(getdirentries)(int fd,
150 off_t * __restrict basep)
153 SYSIO_INTERFACE_NAME(getdirentries)(int fd,
156 long * __restrict basep)
162 struct dirent64 *d64p, d64;
167 SYSIO_INTERFACE_DISPLAY_BLOCK;
169 SYSIO_INTERFACE_ENTER;
171 fil = _sysio_fd_find(fd);
172 if (!(fil && fil->f_ino)) {
173 SYSIO_INTERFACE_RETURN(-1, -EBADF);
176 count = cc = filldirents(fil, buf, nbytes, &b);
182 reclen = _dreclen(n);
183 d64.d_ino = d64p->d_ino;
184 d64.d_off = d64p->d_off;
185 d64.d_type = d64p->d_type;
186 d64.d_reclen = d64p->d_reclen;
190 (void )memcpy(dp->d_name, d64p->d_name, n);
194 dp->d_ino = d64.d_ino;
195 dp->d_off = d64.d_off;
196 if (dp->d_ino != d64.d_ino ||
197 dp->d_off != d64.d_off) {
199 * If conversion failure then we are done.
203 * Couldn't process any entries. We return
210 fil->f_pos = dp->d_off;
211 dp->d_type = d64.d_type;
212 dp->d_reclen = reclen;
214 * Fill the remainder with zeros.
216 p = (char *)dp + dp->d_reclen;
223 } while (cp < (char *)p);
229 d64p = (struct dirent64 *)((char *)d64p + d64.d_reclen);
233 SYSIO_INTERFACE_RETURN(-1, cc);
234 cc = (char *)dp - buf;
236 SYSIO_INTERFACE_RETURN(cc, 0);
238 #else /* !defined(DIRENT64_IS_NATURAL) */
239 sysio_sym_strong_alias(PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries64),
240 SYSIO_INTERFACE_NAME(getdirentries)))
244 #undef __getdirentries
245 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(getdirentries),
246 PREPEND(__, SYSIO_INTERFACE_NAME(getdirentries)))
248 #if defined(BSD) || defined(REDSTORM)
249 #undef _getdirentries
250 sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(getdirentries),
251 PREPEND(_, SYSIO_INTERFACE_NAME(getdirentries)))