@@ -756,6 +756,36 @@ pub fn gethostname<'a>(buffer: &'a mut [u8]) -> Result<&'a CStr> {
756
756
} )
757
757
}
758
758
759
+ /// Set the NIS domain name (see
760
+ /// [setdomainname(2)](http://man7.org/linux/man-pages/man2/setdomainname.2.html)).
761
+ #[ cfg( target_os = "linux" ) ]
762
+ pub fn setdomainname < S : AsRef < OsStr > > ( name : S ) -> Result < ( ) > {
763
+ let ptr = name. as_ref ( ) . as_bytes ( ) . as_ptr ( ) as * const c_char ;
764
+ let len = name. as_ref ( ) . len ( ) as size_t ;
765
+
766
+ let res = unsafe { libc:: setdomainname ( ptr, len) } ;
767
+ Errno :: result ( res) . map ( drop)
768
+ }
769
+
770
+ /// Get the domain name and store it in the provided buffer, returning a pointer
771
+ /// the CStr in that buffer on success (see
772
+ /// [getdomainname(2)](http://man7.org/linux/man-pages/man2/getdomainname.2.html)).
773
+ ///
774
+ /// This function call attempts to get the NIS domain name for the running system
775
+ /// and store it in a provided buffer. The buffer will be populated with bytes up
776
+ /// to the length of the provided slice including a NUL terminating byte.
777
+ #[ cfg( target_os = "linux" ) ]
778
+ pub fn getdomainname < ' a > ( buffer : & ' a mut [ u8 ] ) -> Result < & ' a CStr > {
779
+ let ptr = buffer. as_mut_ptr ( ) as * mut c_char ;
780
+ let len = buffer. len ( ) as size_t ;
781
+
782
+ let res = unsafe { libc:: getdomainname ( ptr, len) } ;
783
+ Errno :: result ( res) . map ( |_| {
784
+ buffer[ len - 1 ] = 0 ; // ensure always null-terminated
785
+ unsafe { CStr :: from_ptr ( buffer. as_ptr ( ) as * const c_char ) }
786
+ } )
787
+ }
788
+
759
789
/// Close a raw file descriptor
760
790
///
761
791
/// Be aware that many Rust types implicitly close-on-drop, including
0 commit comments