MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / access

Function access

components/dfs/dfs_v2/src/dfs_posix.c:1258–1298  ·  view source on GitHub ↗

* this function is a POSIX compliant version, which shall check the file named * by the pathname pointed to by the path argument for accessibility according * to the bit pattern contained in amode. * * @param path the specified file/dir path. * @param amode the value is either the bitwise-inclusive OR of the access * permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK).

Source from the content-addressed store, hash-verified

1256 * permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK).
1257 */
1258int access(const char *path, int amode)
1259{
1260 struct stat st;
1261
1262 if (path == NULL)
1263 {
1264 rt_set_errno(-EINVAL);
1265 return -1;
1266 }
1267
1268 if (stat(path, &st) < 0)
1269 {
1270 rt_set_errno(-ENOENT);
1271 return -1;
1272 }
1273
1274 if (amode == F_OK)
1275 {
1276 return 0;
1277 }
1278
1279 if ((amode & R_OK) && !(st.st_mode & S_IRUSR))
1280 {
1281 rt_set_errno(-EACCES);
1282 return -1;
1283 }
1284
1285 if ((amode & W_OK) && !(st.st_mode & S_IWUSR))
1286 {
1287 rt_set_errno(-EACCES);
1288 return -1;
1289 }
1290
1291 if ((amode & X_OK) && !(st.st_mode & S_IXUSR))
1292 {
1293 rt_set_errno(-EACCES);
1294 return -1;
1295 }
1296
1297 return 0;
1298}
1299
1300/**
1301 * this function is a POSIX compliant version, which will set current

Callers 2

dfs_devfs_mkdirFunction · 0.50
dfs_devfs_device_addFunction · 0.50

Calls 2

rt_set_errnoFunction · 0.85
statFunction · 0.70

Tested by

no test coverage detected