euidaccess.3 サンプル
Linux API euidaccess.3のサンプル
euidaccess, eaccess ファイルへのアクセス権を実効ユーザでチェックする
#define _GNU_SOURCE #include <unistd.h> int euidaccess(const char *pathname, int mode); int eaccess(const char *pathname, int mode); modeは、R_OK, W_OK, X_OK, F_OKのひとつ以上から 構成されるマスク。eaccess()はeuidaccess()の同義語であり、 他のシステムとの互換性のために提供されている。
#include <unistd.h> #include <stdio.h> int main() { int ret; ret = euidaccess("euidaccess.3.c", R_OK | W_OK | X_OK); printf("R_OK | W_OK | X_OK : %s\n", ret == 0 ? "All access is allowed" : "All access is not allowed"); ret = euidaccess("euidaccess.3.c", R_OK); printf("R_OK : %s\n", ret == 0 ? "All access is allowed" : "All access is not allowed"); return 0; } $ gcc euidaccess.3.c $ ./a.out R_OK | W_OK | X_OK : All access is not allowed R_OK : All access is allowed
参考
http://www.linux.or.jp/JM/html/LDP_man-pages/man3/eaccess.3.html