![]()
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
int access_read_test(const char * filename)
{
return access(filename, R_OK);
}
int main(int argc, char * argv[])
{
if (argc < 2)
{
printf("usage:./exe file\n");
exit(EXIT_FAILURE);
}
char * buf = "hello";
char * file = "a.txt";
int fd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if (fd == -1)
{
perror("Error open func.\n");
exit(EXIT_FAILURE);
}
write(fd, buf, strlen(buf));
const char * filename = NULL; // 作用?
filename = argv[1];
if (access_read_test(filename) < 0)
{
perror("access read perrmission test: FAIL\n");
}
else
{
printf("access read perrmission test: DONE\n");
}
exit(EXIT_SUCCESS);
}