dirent.h (2559B)
1 /* -*-comment-start: "//";comment-end:""-*- 2 * GNU Mes --- Maxwell Equations of Software 3 * Copyright (C) 1991, 1992 Free Software Foundation, Inc. 4 * Copyright © 2018,2024 Janneke Nieuwenhuizen <janneke@gnu.org> 5 * Copyright © 2024 Andrius Štikonas <andrius@stikonas.eu> 6 * 7 * This file is part of GNU Mes. 8 * 9 * GNU Mes is free software; you can redistribute it and/or modify it 10 * under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 3 of the License, or (at 12 * your option) any later version. 13 * 14 * GNU Mes is distributed in the hope that it will be useful, but 15 * WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 #ifndef __MES_DIRENT_H 24 #define __MES_DIRENT_H 1 25 26 #if SYSTEM_LIBC 27 #ifndef _GNU_SOURCE 28 #define _GNU_SOURCE 29 #endif 30 #undef __MES_DIRENT_H 31 #include_next <dirent.h> 32 33 #else // ! SYSTEM_LIBC 34 35 #include <arch/syscall.h> 36 #include <dirstream.h> 37 38 // Taken from GNU C Library 1.06.4, 2.2.5 39 40 /* 41 * POSIX Standard: 5.1.2 Directory Operations <dirent.h> 42 */ 43 44 #include <stddef.h> 45 46 int __getdirentries (int filedes, char *buffer, size_t nbytes, off_t * basep); 47 48 // FIXME move to include/<kernel>/<arch>/dirent.h? 49 struct dirent 50 { 51 ino_t d_ino; 52 #if defined (SYS_getdents64) && (__SIZEOF_LONG__ == 4 || __arm__ || __i386__) 53 // FIXME: redefine ino_t to ino64_t instead? 54 int d_ino_h; 55 #endif 56 off_t d_off; 57 #if defined (SYS_getdents64) && (__SIZEOF_LONG__ == 4 || __arm__ || __i386__) 58 // FIXME: redefine off_t to off64_t instead? 59 int d_off_h; 60 #endif 61 unsigned short int d_reclen; 62 #if defined (SYS_getdents64) 63 unsigned char d_type; 64 #endif 65 char d_name[256]; 66 }; 67 68 /* Open a directory stream on NAME. 69 Return a DIR stream on the directory, or NULL if it could not be opened. */ 70 DIR *opendir (char const *name); 71 72 /* Close the directory stream DIRP. 73 Return 0 if successful, -1 if not. */ 74 int closedir (DIR * dirp); 75 76 /* Read a directory entry from DIRP. 77 Return a pointer to a `struct dirent' describing the entry, 78 or NULL for EOF or error. The storage returned may be overwritten 79 by a later readdir call on the same DIR stream. */ 80 struct dirent *readdir (DIR * dirp); 81 82 /* Rewind DIRP to the beginning of the directory. */ 83 extern void rewinddir (DIR * dirp); 84 85 #endif // ! SYSTEM_LIBC 86 87 #endif // __MES_DIRENT_H