lib: c: io: implement standard FILE and DIR interfaces

This commit is contained in:
2026-03-25 20:21:12 +00:00
parent b975256cb9
commit 96784f611f
21 changed files with 599 additions and 0 deletions
+20
View File
@@ -1,6 +1,8 @@
#ifndef DIRENT_H_
#define DIRENT_H_
#include <sys/types.h>
#define DT_UNKNOWN 0
#define DT_BLK 1
#define DT_CHR 2
@@ -10,4 +12,22 @@
#define DT_REG 6
#define DT_SOCK 7
struct dirent {
ino_t d_ino;
off_t d_off;
unsigned short d_reclen;
unsigned char d_type;
char d_name[256];
};
struct __opaque_dir;
typedef struct __opaque_dir DIR;
extern DIR *opendir(const char *name);
extern DIR *fdopendir(int fd);
extern int closedir(DIR *dirp);
extern struct dirent *readdir(DIR *dirp);
#endif
+29
View File
@@ -4,10 +4,15 @@
#include <stdarg.h>
#include <stddef.h>
#define EOF -1
#ifdef __cplusplus
extern "C" {
#endif
struct __opaque_file;
typedef struct __opaque_file FILE;
extern int snprintf(char *buffer, size_t count, const char *format, ...);
extern int vsnprintf(
char *buffer,
@@ -15,6 +20,30 @@ extern int vsnprintf(
const char *format,
va_list va);
extern FILE *fopen(const char *path, const char *mode);
extern int fclose(FILE *stream);
extern int feof(FILE *stream);
extern int ferr(FILE *stream);
extern size_t fread(void *buf, size_t size, size_t count, FILE *stream);
extern size_t fwrite(const void *buf, size_t size, size_t count, FILE *stream);
extern int fgetc(FILE *stream);
static inline int getc(FILE *stream)
{
return fgetc(stream);
}
extern int fputc(int c, FILE *stream);
static inline int putc(int c, FILE *stream)
{
return fputc(c, stream);
}
extern char *fgets(char *restrict str, int count, FILE *restrict stream);
extern int fputs(const char *restrict str, FILE *restrict stream);
#ifdef __cplusplus
}
#endif
+2
View File
@@ -7,6 +7,8 @@
#define SEEK_CUR 1
#define SEEK_END 2
typedef size_t ino_t;
struct dentry {
unsigned long d_ino;
unsigned short d_reclen;