File tree Expand file tree Collapse file tree 1 file changed +32
-2
lines changed Expand file tree Collapse file tree 1 file changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -395,8 +395,38 @@ mod sys {
395395
396396 #[ cfg( target_os = "solaris" ) ]
397397 fn flock ( file : & File , flag : libc:: c_int ) -> Result < ( ) > {
398- // Solaris lacks flock(), so simply succeed with a no-op
399- Ok ( ( ) )
398+ // Solaris lacks flock(), so try to emulate using fcntl()
399+ let mut flock = libc:: flock {
400+ l_type : 0 ,
401+ l_whence : 0 ,
402+ l_start : 0 ,
403+ l_len : 0 ,
404+ l_sysid : 0 ,
405+ l_pid : 0 ,
406+ l_pad : [ 0 , 0 , 0 , 0 ] ,
407+ } ;
408+ if ( flag & libc:: LOCK_SH ) != 0 {
409+ flock. l_type |= libc:: F_RDLCK ;
410+ }
411+ if ( flag & libc:: LOCK_EX ) != 0 {
412+ flock. l_type |= libc:: F_WRLCK ;
413+ }
414+ if ( flag & libc:: LOCK_UN ) != 0 {
415+ flock. l_type |= libc:: F_UNLCK ;
416+ }
417+
418+ let mut ltype = libc:: F_SETLKW ;
419+ if ( flag & libc:: LOCK_NB ) != 0 {
420+ ltype = libc:: F_SETLK ;
421+ }
422+
423+ let ret = unsafe { libc:: fcntl ( file. as_raw_fd ( ) , ltype, & flock) } ;
424+
425+ if ret < 0 {
426+ Err ( Error :: last_os_error ( ) )
427+ } else {
428+ Ok ( ( ) )
429+ }
400430 }
401431}
402432
You can’t perform that action at this time.
0 commit comments