1 /* @(#)dirent.h 1.29 11/08/04 Copyright 1987, 1998, 2000-2011 J. Schilling */ 2 /* 3 * Copyright (c) 1987, 1998, 2000-2011 J. Schilling 4 */ 5 /* 6 * The contents of this file are subject to the terms of the 7 * Common Development and Distribution License, Version 1.0 only 8 * (the "License"). You may not use this file except in compliance 9 * with the License. 10 * 11 * See the file CDDL.Schily.txt in this distribution for details. 12 * A copy of the CDDL is also available via the Internet at 13 * http://www.opensource.org/licenses/cddl1.txt 14 * 15 * When distributing Covered Code, include this CDDL HEADER in each 16 * file and include the License file CDDL.Schily.txt from this distribution. 17 */ 18 19 #ifndef _SCHILY_DIRENT_H 20 #define _SCHILY_DIRENT_H 21 22 #ifndef _SCHILY_MCONFIG_H 23 #include <schily/mconfig.h> 24 #endif 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 #ifdef JOS 31 # ifdef HAVE_SYS_STYPES_H 32 # ifndef _INCL_SYS_STYPES_H 33 # include <sys/stypes.h> 34 # define _INCL_SYS_STYPES_H 35 # endif 36 # endif 37 # ifdef HAVE_SYS_FILEDESC_H 38 # ifndef _INCL_SYS_FILEDESC_H 39 # include <sys/filedesc.h> 40 # define _INCL_SYS_FILEDESC_H 41 # endif 42 # endif 43 # define NEED_READDIR 44 # define dirent _direct 45 # define DIR_NAMELEN(dirent) strlen((dirent)->d_name) 46 # define DIRSIZE 30 47 # define FOUND_DIRSIZE 48 typedef struct _dirent { 49 char name[DIRSIZE]; 50 short ino; 51 } dirent; 52 53 #else /* !JOS */ 54 55 # ifndef _SCHILY_TYPES_H 56 # include <schily/types.h> 57 # endif 58 # ifndef _SCHILY_STAT_H 59 # include <schily/stat.h> 60 # endif 61 # ifndef _SCHILY_LIMITS_H 62 # include <schily/limits.h> 63 # endif 64 # ifndef _SCHILY_PARAM_H 65 # include <schily/param.h> 66 # endif 67 # ifndef _SCHILY_STDLIB_H 68 # include <schily/stdlib.h> /* MSVC: get _MAX_DIR */ 69 # endif 70 71 # ifdef HAVE_DIRENT_H /* This a POSIX compliant system */ 72 # ifndef _INCL_DIRENT_H 73 # include <dirent.h> 74 # define _INCL_DIRENT_H 75 # endif 76 # define DIR_NAMELEN(dirent) strlen((dirent)->d_name) 77 # define _FOUND_DIR_ 78 # else /* This is a Pre POSIX system */ 79 80 # define dirent direct 81 # define DIR_NAMELEN(dirent) (dirent)->d_namlen 82 83 # if defined(HAVE_SYS_DIR_H) 84 # ifndef _INCL_SYS_DIR_H 85 # include <sys/dir.h> 86 # define _INCL_SYS_DIR_H 87 # endif 88 # define _FOUND_DIR_ 89 # endif 90 91 # if defined(HAVE_NDIR_H) && !defined(_FOUND_DIR_) 92 # ifndef _INCL_NDIR_H 93 # include <ndir.h> 94 # define _INCL_NDIR_H 95 # endif 96 # define _FOUND_DIR_ 97 # endif 98 99 # if defined(HAVE_SYS_NDIR_H) && !defined(_FOUND_DIR_) 100 # ifndef _INCL_SYS_NDIR_H 101 # include <sys/ndir.h> 102 # define _INCL_SYS_NDIR_H 103 # endif 104 # define _FOUND_DIR_ 105 # endif 106 # endif /* HAVE_DIRENT_H */ 107 108 # if defined(_FOUND_DIR_) 109 /* 110 * Don't use defaults here to allow recognition of problems. 111 */ 112 # if !defined(FOUND_DIRSIZE) && defined(MAXNAMELEN) 113 # define DIRSIZE MAXNAMELEN /* From sys/param.h */ 114 # define FOUND_DIRSIZE 115 # endif 116 117 # if !defined(FOUND_DIRSIZE) && defined(MAXNAMLEN) 118 # define DIRSIZE MAXNAMLEN /* From dirent.h */ 119 # define FOUND_DIRSIZE 120 # endif 121 122 # ifdef __never__ 123 /* 124 * DIRSIZ(dp) is a parameterized macro, we cannot use it here. 125 */ 126 # if !defined(FOUND_DIRSIZE) && defined(DIRSIZ) 127 # define DIRSIZE DIRSIZ /* From sys/dir.h */ 128 # define FOUND_DIRSIZE 129 # endif 130 # endif /* __never__ */ 131 132 # if !defined(FOUND_DIRSIZE) && defined(NAME_MAX) 133 # define DIRSIZE NAME_MAX /* From limits.h */ 134 # define FOUND_DIRSIZE 135 # endif 136 137 # else /* !_FOUND_DIR_ */ 138 139 # if !defined(FOUND_DIRSIZE) && defined(_MAX_DIR) 140 # if defined(__MINGW32__) || defined(_MSC_VER) 141 # define DIRSIZE _MAX_DIR /* From stdlib.h */ 142 # define FOUND_DIRSIZE 143 # define NEED_READDIR 144 # undef dirent 145 # define dirent _direct 146 # undef DIR_NAMELEN 147 # define DIR_NAMELEN(dirent) strlen((dirent)->d_name) 148 # endif 149 # endif 150 151 # ifndef NEED_READDIR 152 # define NEED_DIRENT 153 # define NEED_READDIR 154 # undef dirent 155 # define dirent _direct 156 # undef DIR_NAMELEN 157 # define DIR_NAMELEN(dirent) strlen((dirent)->d_name) 158 # endif /* !NEED_READDIR */ 159 160 # endif /* _FOUND_DIR_ */ 161 162 163 #ifdef NEED_DIRENT 164 165 #ifndef FOUND_DIRSIZE 166 #define DIRSIZE 14 /* The old UNIX standard value */ 167 #define FOUND_DIRSIZE 168 #endif 169 170 typedef struct _dirent { 171 short ino; 172 char name[DIRSIZE]; 173 } dirent; 174 175 #endif /* NEED_DIRENT */ 176 177 #endif /* !JOS */ 178 179 #ifdef NEED_READDIR 180 181 #ifndef _SCHILY_STDIO_H 182 #include <schily/stdio.h> 183 #endif 184 #if defined(__MINGW32__) || defined(_MSC_VER) 185 #ifndef _SCHILY_IO_H 186 #include <schily/io.h> /* for _findfirst() */ 187 #endif 188 #ifndef _SCHILY_UTYPES_H 189 #include <schily/utypes.h> 190 #endif 191 #endif 192 193 struct _direct { 194 unsigned long d_ino; 195 unsigned short d_reclen; 196 unsigned short d_namlen; 197 char d_name[DIRSIZE +1]; 198 }; 199 #define HAVE_DIRENT_D_INO 200 201 typedef struct __dirdesc { 202 FILE *dd_fd; 203 204 #if defined(__MINGW32__) || defined(_MSC_VER) 205 struct _direct dd_dir; /* dirent for this dir */ 206 struct _finddata_t dd_data; /* _findnext() results */ 207 intptr_t dd_handle; /* _findnext() handle */ 208 int dd_state; /* Current Dir state */ 209 char dd_dirname[1]; /* Dir to open */ 210 #endif 211 } DIR; 212 213 extern DIR *opendir __PR((const char *)); 214 extern int closedir __PR((DIR *)); 215 extern struct dirent *readdir __PR((DIR *)); 216 217 #endif /* NEED_READDIR */ 218 219 #if !defined(HAVE_DIRFD) && defined(HAVE_DIR_DD_FD) 220 # define dirfd(dirp) ((dirp)->dd_fd) 221 #endif 222 223 #ifdef __cplusplus 224 } 225 #endif 226 227 #endif /* _SCHILY_DIRENT_H */ 228