@@ -1308,3 +1308,71 @@ fn test_getpeereid_invalid_fd() {
1308
1308
// getpeereid is not POSIX, so error codes are inconsistent between different Unices.
1309
1309
getpeereid ( -1 ) . expect_err ( "assertion failed" ) ;
1310
1310
}
1311
+
1312
+ #[ test]
1313
+ #[ cfg( not( any( target_os = "illumos" , target_os = "redox" ) ) ) ]
1314
+ fn test_faccessat_none_not_existing ( ) {
1315
+ use nix:: fcntl:: AtFlags ;
1316
+ let tempdir = tempfile:: tempdir ( ) . unwrap ( ) ;
1317
+ let dir = tempdir. path ( ) . join ( "does_not_exist.txt" ) ;
1318
+ assert_eq ! (
1319
+ faccessat( None , & dir, AccessFlags :: F_OK , AtFlags :: empty( ) )
1320
+ . err( )
1321
+ . unwrap( ) ,
1322
+ Errno :: ENOENT
1323
+ ) ;
1324
+ }
1325
+
1326
+ #[ test]
1327
+ #[ cfg( not( any( target_os = "illumos" , target_os = "redox" ) ) ) ]
1328
+ fn test_faccessat_not_existing ( ) {
1329
+ use nix:: fcntl:: AtFlags ;
1330
+ let tempdir = tempfile:: tempdir ( ) . unwrap ( ) ;
1331
+ let dirfd = open ( tempdir. path ( ) , OFlag :: empty ( ) , Mode :: empty ( ) ) . unwrap ( ) ;
1332
+ let not_exist_file = "does_not_exist.txt" ;
1333
+ assert_eq ! (
1334
+ faccessat(
1335
+ Some ( dirfd) ,
1336
+ not_exist_file,
1337
+ AccessFlags :: F_OK ,
1338
+ AtFlags :: empty( )
1339
+ )
1340
+ . err( )
1341
+ . unwrap( ) ,
1342
+ Errno :: ENOENT
1343
+ ) ;
1344
+ }
1345
+
1346
+ #[ test]
1347
+ #[ cfg( not( any( target_os = "illumos" , target_os = "redox" ) ) ) ]
1348
+ fn test_faccessat_none_file_exists ( ) {
1349
+ use nix:: fcntl:: AtFlags ;
1350
+ let tempdir = tempfile:: tempdir ( ) . unwrap ( ) ;
1351
+ let path = tempdir. path ( ) . join ( "does_exist.txt" ) ;
1352
+ let _file = File :: create ( path. clone ( ) ) . unwrap ( ) ;
1353
+ assert ! ( faccessat(
1354
+ None ,
1355
+ & path,
1356
+ AccessFlags :: R_OK | AccessFlags :: W_OK ,
1357
+ AtFlags :: empty( )
1358
+ )
1359
+ . is_ok( ) ) ;
1360
+ }
1361
+
1362
+ #[ test]
1363
+ #[ cfg( not( any( target_os = "illumos" , target_os = "redox" ) ) ) ]
1364
+ fn test_faccessat_file_exists ( ) {
1365
+ use nix:: fcntl:: AtFlags ;
1366
+ let tempdir = tempfile:: tempdir ( ) . unwrap ( ) ;
1367
+ let dirfd = open ( tempdir. path ( ) , OFlag :: empty ( ) , Mode :: empty ( ) ) . unwrap ( ) ;
1368
+ let exist_file = "does_exist.txt" ;
1369
+ let path = tempdir. path ( ) . join ( exist_file) ;
1370
+ let _file = File :: create ( path. clone ( ) ) . unwrap ( ) ;
1371
+ assert ! ( faccessat(
1372
+ Some ( dirfd) ,
1373
+ & path,
1374
+ AccessFlags :: R_OK | AccessFlags :: W_OK ,
1375
+ AtFlags :: empty( )
1376
+ )
1377
+ . is_ok( ) ) ;
1378
+ }
0 commit comments