29 #pragma GCC diagnostic ignored "-Wshadow" 40 #define ISSPACE " \t\n\r\f\v" 53 typedef int32_t off_t;
122 typedef struct utimbuf
129 #define MAX_NAME_LEN _MAX_LFN 131 #define MAX_NAME_LEN 13 138 unsigned short d_reclen;
139 unsigned char d_type;
142 char d_name[MAX_NAME_LEN];
145 typedef struct dirent dirent_t;
159 #define __SSTR 0x0004 160 #define __SPGM 0x0008 161 #define __SERR 0x0010 162 #define __SEOF 0x0020 163 #define __SUNGET 0x040 164 #define __SMALLOC 0x80 168 #define __SLBF 0x0200 169 #define __SNBF 0x0400 170 #define __SMBF 0x0800 174 int (*put)(char,
struct __file *);
175 int (*
get)(
struct __file *);
183 #define O_ACCMODE 00000003 184 #define O_RDONLY 00000000 185 #define O_WRONLY 00000001 186 #define O_RDWR 00000002 187 #define O_CREAT 00000100 188 #define O_EXCL 00000200 190 #define O_NOCTTY 00000400 191 #define O_TRUNC 00001000 192 #define O_APPEND 00002000 193 #define O_NONBLOCK 00004000 194 #define O_BINARY 00000004 195 #define O_TEXT 00000004 196 #define O_CLOEXEC 00000000 197 #define S_IFMT 0170000 199 #define S_IFDIR 0040000 200 #define S_IFCHR 0020000 201 #define S_IFBLK 0060000 202 #define S_IFREG 0100000 203 #define S_IFIFO 0010000 204 #define S_IFLNK 0120000 205 #define S_IFSOCK 0140000 207 #define S_IWRITE 0200 211 #define S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask)) 212 #define S_ISDIR(mode) S_ISTYPE((mode), S_IFDIR) 213 #define S_ISCHR(mode) S_ISTYPE((mode), S_IFCHR) 214 #define S_ISBLK(mode) S_ISTYPE((mode), S_IFBLK) 215 #define S_ISREG(mode) S_ISTYPE((mode), S_IFREG) 218 #define S_IRUSR S_IREAD 219 #define S_IWUSR S_IWRITE 220 #define S_IXUSR S_IEXEC 221 #define S_IRWXU (S_IREAD|S_IWRITE|S_IEXEC) 223 #define S_IRGRP (S_IRUSR >> 3) 224 #define S_IWGRP (S_IWUSR >> 3) 225 #define S_IXGRP (S_IXUSR >> 3) 226 #define S_IRWXG (S_IRWXU >> 3) 228 #define S_IROTH (S_IRGRP >> 3) 229 #define S_IWOTH (S_IWGRP >> 3) 230 #define S_IXOTH (S_IXGRP >> 3) 231 #define S_IRWXO (S_IRWXG >> 3) 235 #define modecmp(str, pat) (strcmp(str, pat) == 0 ? 1: 0) 239 #define FATFS_R (S_IRUSR | S_IRGRP | S_IROTH) 240 #define FATFS_W (S_IWUSR | S_IWGRP | S_IWOTH) 241 #define FATFS_X (S_IXUSR | S_IXGRP | S_IXOTH) 254 typedef struct __file FILE;
258 extern FILE *
__iob[MAX_FILES];
266 #define stdin (__iob[0]) 267 #define stdout (__iob[1]) 268 #define stderr (__iob[2]) 273 #define putc(__c, __stream) fputc(__c, __stream) 277 #define getc(__stream) fgetc(__stream) 281 #define putchar(__c) fputc(__c,stdout) 283 #define puts(__str) fputs(__str,stdout) 288 #define fdev_set_udata(stream, u) do { (stream)->udata = u; } while(0) 289 #define fdev_get_udata(stream) ((stream)->udata) 292 #define _FDEV_EOF (-1) 293 #define _FDEV_ERR (-2) 295 #define _FDEV_SETUP_READ __SRD 296 #define _FDEV_SETUP_WRITE __SWR 297 #define _FDEV_SETUP_RW (__SRD|__SWR) 299 // ============================================= 304 int fgetc ( FILE *stream );
305 int fputc (
int c , FILE *stream );
313 int putc (
int c , FILE *stream );
315 char *
fgets (
char *str ,
int size , FILE *stream );
316 int fputs (
const char *str , FILE *stream );
318 int puts (
const char *str );
320 int feof ( FILE *stream );
321 int fgetpos ( FILE *stream ,
size_t *pos );
322 int fseek ( FILE *stream ,
long offset ,
int whence );
323 int fsetpos ( FILE *stream ,
size_t *pos );
324 long ftell ( FILE *stream );
325 off_t
lseek (
int fileno , off_t position ,
int whence );
326 void rewind ( FILE *stream );
328 int fileno ( FILE *stream );
330 FILE *
fopen (
const char *path ,
const char *mode );
331 size_t __wrap_fread (
void *ptr ,
size_t size ,
size_t nmemb , FILE *stream );
333 size_t fwrite (
const void *ptr ,
size_t size ,
size_t nmemb , FILE *stream );
334 int open (
const char *pathname,
int flags);
335 ssize_t
read (
int fd ,
void *buf ,
size_t count );
338 int fsync (
int fd );
339 int truncate (
const char *path , off_t length );
340 ssize_t
write (
int fd ,
const void *buf ,
size_t count );
342 FILE *
__wrap_freopen (
const char * filename,
const char * mode, FILE * stream );
344 char *
gets (
char *p);
348 int fstat (
int fd ,
struct stat *buf );
355 int chdir (
const char *pathname );
356 int chmod (
const char *pathname , mode_t mode );
361 int fchmod (
int fd , mode_t mode );
364 char *
getcwd (
char *pathname ,
int len );
365 int mkdir (
const char *pathname , mode_t mode );
366 int rename (
const char *oldpath ,
const char *newpath );
367 int rmdir (
const char *pathname );
368 int unlink (
const char *pathname );
369 int remove(
const char *pathname);
374 int ferror ( FILE *stream );
375 void perror (
const char *s );
378 FILE *
fdevopen (
int (*put )(
char ,FILE *),
int (*
get )(FILE *));
391 int fprintf(FILE *fp,
const char *format, ...);
int syncfs(int fd)
POSIX Sync pending file changes and metadata for specified fileno.
int fileno(FILE *stream)
Convert POSIX stream pointer to POSIX fileno (index of __iob[])
char * baseext(char *str)
File extention of a file name. NOT POSIX.
int rename(const char *oldpath, const char *newpath)
POSIX rename a file by name.
void rewind(FILE *stream)
POSIX rewind file to the beginning.
dirent_t * readdir(DIR *dirp)
int ferror(FILE *stream)
ferror reports if the stream has an error flag set
int open(const char *pathname, int flags)
POSIX Open a file with integer mode flags.
int fgetpos(FILE *stream, size_t *pos)
POSIX get position of file stream.
int fatfs_putc(char c, FILE *stream)
Private FatFs function called by fputc() to put a byte from file stream NOT POSIX open() assigns stre...
char * __wrap_strerror_r(int errnum, char *buf, size_t buflen)
POSIX strerror_r() - convert POSIX errno to text with user message.
int fatfs_to_errno(FRESULT Result)
Convert FafFs error result to POSIX errno. NOT POSIX.
char * strerror(int errnum)
POSIX strerror() - convert POSIX errno to text with user message.
int dirname(char *str)
POSIX directory name of a filename. Return the index of the last '/' character.
ssize_t write(int fd, const void *buf, size_t count)
POSIX Write count bytes from *buf to fileno fd.
int posix_fopen_modes_to_open(const char *mode)
Convert POSIX fopen mode to POSIX open mode flags. NOT POSIX.
int rmdir(const char *pathname)
POSIX delete a directory.
int new_file_descriptor(void)
Allocate a POSIX FILE descriptor. NOT POSIX.
char * getcwd(char *pathname, int len)
POSIX get current working directory.
int fatfs_getc(FILE *stream)
Formt SD card.
int putchar(int c)
put a character to stdout See fdevopen() sets stream->put get for TTY devices
time_t fat_time_to_unix(uint16_t date, uint16_t time)
Convert FatFs file date and time to POSIX epoch seconds. NOT POSIX.
FILE * fdevopen(int(*put)(char, FILE *), int(*get)(FILE *))
Device open functions.
int fatfs_to_fileno(FIL *fh)
Convert FatFS file handle to POSIX fileno. NOT POSIX.
int fsetpos(FILE *stream, size_t *pos)
POSIX set position of file stream.
void perror(const char *s)
POSIX perror() - convert POSIX errno to text with user message.
long ftell(FILE *stream)
POSIX file position of open stream.
int free_file_descriptor(int fileno)
Free POSIX fileno FILE descriptor. NOT POSIX.
int feof(FILE *stream)
feof reports if the stream is at EOF
ssize_t read(int fd, void *buf, size_t count)
POSIX read count bytes from *buf to fileno fd.
int isatty(int fileno)
Test POSIX fileno if it is a Serial Console/TTY.
void unix_time_to_fat(time_t epoch, uint16_t *date, uint16_t *time)
Convert Linux POSIX time_t to FAT32 date and time. NOT POSIX.
int puts(const char *str)
put a string to stdout See fdevopen() sets stream->put get for TTY devices
int putc(int c, FILE *stream)
Un-Get byte from a TTY device or FatFs file stream.
int __wrap_fclose(FILE *stream)
POSIX close a file stream.
int getchar()
functions normally defined as macros
int close(int fileno)
POSIX Close a file with fileno handel.
void sync(void)
POSIX Sync all pending file changes and metadata on ALL files.
int unlink(const char *pathname)
POSIX delete a file.
int fputs(const char *str, FILE *stream)
put a string to stdout See fdevopen() sets stream->put get for TTY devices
off_t lseek(int fileno, off_t position, int whence)
POSIX seek to file position.
int mkdir(const char *pathname, mode_t mode)
POSIX make a directory.
int fseek(FILE *stream, long offset, int whence)
POSIX seek to file possition.
int ftruncate(int fd, off_t length)
POSIX truncate open file to length.
FIL * fileno_to_fatfs(int fileno)
Convert POSIX fileno to FatFS handle NOT POSIX.
FILE * fileno_to_stream(int fileno)
Convert POSIX fileno to POSIX FILE stream pointer. NOT POSIX.
int stat(const char *name, struct stat *buf)
Display struct stat, from POSIX stat(0 or fstat(), in ASCII. NOT POSIX.
FILE * fopen(const char *path, const char *mode)
POSIX Open a file with path name and ascii file mode string.
int chdir(const char *pathname)
POSIX change directory.
int closedir(DIR *dirp)
POSIX closedir.
int fgetc(FILE *stream)
Get byte from a TTY device or FatFs file stream open() or fopen() sets stream->get = fatfs_getc() for...
int chmod(const char *pathname, mode_t mode)
POSIX chmod function - change file access permission Unfortunately file f_open modes and f_chmod mode...
int errno
Note: fdevopen assigns stdin,stdout,stderr.
int fprintf(FILE *fp, const char *fmt,...)
fprintf character write function
int truncate(const char *path, off_t length)
POSIX truncate named file to length.
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
POSIX write nmemb elements from buf, size bytes each, to the stream fd.
int fputc(int c, FILE *stream)
Put a byte to TTY device or FatFs file stream open() or fopen() sets stream->put = fatfs_outc() for F...
FILE * __iob[MAX_FILES]
POSIX fileno to POSIX FILE stream table.
DIR * opendir(const char *pathdir)
FILE * __wrap_freopen(const char *filename, const char *mode, FILE *stream)
char * fgets(char *str, int size, FILE *stream)
get a string from stdin See fdevopen() sets stream->put get for TTY devices
char * basename(const char *str)
POSIX Basename of filename.
void clearerr(FILE *stream)
size_t __wrap_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
POSIX read nmemb elements from buf, size bytes each, to the stream fd.
void clrerror(FILE *stream)
clrerror resets stream EOF and error flags