API для директорий
Операции с директориями: создать директорию удалить директорию удалить можно только пустую директорию На самом деле очень интересно посмотреть как работала библиотечная функция по созданию директории в ранней версиях UNIX: Она создавала специальный файл - типа директория Затем делала hard link на саму директорию и на родителя (если только он на root) с именами . и .. Поэтому даже сейчас UNIX позволяет делать hardlinks на директории. Создание и удаление
![]() |
int mkdir(const char* path, mode_t mode) int rmdir(const char* path) |
![]() |
DIR* opendir(const char*name)
int dirfd(DIR* dir) // BSD
struct dirent * readdir(DIR* dir)
int closedir(DIR* dir)
// . and .. in directory not warranted
// may absent or be in center of catalog
struct direct
{
ino_t d_ino; // UNIX, d_fileno
off_t d_off; // offset to next record
unsigned short d_reclen;
unsigned char d_type; // Linix,BSD
DT_BLK
DT_CHR
DT_DIR
DT_FIFO
DT_LNK
DT_REG
DT_SOCK
DT_UNKNOWN
DT_WHT // bsd
char d_name[256]; //+
};
void rewinddir(DIR* dir) // Non standard
void seekdir(DIR* dir, long loc) // Non standard BSD
long telldir(DIR* dir) // Non standard BSD
int readdir(int fd, struct dirent* dirp, unsigned int count); // internal
int getdirents(int fd, struct dirent* dirp, unsigned int count); // internal
int readdir_r(DIR* restrict dir, struct dirent* entry, struct dirent** result)
|
![]() |
char* getcwd(char* buf, size_t size) int chdir(const char* path) int fchdir(int fd) |
![]() |
int inotify_init(void) int inotify_add_watch(int fd, const char* path, uint32_t mask) int inotify_rm_watch(int fd, uint32_t wd) |