@@ -1293,13 +1293,23 @@ impl File {
12931293 return Ok ( ( ) ) ;
12941294 }
12951295
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_SETLK , & flock) } ) ?;
1302+ Ok ( ( ) )
1303+ }
1304+
12961305 #[ cfg( not( any(
12971306 target_os = "freebsd" ,
12981307 target_os = "fuchsia" ,
12991308 target_os = "linux" ,
13001309 target_os = "netbsd" ,
13011310 target_os = "openbsd" ,
13021311 target_os = "cygwin" ,
1312+ target_os = "solaris" ,
13031313 target_vendor = "apple" ,
13041314 ) ) ) ]
13051315 pub fn lock ( & self ) -> io:: Result < ( ) > {
@@ -1320,13 +1330,23 @@ impl File {
13201330 return Ok ( ( ) ) ;
13211331 }
13221332
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_SETLK , & flock) } ) ?;
1339+ Ok ( ( ) )
1340+ }
1341+
13231342 #[ cfg( not( any(
13241343 target_os = "freebsd" ,
13251344 target_os = "fuchsia" ,
13261345 target_os = "linux" ,
13271346 target_os = "netbsd" ,
13281347 target_os = "openbsd" ,
13291348 target_os = "cygwin" ,
1349+ target_os = "solaris" ,
13301350 target_vendor = "apple" ,
13311351 ) ) ) ]
13321352 pub fn lock_shared ( & self ) -> io:: Result < ( ) > {
@@ -1355,13 +1375,31 @@ impl File {
13551375 }
13561376 }
13571377
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_SETLKW , & 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+
13581395 #[ cfg( not( any(
13591396 target_os = "freebsd" ,
13601397 target_os = "fuchsia" ,
13611398 target_os = "linux" ,
13621399 target_os = "netbsd" ,
13631400 target_os = "openbsd" ,
13641401 target_os = "cygwin" ,
1402+ target_os = "solaris" ,
13651403 target_vendor = "apple" ,
13661404 ) ) ) ]
13671405 pub fn try_lock ( & self ) -> Result < ( ) , TryLockError > {
@@ -1393,13 +1431,31 @@ impl File {
13931431 }
13941432 }
13951433
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_SETLKW , & 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+
13961451 #[ cfg( not( any(
13971452 target_os = "freebsd" ,
13981453 target_os = "fuchsia" ,
13991454 target_os = "linux" ,
14001455 target_os = "netbsd" ,
14011456 target_os = "openbsd" ,
14021457 target_os = "cygwin" ,
1458+ target_os = "solaris" ,
14031459 target_vendor = "apple" ,
14041460 ) ) ) ]
14051461 pub fn try_lock_shared ( & self ) -> Result < ( ) , TryLockError > {
@@ -1423,13 +1479,23 @@ impl File {
14231479 return Ok ( ( ) ) ;
14241480 }
14251481
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_SETLK , & flock) } ) ?;
1488+ Ok ( ( ) )
1489+ }
1490+
14261491 #[ cfg( not( any(
14271492 target_os = "freebsd" ,
14281493 target_os = "fuchsia" ,
14291494 target_os = "linux" ,
14301495 target_os = "netbsd" ,
14311496 target_os = "openbsd" ,
14321497 target_os = "cygwin" ,
1498+ target_os = "solaris" ,
14331499 target_vendor = "apple" ,
14341500 ) ) ) ]
14351501 pub fn unlock ( & self ) -> io:: Result < ( ) > {
0 commit comments