1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use std::ffi::CStr;
use std::slice;
use std::str;
#[derive(Debug)]
pub struct LibraryVersion {
version: &'static str,
camlibs: &'static str,
compiler: &'static str,
ltdl: &'static str,
exif: &'static str,
}
impl LibraryVersion {
fn new() -> LibraryVersion {
let ptr = unsafe {
::gphoto2::gp_library_version(::gphoto2::GPVersionVerbosity::GP_VERSION_SHORT)
};
let mut len: usize = 0;
while !unsafe { *ptr.offset(len as isize) }.is_null() {
len += 1;
}
assert!(len >= 5);
let table = unsafe {
slice::from_raw_parts(ptr, len)
};
LibraryVersion {
version: unsafe { str::from_utf8_unchecked(CStr::from_ptr(table[0]).to_bytes()) },
camlibs: unsafe { str::from_utf8_unchecked(CStr::from_ptr(table[1]).to_bytes()) },
compiler: unsafe { str::from_utf8_unchecked(CStr::from_ptr(table[2]).to_bytes()) },
ltdl: unsafe { str::from_utf8_unchecked(CStr::from_ptr(table[3]).to_bytes()) },
exif: unsafe { str::from_utf8_unchecked(CStr::from_ptr(table[4]).to_bytes()) },
}
}
pub fn version(&self) -> &str {
self.version
}
pub fn camlibs(&self) -> &str {
self.camlibs
}
pub fn compiler(&self) -> &str {
self.compiler
}
pub fn ltdl(&self) -> &str {
self.ltdl
}
pub fn exif(&self) -> &str {
self.exif
}
}
pub fn libgphoto2_version() -> LibraryVersion {
LibraryVersion::new()
}