POSIX API
The best-known API for accessing and managing files and directories is specified within the POSIX standard (IEEE Std 1003.1). The basis of some of this functionality, in particular buffered input/output, lies in the ISO C standard (ISO/IEC 9899), though many extensions provide new features and clarify existing behaviors. Functions and macros prototyped in four header files are of particular importance:
stdio.h
. Standard buffered input/output (fopen()
,fread()
, etc), operating on FILE objects.dirent.h
. Directory accesses (opendir()
,readdir()
, etc), operating on DIR objects.unistd.h
. Miscellaneous functions, including working directory management (chdir()
,getcwd()
),ftruncate()
andrmdir()
.sys/stat.h.
File statistics functions andmkdir()
.
µC/FS provides a POSIX-like API based on a subset of the functions in these four header files. To avoid conflicts with the user compilation environment, files, functions and objects are renamed:
- All functions begin with ‘fs_’. For example,
fopen()
is renamedfs_fopen()
,opendir()
is renamedfs_opendir()
,getcwd()
is renamedfs_getcwd()
, etc. - All objects begin with ‘FS_’. So
fs_fopen()
returns a pointer to aFS_FILE
andfs_opendir()
returns a pointer to aFS_DIR
. - Some argument types are renamed. For example, the second and third parameters of
fs_fread()
are typedfs_size_t
to avoid conflicting with othersize_t
definitions.
Important warning about the POSIX API
The µC/FS implementation of the POSIX API is not 100% compliant. Most notably, the errno
error flag isn’t set when an error occurs and thus it is recommended to use the µC/FS proprietary API (FSFile_####()
, FSDir_####(),
FSEntry_####()
, etc.).