#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 は存在しません.
| ホームページ | 目次 | 演習解答例目次 | 付録目次 | 索引 |