@@ -231,6 +231,34 @@ fn devname(dev: dev_t) -> Option<String> {
231231 Some ( String :: from_utf8 ( dev_name) . expect ( "Returned device name is not valid utf8" ) )
232232}
233233
234+ #[ cfg( target_os = "openbsd" ) ]
235+ fn devname ( dev : dev_t ) -> Option < String > {
236+ use std:: ffi:: CStr ;
237+ use std:: os:: raw:: { c_char, c_int} ;
238+
239+ let buf = unsafe {
240+ libc:: devname (
241+ dev,
242+ libc:: S_IFCHR , // Must be S_IFCHR or S_IFBLK
243+ )
244+ } ;
245+
246+ if buf. is_null ( ) {
247+ return None ;
248+ }
249+
250+ let dev_str =
251+ unsafe { CStr :: from_ptr ( buf) . to_str ( ) } . expect ( "Returned device name is not valid utf8" ) ;
252+
253+ // If no device matches the specified values, or no information is
254+ // available, a pointer to the string "??" is returned.
255+ if dev_str == "??" {
256+ return None ;
257+ }
258+
259+ Some ( dev_str. to_owned ( ) )
260+ }
261+
234262/// Returns if the given device by major:minor pair is a DRM device.
235263#[ cfg( target_os = "linux" ) ]
236264pub fn is_device_drm ( dev : dev_t ) -> bool {
@@ -241,7 +269,7 @@ pub fn is_device_drm(dev: dev_t) -> bool {
241269}
242270
243271/// Returns if the given device by major:minor pair is a DRM device.
244- #[ cfg( target_os = "freebsd" ) ]
272+ #[ cfg( any ( target_os = "freebsd" , target_os = "openbsd" ) ) ]
245273pub fn is_device_drm ( dev : dev_t ) -> bool {
246274 devname ( dev) . map_or ( false , |dev_name| {
247275 dev_name. starts_with ( "drm/" )
@@ -252,7 +280,7 @@ pub fn is_device_drm(dev: dev_t) -> bool {
252280}
253281
254282/// Returns if the given device by major:minor pair is a DRM device.
255- #[ cfg( not( any( target_os = "linux" , target_os = "freebsd" ) ) ) ]
283+ #[ cfg( not( any( target_os = "linux" , target_os = "freebsd" , target_os = "openbsd" ) ) ) ]
256284pub fn is_device_drm ( dev : dev_t ) -> bool {
257285 major ( dev) == DRM_MAJOR
258286}
@@ -313,7 +341,7 @@ pub fn dev_path(dev: dev_t, ty: NodeType) -> io::Result<PathBuf> {
313341}
314342
315343/// Returns the path of a specific type of node from the DRM device described by major and minor device numbers.
316- #[ cfg( target_os = "freebsd" ) ]
344+ #[ cfg( any ( target_os = "freebsd" , target_os = "openbsd" ) ) ]
317345pub fn dev_path ( dev : dev_t , ty : NodeType ) -> io:: Result < PathBuf > {
318346 // Based on libdrm `drmGetMinorNameForFD`. Should be updated if the code
319347 // there is replaced with anything more sensible...
@@ -351,7 +379,7 @@ pub fn dev_path(dev: dev_t, ty: NodeType) -> io::Result<PathBuf> {
351379}
352380
353381/// Returns the path of a specific type of node from the DRM device described by major and minor device numbers.
354- #[ cfg( not( any( target_os = "linux" , target_os = "freebsd" ) ) ) ]
382+ #[ cfg( not( any( target_os = "linux" , target_os = "freebsd" , target_os = "openbsd" ) ) ) ]
355383pub fn dev_path ( dev : dev_t , ty : NodeType ) -> io:: Result < PathBuf > {
356384 use std:: io:: ErrorKind ;
357385
0 commit comments