#include <unistd.h> int access(char *path, int amode) path : パス名 amode : 許可属性(以下の論理和) R_OK : 読み W_OK : 書き X_OK : 実行 F_OK : ファイルの存在
#include <stdio.h>
#include <unistd.h>
int main()
{
int sw;
char *file1 = "test.c";
char *file2 = "xyz.w";
sw = access(file1, W_OK|R_OK);
if (sw == 0)
printf("ファイル %s は読み書きできます.\n", file1);
else
printf("ファイル %s は読み書きできません\n", file1);
sw = access(file2, F_OK);
if (sw == 0)
printf("ファイル %s は存在します.\n", file2);
else
printf("ファイル %s は存在しません.\n", file2);
return 0;
}
ファイル test.c は読み書きできます. ファイル xyz.w は存在しません.
| 菅沼ホーム | 本文目次 | 演習問題解答例 | 付録目次 | 索引 |