Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/contrib/libgit-sys/src/lib.rs # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / contrib / libgit-sys / src / lib.rs` 79 lines ยท 2022 bytes Raw Blame History 1 use std::ffi::c_void; 2 3 #[cfg(has_std__ffi__c_char)] 4 use std::ffi::{c_char, c_int}; 5 6 #[cfg(not(has_std__ffi__c_char))] 7 #[allow(non_camel_case_types)] 8 pub type c_char = i8; 9 10 #[cfg(not(has_std__ffi__c_char))] 11 #[allow(non_camel_case_types)] 12 pub type c_int = i32; 13 14 extern crate libz_sys; 15 16 #[allow(non_camel_case_types)] 17 #[repr(C)] 18 pub struct libgit_config_set { 19 _data: [u8; 0], 20 _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>, 21 } 22 23 extern "C" { 24 pub fn free(ptr: *mut c_void); 25 26 pub fn libgit_user_agent() -> *const c_char; 27 pub fn libgit_user_agent_sanitized() -> *const c_char; 28 29 pub fn libgit_configset_alloc() -> *mut libgit_config_set; 30 pub fn libgit_configset_free(cs: *mut libgit_config_set); 31 32 pub fn libgit_configset_add_file(cs: *mut libgit_config_set, filename: *const c_char) -> c_int; 33 34 pub fn libgit_configset_get_int( 35 cs: *mut libgit_config_set, 36 key: *const c_char, 37 int: *mut c_int, 38 ) -> c_int; 39 40 pub fn libgit_configset_get_string( 41 cs: *mut libgit_config_set, 42 key: *const c_char, 43 dest: *mut *mut c_char, 44 ) -> c_int; 45 46 } 47 48 #[cfg(test)] 49 mod tests { 50 use std::ffi::CStr; 51 52 use super::*; 53 54 #[test] 55 fn user_agent_starts_with_git() { 56 let c_str = unsafe { CStr::from_ptr(libgit_user_agent()) }; 57 let agent = c_str 58 .to_str() 59 .expect("User agent contains invalid UTF-8 data"); 60 assert!( 61 agent.starts_with("git/"), 62 r#"Expected user agent to start with "git/", got: {}"#, 63 agent 64 ); 65 } 66 67 #[test] 68 fn sanitized_user_agent_starts_with_git() { 69 let c_str = unsafe { CStr::from_ptr(libgit_user_agent_sanitized()) }; 70 let agent = c_str 71 .to_str() 72 .expect("Sanitized user agent contains invalid UTF-8 data"); 73 assert!( 74 agent.starts_with("git/"), 75 r#"Expected user agent to start with "git/", got: {}"#, 76 agent 77 ); 78 } 79 }