| 1 |
/**************************************************************************/ |
| 2 |
/* */ |
| 3 |
/* This file is part of Frama-C. */ |
| 4 |
/* */ |
| 5 |
/* Copyright (C) 2007-2022 */ |
| 6 |
/* CEA (Commissariat à l'énergie atomique et aux énergies */ |
| 7 |
/* alternatives) */ |
| 8 |
/* */ |
| 9 |
/* you can redistribute it and/or modify it under the terms of the GNU */ |
| 10 |
/* Lesser General Public License as published by the Free Software */ |
| 11 |
/* Foundation, version 2.1. */ |
| 12 |
/* */ |
| 13 |
/* It is distributed in the hope that it will be useful, */ |
| 14 |
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 15 |
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
| 16 |
/* GNU Lesser General Public License for more details. */ |
| 17 |
/* */ |
| 18 |
/* See the GNU Lesser General Public License version 2.1 */ |
| 19 |
/* for more details (enclosed in the file licenses/LGPLv2.1). */ |
| 20 |
/* */ |
| 21 |
/**************************************************************************/ |
| 22 |
|
| 23 |
#ifndef __FC_DIRENT_H |
| 24 |
#define __FC_DIRENT_H |
| 25 |
#include "features.h" |
| 26 |
__PUSH_FC_STDLIB |
| 27 |
|
| 28 |
#include "errno.h" |
| 29 |
|
| 30 |
#include "__fc_define_ino_t.h" |
| 31 |
#include "__fc_define_off_t.h" |
| 32 |
|
| 33 |
__BEGIN_DECLS |
| 34 |
|
| 35 |
struct dirent { |
| 36 |
ino_t d_ino; /* inode number */ |
| 37 |
off_t d_off; /* offset to the next dirent */ |
| 38 |
unsigned short d_reclen; /* length of this record */ |
| 39 |
unsigned char d_type; /* type of file; not supported |
| 40 |
by all file system types */ |
| 41 |
char d_name[256]; /* filename */ |
| 42 |
}; |
| 43 |
|
| 44 |
typedef struct DIR { |
| 45 |
unsigned int __fc_dir_id; |
| 46 |
unsigned int __fc_dir_position; |
| 47 |
struct stat* __fc_dir_inode; |
| 48 |
struct dirent ** __fc_dir_entries; |
| 49 |
} DIR; |
| 50 |
|
| 51 |
DIR __fc_opendir[__FC_FOPEN_MAX]; |
| 52 |
DIR* const __fc_p_opendir = __fc_opendir; |
| 53 |
|
| 54 |
extern int alphasort(const struct dirent **, const struct dirent **); |
| 55 |
|
| 56 |
/*@ |
| 57 |
requires dirp_valid_dir_stream: \subset(dirp,&__fc_opendir[0 .. __FC_FOPEN_MAX-1]); |
| 58 |
assigns \result \from dirp, *dirp, __fc_p_opendir; |
| 59 |
assigns __fc_errno \from dirp, *dirp, __fc_p_opendir; |
| 60 |
assigns *dirp \from dirp, *dirp, __fc_p_opendir; |
| 61 |
ensures err_or_closed_on_success: |
| 62 |
(\result == 0 && dirp->__fc_dir_inode == \null) || \result == -1; |
| 63 |
*/ |
| 64 |
extern int closedir(DIR *dirp); |
| 65 |
extern int dirfd(DIR *); |
| 66 |
extern DIR *fdopendir(int); |
| 67 |
|
| 68 |
/*@ |
| 69 |
assigns \result \from path[0..], __fc_p_opendir; |
| 70 |
assigns __fc_errno \from path[0..], __fc_p_opendir; |
| 71 |
ensures result_null_or_valid: \result == \null || \valid(\result); |
| 72 |
ensures valid_dir_stream_on_success: |
| 73 |
\result != \null ==> \result == &__fc_opendir[\result->__fc_dir_id]; |
| 74 |
ensures stream_positioned_on_success: |
| 75 |
\result != \null ==> \result->__fc_dir_inode != \null; |
| 76 |
*/ |
| 77 |
extern DIR *opendir(const char *path); |
| 78 |
|
| 79 |
/*@ |
| 80 |
requires dirp_valid_dir_stream: \subset(dirp, &__fc_opendir[0 .. __FC_FOPEN_MAX-1]); |
| 81 |
assigns \result \from *dirp, __fc_p_opendir; |
| 82 |
assigns dirp->__fc_dir_position \from dirp->__fc_dir_position; |
| 83 |
assigns __fc_errno \from dirp, *dirp, __fc_p_opendir; |
| 84 |
ensures result_null_or_valid: \result == \null || \valid(\result); |
| 85 |
*/ |
| 86 |
extern struct dirent *readdir(DIR *dirp); |
| 87 |
|
| 88 |
extern int readdir_r(DIR * dirp, struct dirent * entry, |
| 89 |
struct dirent ** result); |
| 90 |
extern void rewinddir(DIR *); |
| 91 |
extern int scandir(const char *, struct dirent ***, |
| 92 |
int (*)(const struct dirent *), |
| 93 |
int (*)(const struct dirent **, |
| 94 |
const struct dirent **)); |
| 95 |
|
| 96 |
extern void seekdir(DIR *, long); |
| 97 |
extern long telldir(DIR *); |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
/* File types for `d_type'. */ |
| 102 |
enum __fc_readdir_dtype |
| 103 |
{ |
| 104 |
DT_UNKNOWN = 0, |
| 105 |
# define DT_UNKNOWN DT_UNKNOWN |
| 106 |
DT_FIFO = 1, |
| 107 |
# define DT_FIFO DT_FIFO |
| 108 |
DT_CHR = 2, |
| 109 |
# define DT_CHR DT_CHR |
| 110 |
DT_DIR = 4, |
| 111 |
# define DT_DIR DT_DIR |
| 112 |
DT_BLK = 6, |
| 113 |
# define DT_BLK DT_BLK |
| 114 |
DT_REG = 8, |
| 115 |
# define DT_REG DT_REG |
| 116 |
DT_LNK = 10, |
| 117 |
# define DT_LNK DT_LNK |
| 118 |
DT_SOCK = 12, |
| 119 |
# define DT_SOCK DT_SOCK |
| 120 |
DT_WHT = 14 |
| 121 |
# define DT_WHT DT_WHT |
| 122 |
}; |
| 123 |
|
| 124 |
/* Convert between stat structure types and directory types. */ |
| 125 |
# define IFTODT(mode) (((mode) & 0170000) >> 12) |
| 126 |
# define DTTOIF(dirtype) ((dirtype) << 12) |
| 127 |
|
| 128 |
__END_DECLS |
| 129 |
|
| 130 |
__POP_FC_STDLIB |
| 131 |
#endif |
| 132 |
|