@@ -1254,16 +1254,54 @@ impl File {
12541254 }
12551255 }
12561256
1257+ #[ cfg( any(
1258+ target_os = "freebsd" ,
1259+ target_os = "linux" ,
1260+ target_os = "netbsd" ,
1261+ target_vendor = "apple" ,
1262+ ) ) ]
12571263 pub fn lock ( & self ) -> io:: Result < ( ) > {
12581264 cvt ( unsafe { libc:: flock ( self . as_raw_fd ( ) , libc:: LOCK_EX ) } ) ?;
12591265 return Ok ( ( ) ) ;
12601266 }
12611267
1268+ #[ cfg( not( any(
1269+ target_os = "freebsd" ,
1270+ target_os = "linux" ,
1271+ target_os = "netbsd" ,
1272+ target_vendor = "apple" ,
1273+ ) ) ) ]
1274+ pub fn lock ( & self ) -> io:: Result < ( ) > {
1275+ Err ( io:: const_io_error!( io:: ErrorKind :: Unsupported , "lock() not supported" ) )
1276+ }
1277+
1278+ #[ cfg( any(
1279+ target_os = "freebsd" ,
1280+ target_os = "linux" ,
1281+ target_os = "netbsd" ,
1282+ target_vendor = "apple" ,
1283+ ) ) ]
12621284 pub fn lock_shared ( & self ) -> io:: Result < ( ) > {
12631285 cvt ( unsafe { libc:: flock ( self . as_raw_fd ( ) , libc:: LOCK_SH ) } ) ?;
12641286 return Ok ( ( ) ) ;
12651287 }
12661288
1289+ #[ cfg( not( any(
1290+ target_os = "freebsd" ,
1291+ target_os = "linux" ,
1292+ target_os = "netbsd" ,
1293+ target_vendor = "apple" ,
1294+ ) ) ) ]
1295+ pub fn lock_shared ( & self ) -> io:: Result < ( ) > {
1296+ Err ( io:: const_io_error!( io:: ErrorKind :: Unsupported , "lock_shared() not supported" ) )
1297+ }
1298+
1299+ #[ cfg( any(
1300+ target_os = "freebsd" ,
1301+ target_os = "linux" ,
1302+ target_os = "netbsd" ,
1303+ target_vendor = "apple" ,
1304+ ) ) ]
12671305 pub fn try_lock ( & self ) -> io:: Result < bool > {
12681306 let result = cvt ( unsafe { libc:: flock ( self . as_raw_fd ( ) , libc:: LOCK_EX | libc:: LOCK_NB ) } ) ;
12691307 if let Err ( ref err) = result {
@@ -1275,6 +1313,22 @@ impl File {
12751313 return Ok ( true ) ;
12761314 }
12771315
1316+ #[ cfg( not( any(
1317+ target_os = "freebsd" ,
1318+ target_os = "linux" ,
1319+ target_os = "netbsd" ,
1320+ target_vendor = "apple" ,
1321+ ) ) ) ]
1322+ pub fn try_lock ( & self ) -> io:: Result < bool > {
1323+ Err ( io:: const_io_error!( io:: ErrorKind :: Unsupported , "try_lock() not supported" ) )
1324+ }
1325+
1326+ #[ cfg( any(
1327+ target_os = "freebsd" ,
1328+ target_os = "linux" ,
1329+ target_os = "netbsd" ,
1330+ target_vendor = "apple" ,
1331+ ) ) ]
12781332 pub fn try_lock_shared ( & self ) -> io:: Result < bool > {
12791333 let result = cvt ( unsafe { libc:: flock ( self . as_raw_fd ( ) , libc:: LOCK_SH | libc:: LOCK_NB ) } ) ;
12801334 if let Err ( ref err) = result {
@@ -1286,11 +1340,37 @@ impl File {
12861340 return Ok ( true ) ;
12871341 }
12881342
1343+ #[ cfg( not( any(
1344+ target_os = "freebsd" ,
1345+ target_os = "linux" ,
1346+ target_os = "netbsd" ,
1347+ target_vendor = "apple" ,
1348+ ) ) ) ]
1349+ pub fn try_lock_shared ( & self ) -> io:: Result < bool > {
1350+ Err ( io:: const_io_error!( io:: ErrorKind :: Unsupported , "try_lock_shared() not supported" ) )
1351+ }
1352+
1353+ #[ cfg( any(
1354+ target_os = "freebsd" ,
1355+ target_os = "linux" ,
1356+ target_os = "netbsd" ,
1357+ target_vendor = "apple" ,
1358+ ) ) ]
12891359 pub fn unlock ( & self ) -> io:: Result < ( ) > {
12901360 cvt ( unsafe { libc:: flock ( self . as_raw_fd ( ) , libc:: LOCK_UN ) } ) ?;
12911361 return Ok ( ( ) ) ;
12921362 }
12931363
1364+ #[ cfg( not( any(
1365+ target_os = "freebsd" ,
1366+ target_os = "linux" ,
1367+ target_os = "netbsd" ,
1368+ target_vendor = "apple" ,
1369+ ) ) ) ]
1370+ pub fn unlock ( & self ) -> io:: Result < ( ) > {
1371+ Err ( io:: const_io_error!( io:: ErrorKind :: Unsupported , "unlock() not supported" ) )
1372+ }
1373+
12941374 pub fn truncate ( & self , size : u64 ) -> io:: Result < ( ) > {
12951375 let size: off64_t =
12961376 size. try_into ( ) . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: InvalidInput , e) ) ?;
0 commit comments