|
|
1.1 root 1:
2:
3: access() COHERENT System Call access()
4:
5:
6:
7:
8: Check if a file can be accessed in a given mode
9:
10: #iinncclluuddee <aacccceessss.hh>
11: iinntt aacccceessss(_f_i_l_e_n_a_m_e, _m_o_d_e) cchhaarr *_f_i_l_e_n_a_m_e; iinntt _m_o_d_e;
12:
13: access checks whether a file or directory can be accessed in the
14: mode you wish. filename is the full path name of the file or
15: directory you wish to check. mode is the mode in which you wish
16: to access filename, as follows:
17:
18:
19: AARREEAADD Read a file
20: AALLIISSTT List the contents of a directory
21:
22: AAWWRRIITTEE Write into a file
23: AADDEELL Delete files from a directory
24:
25: AAEEXXEECC Execute a file
26: AASSRRCCHH Search a directory
27:
28: AAAAPPPPNNDD Append to a file
29: AACCRREEAATT Create a file in a directory
30:
31:
32: The header file access.h defines these values, which may be logi-
33: cally combined to produce the mode argument.
34:
35: If mode is set to zero, access tests only whether filename ex-
36: ists, and whether you have permission to search all directories
37: that lead to it.
38:
39: access returns zero if filename can be accessed in the requested
40: mode, and a number greater than zero if it cannot.
41:
42: access uses the real user id and real group id (rather than the
43: effective user id and effective group id), so set user id
44: programs can use it.
45:
46: ***** Example *****
47:
48: The following example checks if a file can be accessed in a par-
49: ticular manner.
50:
51:
52: #include <access.h>
53: #include <stdio.h>
54:
55:
56:
57: main(argc, argv)
58: int argc; char *argv[];
59: {
60: int mode;
61: extern int access();
62:
63:
64: COHERENT Lexicon Page 1
65:
66:
67:
68:
69: access() COHERENT System Call access()
70:
71:
72:
73:
74:
75:
76: if (argc != 3) {
77: fprintf(stderr, "Usage: access filename mode\n");
78: exit(1);
79: }
80:
81:
82:
83: switch (*argv[2]) {
84: case 'x':
85: mode = AEXEC;
86: break;
87:
88:
89:
90: case 'w':
91: mode = AWRITE;
92: break;
93:
94:
95:
96: case 'r':
97: mode = AREAD;
98: break;
99:
100:
101:
102: default:
103: fprintf(stderr,
104: "modes: x = execute, w = write, r = read\n");
105: exit(1);
106: break;
107: }
108:
109:
110:
111: if (access(argv[1], mode)) {
112: printf("file %s not found in mode %d\n", argv[1], mode);
113: exit(0);
114: } else
115: printf("file %s accessible in mode %d\n",
116: argv[1], mode);
117: exit(0);
118: }
119:
120:
121: ***** See Also *****
122:
123: access.h, COHERENT system calls, path()
124:
125:
126:
127:
128:
129:
130: COHERENT Lexicon Page 2
131:
132:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.