@@ -1254,16 +1254,54 @@ impl File {
1254
1254
}
1255
1255
}
1256
1256
1257
+ #[ cfg( any(
1258
+ target_os = "freebsd" ,
1259
+ target_os = "linux" ,
1260
+ target_os = "netbsd" ,
1261
+ target_vendor = "apple" ,
1262
+ ) ) ]
1257
1263
pub fn lock ( & self ) -> io:: Result < ( ) > {
1258
1264
cvt ( unsafe { libc:: flock ( self . as_raw_fd ( ) , libc:: LOCK_EX ) } ) ?;
1259
1265
return Ok ( ( ) ) ;
1260
1266
}
1261
1267
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
+ ) ) ]
1262
1284
pub fn lock_shared ( & self ) -> io:: Result < ( ) > {
1263
1285
cvt ( unsafe { libc:: flock ( self . as_raw_fd ( ) , libc:: LOCK_SH ) } ) ?;
1264
1286
return Ok ( ( ) ) ;
1265
1287
}
1266
1288
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
+ ) ) ]
1267
1305
pub fn try_lock ( & self ) -> io:: Result < bool > {
1268
1306
let result = cvt ( unsafe { libc:: flock ( self . as_raw_fd ( ) , libc:: LOCK_EX | libc:: LOCK_NB ) } ) ;
1269
1307
if let Err ( ref err) = result {
@@ -1275,6 +1313,22 @@ impl File {
1275
1313
return Ok ( true ) ;
1276
1314
}
1277
1315
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
+ ) ) ]
1278
1332
pub fn try_lock_shared ( & self ) -> io:: Result < bool > {
1279
1333
let result = cvt ( unsafe { libc:: flock ( self . as_raw_fd ( ) , libc:: LOCK_SH | libc:: LOCK_NB ) } ) ;
1280
1334
if let Err ( ref err) = result {
@@ -1286,11 +1340,37 @@ impl File {
1286
1340
return Ok ( true ) ;
1287
1341
}
1288
1342
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
+ ) ) ]
1289
1359
pub fn unlock ( & self ) -> io:: Result < ( ) > {
1290
1360
cvt ( unsafe { libc:: flock ( self . as_raw_fd ( ) , libc:: LOCK_UN ) } ) ?;
1291
1361
return Ok ( ( ) ) ;
1292
1362
}
1293
1363
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
+
1294
1374
pub fn truncate ( & self , size : u64 ) -> io:: Result < ( ) > {
1295
1375
let size: off64_t =
1296
1376
size. try_into ( ) . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: InvalidInput , e) ) ?;
0 commit comments