RT-Thread RTOS  1.2.0
An open source embedded real-time operating system
+ Collaboration diagram for File POSIX API:

Functions

int open (const char *file, int flags,...)
 
int creat (const char *path, mode_t mode)
 
int close (int fd)
 
ssize_t read (int fd, void *buf, size_t len)
 
ssize_t write (int fd, const void *buf, size_t len)
 
off_t lseek (int fd, off_t offset, int whence)
 
int rename (const char *old_file, const char *new_file)
 
int unlink (const char *pathname)
 
int stat (const char *file, struct stat *buf)
 
int fstat (int fildes, struct stat *buf)
 
int fsync (int fildes)
 
int fcntl (int fildes, int cmd,...)
 
int ioctl (int fildes, int cmd,...)
 
int ftruncate (int fd, off_t length)
 
int statfs (const char *path, struct statfs *buf)
 
int fstatfs (int fildes, 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, long offset)
 
void rewinddir (DIR *d)
 
int closedir (DIR *d)
 
int access (const char *path, int amode)
 
void setcwd (char *buf)
 
char * getcwd (char *buf, size_t size)
 
ssize_t pread (int fd, void *buf, size_t len, off_t offset)
 
ssize_t pwrite (int fd, const void *buf, size_t len, off_t offset)
 

Detailed Description

Function Documentation

◆ open()

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

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

Parameters
filethe path name of file.
flagsthe file open flags.
Returns
the non-negative integer on successful open, others for failed.

◆ creat()

int creat ( const char *  path,
mode_t  mode 
)

this function is a POSIX compliant version, which will create a new file or rewrite an existing one

Parameters
paththe path name of file.
modethe file permission bits to be used in creating the file (not used, can be 0)
Returns
the non-negative integer on successful open, others for failed.

◆ close()

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.

◆ read()

ssize_t 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. If the returned value is 0, it may be reach the end of file, please check errno.

◆ write()

ssize_t 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.

◆ lseek()

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 read/write position in the file, or -1 on failed.

◆ rename()

int rename ( const char *  old_file,
const char *  new_file 
)

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

Parameters
old_filethe old file name.
new_filethe 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.

◆ unlink()

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.

◆ stat()

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.

◆ fstat()

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.
Returns
0 on successful, -1 on failed.

◆ fsync()

int fsync ( int  fildes)

this function is a POSIX compliant version, which shall request that all data for the open file descriptor named by fildes is to be transferred to the storage device associated with the file described by fildes.

Parameters
fildesthe file description
Returns
0 on successful completion. Otherwise, -1 shall be returned and errno set to indicate the error.

◆ fcntl()

int fcntl ( int  fildes,
int  cmd,
  ... 
)

this function is a POSIX compliant version, which shall perform a variety of control functions on devices.

Parameters
fildesthe file description
cmdthe specified command
...represents the additional information that is needed by this specific device to perform the requested function.
Returns
0 on successful completion. Otherwise, -1 shall be returned and errno set to indicate the error.

◆ ioctl()

int ioctl ( int  fildes,
int  cmd,
  ... 
)

this function is a POSIX compliant version, which shall perform a variety of control functions on devices.

Parameters
fildesthe file description
cmdthe specified command
...represents the additional information that is needed by this specific device to perform the requested function.
Returns
0 on successful completion. Otherwise, -1 shall be returned and errno set to indicate the error.

◆ ftruncate()

int ftruncate ( int  fd,
off_t  length 
)

this function is a POSIX compliant version, which cause the regular file referenced by fd to be truncated to a size of precisely length bytes.

Parameters
fdthe file descriptor.
lengththe length to be truncated.
Returns
Upon successful completion, ftruncate() shall return 0; otherwise, -1 shall be returned and errno set to indicate the error.

◆ statfs()

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.

◆ fstatfs()

int fstatfs ( int  fildes,
struct statfs buf 
)

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

Parameters
fildesthe file description.
bufthe buffer to save the returned information.
Returns
0 on successful, others on failed.

◆ mkdir()

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.

◆ rmdir()

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 successful, others on failed.

◆ opendir()

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 directory failed.

◆ readdir()

struct dirent* readdir ( DIR *  d)

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.

◆ telldir()

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.

◆ seekdir()

void seekdir ( DIR *  d,
long  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.

◆ rewinddir()

void rewinddir ( DIR *  d)

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

Parameters
dthe directory stream.

◆ closedir()

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.

◆ access()

int access ( const char *  path,
int  amode 
)

this function is a POSIX compliant version, which shall check the file named by the pathname pointed to by the path argument for accessibility according to the bit pattern contained in amode.

Parameters
paththe specified file/dir path.
amodethe value is either the bitwise-inclusive OR of the access permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK).

◆ setcwd()

void setcwd ( char *  buf)

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

Parameters
bufthe current directory.

◆ getcwd()

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.

◆ pread()

ssize_t pread ( int  fd,
void *  buf,
size_t  len,
off_t  offset 
)

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
offsetthe file pos
Returns
the actual read data buffer length. If the returned value is 0, it may be reach the end of file, please check errno.

◆ pwrite()

ssize_t pwrite ( int  fd,
const void *  buf,
size_t  len,
off_t  offset 
)

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.
offsetthe file pos
Returns
the actual written data buffer length.