The difference between the mkdir function in Linux and the _mkdir function in Windows
- 2020-05-15 02:34:59
- OfStack
So let me introduce you to the _mkdir function for windows
#include<direct.h>
int _mkdir( const char *dirname );
Parameters:
dirname is a pathname pointer to a directory
The return value:
Each of these functions returns a value of 0 if the new directory was created. On error, the function returns the wok
linux mkdir function mode_t parameter details
#include <sys/stat.h>
int mkdir(const char *path, mode_t mode);
Parameters:
path is the directory name
mode is a directory permission
The return value:
A return of 0 indicates success, a return of -1 indicates error, and the errno value is set.
mode mode bit:
mode represents the permissions for the new directory and can take the following values:
S_IRUSR
S_IREAD
S_IWUSR
S_IWRITE
S_IXUSR
S_IEXEC
S_IRWXU
This is equivalent to (S_IRUSR | S_IWUSR | S_IXUSR).
S_IRGRP
Read permission bit for the group owner of the file. Usually 040.
S_IWGRP
Write permission bit for the group owner of the file. Usually 020.
S_IXGRP
Execute or search permission bit for the group owner of the file. Usually 010.
S_IRWXG
This is equivalent to (S_IRGRP | S_IWGRP | S_IXGRP).
S_IROTH
Read permission bit for other users. Usually 04.
S_IWOTH
Write permission bit for other users. Usually 02.
S_IXOTH
Execute or search permission bit for other users. Usually 01.
S_IRWXO
This is equivalent to (S_IROTH | S_IWOTH | S_IXOTH).
S_ISUID
This is the set-user-ID on execute bit, usually 04000. See How Change Persona.
S_ISGID
This is the set-group-ID on execute bit, usually 02000. See How Change Persona.
S_ISVTX
This is the sticky bit, usually 01000.
S_IRWXU 00700 permissions, which means that the file owner has read, write, and execute permissions
S_IRUSR(S_IREAD) 00400 permissions, which means the file owner has readable permissions
S_IWUSR(S_IWRITE) 00200 permissions, which means that the file owner has writable permissions
S_IXUSR(S_IEXEC) 00100 authority, which means that the file owner has the authority to execute
S_IRWXG 00070, which means that the file user group has read, write, and execute permissions
S_IRGRP 00040, which means that the file user group has readable permissions
S_IWGRP 00020 permissions, which means that the file user group has writable permissions
S_IXGRP 00010 authority, which represents the file user group that has the authority to execute
S_IRWXO 00007, which means that other users have read, write, and execute permissions
S_IROTH 00004 permissions, which means that other users have readable permissions
S_IWOTH 00002 permissions, which means other users have writable permissions
S_IXOTH 00001 authority, which means that other users have the authority to execute
Now let me give you a detailed explanation of the mkdir function in Linux
mkdir function
Head file library:
#include
<
sys/stat.h
>
#include
<
sys/types.h
>
Function prototype:
int mkdir(const char *pathname, mode_t mode);
Function description:
The mkdir() function creates a directory named after parameter pathname in mode mode, and mode defines the permissions for the newly created directory.
The return value:
If the directory is created successfully, 0 is returned. Otherwise, it returns -1 and logs the error to the global variable errno.
mode way:
S_IRWXU 00700 permissions, which means that the file owner has read, write, and execute permissions
S_IRUSR(S_IREAD) 00400 permissions, which means that the file owner has readable permissions
S_IWUSR(S_IWRITE) 00200 permissions, which means that the file owner has writable permissions
S_IXUSR(S_IEXEC) 00100 authority, which means that the file owner has the authority to execute
S_IRWXG 00070 permissions, which means that the file user group has read, write, and execute permissions
S_IRGRP 00040 permissions, which means that the file user group has readable permissions
S_IWGRP 00020 permissions, which means that the file user group has writable permissions
S_IXGRP 00010 authority, which represents the file user group that has the authority to execute
S_IRWXO 00007 permissions, which means that other users have read, write, and execute permissions
S_IROTH 00004 permissions, which means that other users have readable permissions
S_IWOTH 00002 permissions, which means that other users have writable permissions
S_IXOTH 00001 authority, which means that other users have the authority to execute