如何将 *argv[] 中的八进制字符串用于以下内容:
open("outfile",O_CREAT | O_RDWR,0777);
Run Code Online (Sandbox Code Playgroud)
0777 表示八进制数的许可。
我的代码:
int arC = atoi(argv[optind]);
printf("argv optind %s after atoi %d\n",argv[optind],arC);
int test =des2=open("createfile",O_CREAT | O_RDWR,arC);
printf("fd %d\n",test);
Run Code Online (Sandbox Code Playgroud)
终端输出:
./copymaster -c 0777 in
argv optind 0777 after atoi 777
fd 5
Run Code Online (Sandbox Code Playgroud)
但权限未设置为 0777。open()只是忽略arC.
如何将此字符串转换argv[optind]为open()命令的可用形式?