😸
[C] chmod 関数
機能
ファイルやディレクトリのパーミッション(アクセス権)を設定・変更する C言語の関数[1]
使用例
test.txt
のパーミッションを 644(rw-r--r--)に変更する
\n
は改行を表す エスケープシーケンス[2]
コード
chmod("test.txt", 0644);
全文
#include <stdio.h>
#include <sys/stat.h>
void main() {
chmod("test.txt", 0644);
}
実行結果
(何も出力しない/エラー時のみ出力)
シンボリックモードで 777(rwxrwxrwx)を変数から設定する
コード
int mode = 0777;
chmod("test.txt", mode);
全文
#include <stdio.h>
#include <sys/stat.h>
void main() {
int mode = 0777;
chmod("test.txt", mode);
}
実行結果
(何も出力しない/エラー時のみ出力)
Discussion