我是C编程的新手,我正在尝试将文件的权限设置为只读。我确定我没有正确的指令,当我尝试编译时,在#include <io.h>上出现了“严重错误:io.h没有这样的文件或目录”的错误。文件“ time.log”位于名为“ time_logs”的目录中,程序将从目录“ time_logs”所在的目录中运行。
OS是使用GCC的Raspbian Pi 4 Arm的Rasbian
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <io.h>
#include <sys.h>
struct stat st = {0};
int main(void){
if(_chmod("time_logs/time.log", _S_IREAD) == -1)
perror("Not found");
else{
_chmod("time_logs/time.log", _S_IREAD);
}
}
似乎你使用Windows手册尝试为Linux编写代码。
#include <unistd.h>
#include <sys/stat.h>
if(chmod("time_logs/time.log", S_IRUSR | S_IRGRP | S_IROTH) == -1)
perror("time_logs/time.log");
但是大多数人只是直接输入权限位。这将是0444
。调整口味。
是的,看来我没有使用一些Windows指令。我正在使用Linux。因此,我将确保将来搜索LinuxC。
@YHapticY:提示:搜索
linux man 2 xyz
或linux man 3 xyz
。非常感谢@Joshua。我想我现在可以工作了。