#include <wchar.h>
|
#include <sys/stat.h>
|
#include <sys/types.h>
|
int
wchmod (const wchar_t *path, mode_t mode); |
A mode is created from or’d permission bit masks defined in
#include <sys/stat.h> :
#define S_IRWXU 0000700 /* RWX mask for owner */ #define S_IRUSR 0000400 /* R for owner */ #define S_IWUSR 0000200 /* W for owner */ #define S_IXUSR 0000100 /* X for owner */ #define S_IRWXG 0000070 /* RWX mask for group */ #define S_IRGRP 0000040 /* R for group */ #define S_IWGRP 0000020 /* W for group */ #define S_IXGRP 0000010 /* X for group */ #define S_IRWXO 0000007 /* RWX mask for other */ #define S_IROTH 0000004 /* R for other */ #define S_IWOTH 0000002 /* W for other */ #define S_IXOTH 0000001 /* X for other */ #define S_ISUID 0004000 /* set user id on execution */ #define S_ISGID 0002000 /* set group id on execution */ #ifndef __BSD_VISIBLE #define S_ISTXT 0001000 /* sticky bit */ #endif Note : sticky bit and setuid on exec bit are not supported, permission values for users is considered while premissions values for group and others are ignored(As there is no concept of group and others). An attempt to change file permission to write-only changes the file permission to read-write. Permissions for directory will be ignored.
|
#include <wchar.h> /* wchmode, wfopen */ #include <sys/stat.h> /* S_IWUSR */ #include <stdio.h> /* printf */ int main() { FILE * wfp = wfopen(L"fileName.txt", L"wb"); /* create file */ if(wfp) { fclose(wfp); /* close file */ int ret = wchmod(L"fileName", S_IWUSR); /* change mode */ if(ret < 0) { printf("error changing mode"); return -1; } else { printf("mode changed"); } } else { printf("error creating file"); return -1; } return 0; }
Output
mode changed
[EINVAL] | |
Invalid argument. | |
[ENAMETOOLONG] | |
A component of a pathname exceeded 255 characters. | |
[ENOENT] | |
The named file does not exist. | |
[EACCES] | |
Search permission is denied for a component of the path prefix. | |
© 2005-2007 Nokia |