RT-Thread RTOS  1.0.0
An open source embedded real-time operating system
File POSIX API

Functions

int open (const char *file, int flags, int mode)
int close (int fd)
int read (int fd, void *buf, size_t len)
int write (int fd, const void *buf, size_t len)
off_t lseek (int fd, off_t offset, int whence)
int rename (const char *old, const char *new)
int unlink (const char *pathname)
int stat (const char *file, struct stat *buf)
int fstat (int fildes, struct stat *buf)
int statfs (const char *path, struct statfs *buf)
int mkdir (const char *path, mode_t mode)
int rmdir (const char *pathname)
DIR * opendir (const char *name)
struct dirent * readdir (DIR *d)
long telldir (DIR *d)
void seekdir (DIR *d, off_t offset)
void rewinddir (DIR *d)
int closedir (DIR *d)
char * getcwd (char *buf, size_t size)

Function Documentation

int open ( const char *  file,
int  flags,
int  mode 
)

this function is a POSIX compliant version, which will open a file and return a file descriptor.

Parameters:
filethe path name of file.
flagsthe file open flags.
mode
Returns:
the non-negative integer on successful open, others for failed.
int close ( int  fd)

this function is a POSIX compliant version, which will close the open file descriptor.

Parameters:
fdthe file descriptor.
Returns:
0 on successful, -1 on failed.
int read ( int  fd,
void *  buf,
size_t  len 
)

this function is a POSIX compliant version, which will read specified data buffer length for an open file descriptor.

Parameters:
fdthe file descriptor.
bufthe buffer to save the read data.
lenthe maximal length of data buffer
Returns:
the actual read data buffer length
int write ( int  fd,
const void *  buf,
size_t  len 
)

this function is a POSIX compliant version, which will write specified data buffer length for an open file descriptor.

Parameters:
fdthe file descriptor
bufthe data buffer to be written.
lenthe data buffer length.
Returns:
the actual written data buffer length.
off_t lseek ( int  fd,
off_t  offset,
int  whence 
)

this function is a POSIX compliant version, which will seek the offset for an open file descriptor.

Parameters:
fdthe file descriptor.
offsetthe offset to be seeked.
whencethe directory of seek.
Returns:
the current file position, or -1 on failed.
int rename ( const char *  old,
const char *  new 
)

this function is a POSIX compliant version, which will rename old file name to new file name.

Parameters:
oldthe old file name.
newthe new file name.
Returns:
0 on successful, -1 on failed.

note: the old and new file name must be belong to a same file system.

int unlink ( const char *  pathname)

this function is a POSIX compliant version, which will unlink (remove) a specified path file from file system.

Parameters:
pathnamethe specified path name to be unlinked.
Returns:
0 on successful, -1 on failed.
int stat ( const char *  file,
struct stat buf 
)

this function is a POSIX compliant version, which will get file information.

Parameters:
filethe file name
bufthe data buffer to save stat description.
Returns:
0 on successful, -1 on failed.
int fstat ( int  fildes,
struct stat buf 
)

this function is a POSIX compliant version, which will get file status.

Parameters:
fildesthe file description
bufthe data buffer to save stat description.
int statfs ( const char *  path,
struct statfs buf 
)

this function is a POSIX compliant version, which will return the information about a mounted file system.

Parameters:
paththe path which mounted file system.
bufthe buffer to save the returned information.
Returns:
0 on successful, others on failed.
int mkdir ( const char *  path,
mode_t  mode 
)

this function is a POSIX compliant version, which will make a directory

Parameters:
paththe directory path to be made.
mode
Returns:
0 on successful, others on failed.
int rmdir ( const char *  pathname)

this function is a POSIX compliant version, which will remove a directory.

Parameters:
pathnamethe path name to be removed.
Returns:
0 on sucessfull, others on failed.
DIR* opendir ( const char *  name)

this function is a POSIX compliant version, which will open a directory.

Parameters:
namethe path name to be open.
Returns:
the DIR pointer of directory, NULL on open failed.
struct dirent* readdir ( DIR *  d) [read]

this function is a POSIX compliant version, which will return a pointer to a dirent structure representing the next directory entry in the directory stream.

Parameters:
dthe directory stream pointer.
Returns:
the next directory entry, NULL on the end of directory or failed.
long telldir ( DIR *  d)

this function is a POSIX compliant version, which will return current location in directory stream.

Parameters:
dthe directory stream pointer.
Returns:
the current location in directory stream.
void seekdir ( DIR *  d,
off_t  offset 
)

this function is a POSIX compliant version, which will set position of next directory structure in the directory stream.

Parameters:
dthe directory stream.
offsetthe offset in directory stream.
void rewinddir ( DIR *  d)

this function is a POSIX compliant version, which will reset directory stream.

Parameters:
dthe directory stream.
int closedir ( DIR *  d)

this function is a POSIX compliant version, which will close a directory stream.

Parameters:
dthe directory stream.
Returns:
0 on successful, -1 on failed.
char* getcwd ( char *  buf,
size_t  size 
)

this function is a POSIX compliant version, which will return current working directory.

Parameters:
bufthe returned current directory.
sizethe buffer size.
Returns:
the returned current directory.
 All Data Structures Variables