仿写头文件 dirent.h
模拟linux下头文件 myDirent.h
#ifndef MYDIRENT_H
#define MYDIRENT_H
typedef struct _dirdesc {
int dd_fd; /** file descriptor associated with directory */
long dd_loc; /** offset in current buffer */
long dd_size; /** amount of data returned by getdirentries */
char *dd_buf; /** data buffer */
int dd_len; /** size of data buffer */
long dd_seek; /** magic cookie returned by getdirentries */
} DIR;
# define __dirfd(dp) ((dp)->dd_fd)
DIR *opendir(const char *);
struct dirent *readdir(DIR *);
void rewinddir(DIR *);
int closedir(DIR *);
#include <sys/types.h>
struct dirent
{
long d_ino; /* inode number*/
off_t d_off; /* offset to this dirent*/
unsigned short d_reclen; /* length of this d_name*/
unsigned char d_type; /* the type of d_name*/
char d_name[1]; /* file name (null-terminated)*/
};
#endif
实现函数 cpp
windows下仿写opendir() readdir() closedir()
利用FindFirstFile() FindNextFile() 这两个windows函数
myDirent.cpp
#include <iostream>
#include <string>
#include <stdio.h>