#include <sys/stat.h>
int chmod(const char *path, mode_t mode);
ll test.txt
---------- 1 groad users 19 05-30 12:16 test.txt
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
if (chmod ("test.txt", S_IRUSR | S_IWUSR | S_IWGRP | S_IWGRP | S_IWOTH) < 0) {
perror ("chmod");
exit (EXIT_FAILURE);
}
return (0);
}
ll test.txt
---------- 1 groad users 19 05-30 12:16 test.txt
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
struct stat buf;
if (chmod ("test.txt", S_IRUSR | S_IWUSR | S_IWGRP | S_IWGRP | S_IWOTH) < 0) {
perror ("chmod");
exit (EXIT_FAILURE);
}
if (stat ("test.txt", &buf) < 0) {
perror ("stat");
exit (EXIT_FAILURE);
}
chmod ("test.txt", (buf.st_mode & ~S_IWGRP | S_ISGID));
return (0);
}
ll test.txt
-rw---S-w- 1 groad users 19 05-30 12:16 test.txt
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |