@@ -1293,13 +1293,23 @@ impl File {
1293
1293
return Ok ( ( ) ) ;
1294
1294
}
1295
1295
1296
+ #[ cfg( target_os = "solaris" ) ]
1297
+ pub fn lock ( & self ) -> io:: Result < ( ) > {
1298
+ let mut flock: libc:: flock = unsafe { mem:: zeroed ( ) } ;
1299
+ flock. l_type = libc:: F_WRLCK as libc:: c_short ;
1300
+ flock. l_whence = libc:: SEEK_SET as libc:: c_short ;
1301
+ cvt ( unsafe { libc:: fcntl ( self . as_raw_fd ( ) , libc:: F_SETLKW , & flock) } ) ?;
1302
+ Ok ( ( ) )
1303
+ }
1304
+
1296
1305
#[ cfg( not( any(
1297
1306
target_os = "freebsd" ,
1298
1307
target_os = "fuchsia" ,
1299
1308
target_os = "linux" ,
1300
1309
target_os = "netbsd" ,
1301
1310
target_os = "openbsd" ,
1302
1311
target_os = "cygwin" ,
1312
+ target_os = "solaris" ,
1303
1313
target_vendor = "apple" ,
1304
1314
) ) ) ]
1305
1315
pub fn lock ( & self ) -> io:: Result < ( ) > {
@@ -1320,13 +1330,23 @@ impl File {
1320
1330
return Ok ( ( ) ) ;
1321
1331
}
1322
1332
1333
+ #[ cfg( target_os = "solaris" ) ]
1334
+ pub fn lock_shared ( & self ) -> io:: Result < ( ) > {
1335
+ let mut flock: libc:: flock = unsafe { mem:: zeroed ( ) } ;
1336
+ flock. l_type = libc:: F_RDLCK as libc:: c_short ;
1337
+ flock. l_whence = libc:: SEEK_SET as libc:: c_short ;
1338
+ cvt ( unsafe { libc:: fcntl ( self . as_raw_fd ( ) , libc:: F_SETLKW , & flock) } ) ?;
1339
+ Ok ( ( ) )
1340
+ }
1341
+
1323
1342
#[ cfg( not( any(
1324
1343
target_os = "freebsd" ,
1325
1344
target_os = "fuchsia" ,
1326
1345
target_os = "linux" ,
1327
1346
target_os = "netbsd" ,
1328
1347
target_os = "openbsd" ,
1329
1348
target_os = "cygwin" ,
1349
+ target_os = "solaris" ,
1330
1350
target_vendor = "apple" ,
1331
1351
) ) ) ]
1332
1352
pub fn lock_shared ( & self ) -> io:: Result < ( ) > {
@@ -1355,13 +1375,31 @@ impl File {
1355
1375
}
1356
1376
}
1357
1377
1378
+ #[ cfg( target_os = "solaris" ) ]
1379
+ pub fn try_lock ( & self ) -> Result < ( ) , TryLockError > {
1380
+ let mut flock: libc:: flock = unsafe { mem:: zeroed ( ) } ;
1381
+ flock. l_type = libc:: F_WRLCK as libc:: c_short ;
1382
+ flock. l_whence = libc:: SEEK_SET as libc:: c_short ;
1383
+ let result = cvt ( unsafe { libc:: fcntl ( self . as_raw_fd ( ) , libc:: F_SETLK , & flock) } ) ;
1384
+ if let Err ( err) = result {
1385
+ if err. kind ( ) == io:: ErrorKind :: WouldBlock {
1386
+ Err ( TryLockError :: WouldBlock )
1387
+ } else {
1388
+ Err ( TryLockError :: Error ( err) )
1389
+ }
1390
+ } else {
1391
+ Ok ( ( ) )
1392
+ }
1393
+ }
1394
+
1358
1395
#[ cfg( not( any(
1359
1396
target_os = "freebsd" ,
1360
1397
target_os = "fuchsia" ,
1361
1398
target_os = "linux" ,
1362
1399
target_os = "netbsd" ,
1363
1400
target_os = "openbsd" ,
1364
1401
target_os = "cygwin" ,
1402
+ target_os = "solaris" ,
1365
1403
target_vendor = "apple" ,
1366
1404
) ) ) ]
1367
1405
pub fn try_lock ( & self ) -> Result < ( ) , TryLockError > {
@@ -1393,13 +1431,31 @@ impl File {
1393
1431
}
1394
1432
}
1395
1433
1434
+ #[ cfg( target_os = "solaris" ) ]
1435
+ pub fn try_lock_shared ( & self ) -> Result < ( ) , TryLockError > {
1436
+ let mut flock: libc:: flock = unsafe { mem:: zeroed ( ) } ;
1437
+ flock. l_type = libc:: F_RDLCK as libc:: c_short ;
1438
+ flock. l_whence = libc:: SEEK_SET as libc:: c_short ;
1439
+ let result = cvt ( unsafe { libc:: fcntl ( self . as_raw_fd ( ) , libc:: F_SETLK , & flock) } ) ;
1440
+ if let Err ( err) = result {
1441
+ if err. kind ( ) == io:: ErrorKind :: WouldBlock {
1442
+ Err ( TryLockError :: WouldBlock )
1443
+ } else {
1444
+ Err ( TryLockError :: Error ( err) )
1445
+ }
1446
+ } else {
1447
+ Ok ( ( ) )
1448
+ }
1449
+ }
1450
+
1396
1451
#[ cfg( not( any(
1397
1452
target_os = "freebsd" ,
1398
1453
target_os = "fuchsia" ,
1399
1454
target_os = "linux" ,
1400
1455
target_os = "netbsd" ,
1401
1456
target_os = "openbsd" ,
1402
1457
target_os = "cygwin" ,
1458
+ target_os = "solaris" ,
1403
1459
target_vendor = "apple" ,
1404
1460
) ) ) ]
1405
1461
pub fn try_lock_shared ( & self ) -> Result < ( ) , TryLockError > {
@@ -1423,13 +1479,23 @@ impl File {
1423
1479
return Ok ( ( ) ) ;
1424
1480
}
1425
1481
1482
+ #[ cfg( target_os = "solaris" ) ]
1483
+ pub fn unlock ( & self ) -> io:: Result < ( ) > {
1484
+ let mut flock: libc:: flock = unsafe { mem:: zeroed ( ) } ;
1485
+ flock. l_type = libc:: F_UNLCK as libc:: c_short ;
1486
+ flock. l_whence = libc:: SEEK_SET as libc:: c_short ;
1487
+ cvt ( unsafe { libc:: fcntl ( self . as_raw_fd ( ) , libc:: F_SETLKW , & flock) } ) ?;
1488
+ Ok ( ( ) )
1489
+ }
1490
+
1426
1491
#[ cfg( not( any(
1427
1492
target_os = "freebsd" ,
1428
1493
target_os = "fuchsia" ,
1429
1494
target_os = "linux" ,
1430
1495
target_os = "netbsd" ,
1431
1496
target_os = "openbsd" ,
1432
1497
target_os = "cygwin" ,
1498
+ target_os = "solaris" ,
1433
1499
target_vendor = "apple" ,
1434
1500
) ) ) ]
1435
1501
pub fn unlock ( & self ) -> io:: Result < ( ) > {
0 commit comments