MentOS  0.8.0
The Mentoring Operating System
Macros | Functions
stat.h File Reference

Stat functions. More...

Go to the source code of this file.

Macros

#define __SYS_STAT_H
 Prevents the error when inlcuding <bits/stat.h>.
 
#define S_IFMT   0xF000
 Format mask.
 
#define S_IFSOCK   0xC000
 Socket.
 
#define S_IFLNK   0xA000
 Symbolic link.
 
#define S_IFREG   0x8000
 Regular file.
 
#define S_IFBLK   0x6000
 Block device.
 
#define S_IFDIR   0x4000
 Directory.
 
#define S_IFCHR   0x2000
 Character device.
 
#define S_IFIFO   0x1000
 Fifo.
 
#define S_ISTYPE(mode, mask)   (((mode) & S_IFMT) == (mask))
 Easy macro for checking the type.
 
#define S_ISSOCK(mode)   (S_ISTYPE(mode, S_IFSOCK))
 Check if a socket.
 
#define S_ISLNK(mode)   (S_ISTYPE(mode, S_IFLNK))
 Check if a symbolic link.
 
#define S_ISREG(mode)   (S_ISTYPE(mode, S_IFREG))
 Check if a regular file.
 
#define S_ISBLK(mode)   (S_ISTYPE(mode, S_IFBLK))
 Check if a block special.
 
#define S_ISDIR(mode)   (S_ISTYPE(mode, S_IFDIR))
 Check if a directory.
 
#define S_ISCHR(mode)   (S_ISTYPE(mode, S_IFCHR))
 Check if a char special.
 
#define S_ISFIFO(mode)   (S_ISTYPE(mode, S_IFIFO))
 Check if a fifo.
 
#define S_ISUID   0x0800
 Set user id on execution.
 
#define S_ISGID   0x0400
 Set group id on execution.
 
#define S_ISVTX   0x0200
 Save swapped text even after use (Sticky Bit)
 
#define S_IRWXU   0x01C0
 rwx---— : User can read/write/execute
 
#define S_IRUSR   0x0100
 r-----— : User can read
 
#define S_IWUSR   0x0080
 -w----— : User can write
 
#define S_IXUSR   0x0040
 –x---— : User can execute
 
#define S_IRWXG   0x0038
 —rwx— : Group can read/write/execute
 
#define S_IRGRP   0x0020
 —r--— : Group can read
 
#define S_IWGRP   0x0010
 -—w-— : Group can write
 
#define S_IXGRP   0x0008
 --—x— : Group can execute
 
#define S_IRWXO   0x0007
 ---—rwx : Others can read/write/execute
 
#define S_IROTH   0x0004
 ---—r– : Others can read
 
#define S_IWOTH   0x0002
 ----—w- : Others can write
 
#define S_IXOTH   0x0001
 -----—x : Others can execute
 

Functions

int stat (const char *path, stat_t *buf)
 Retrieves information about the file at the given location. More...
 
int fstat (int fd, stat_t *buf)
 Retrieves information about the file at the given location. More...
 
int mkdir (const char *path, mode_t mode)
 Creates a new directory at the given path. More...
 
int rmdir (const char *path)
 Removes the given directory. More...
 
int creat (const char *path, mode_t mode)
 Creates a new file or rewrite an existing one. More...
 

Detailed Description

Stat functions.

Function Documentation

◆ creat()

int creat ( const char *  path,
mode_t  mode 
)

Creates a new file or rewrite an existing one.

Parameters
pathpath to the file.
modemode for file creation.
Returns
file descriptor number, -1 otherwise and errno is set to indicate the error.

It is equivalent to: open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)

◆ fstat()

int fstat ( int  fd,
stat_t buf 
)

Retrieves information about the file at the given location.

Parameters
fdThe file descriptor of the file that is being inquired.
bufA structure where data about the file will be stored.
Returns
Returns a negative value on failure.

◆ mkdir()

int mkdir ( const char *  path,
mode_t  mode 
)

Creates a new directory at the given path.

Parameters
pathThe path of the new directory.
modeThe permission of the new directory.
Returns
Returns a negative value on failure.

◆ rmdir()

int rmdir ( const char *  path)

Removes the given directory.

Parameters
pathThe path to the directory to remove.
Returns
Returns a negative value on failure.

◆ stat()

int stat ( const char *  path,
stat_t buf 
)

Retrieves information about the file at the given location.

Parameters
pathThe path to the file that is being inquired.
bufA structure where data about the file will be stored.
Returns
Returns a negative value on failure.