Skip to content

Commit

Permalink
Add support for libc::time_t and related types
Browse files Browse the repository at this point in the history
  • Loading branch information
sdroege authored and bilelmoussaoui committed Apr 3, 2024
1 parent 44c49bb commit eb5be4f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/analysis/conversion_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ impl ConversionType {
Filename => Self::Pointer,
OsString => Self::Pointer,
Type => Self::Scalar,
TimeT => Self::Direct,
OffT => Self::Direct,
DevT => Self::Direct,
GidT => Self::Direct,
PidT => Self::Direct,
SockLenT => Self::Direct,
UidT => Self::Direct,
None => Self::Unknown,
IntPtr => Self::Direct,
UIntPtr => Self::Direct,
Expand Down
7 changes: 7 additions & 0 deletions src/analysis/ffi_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ fn ffi_inner(env: &Env, tid: TypeId, inner: &str) -> Result {
SSize => "libc::ssize_t",
Float => "libc::c_float",
Double => "libc::c_double",
TimeT => "libc::time_t",
OffT => "libc::off_t",
DevT => "libc::dev_t",
GidT => "libc::gid_t",
PidT => "libc::pid_t",
SockLenT => "libc::socklen_t",
UidT => "libc::uid_t",
UniChar => "u32",
Utf8 => "libc::c_char",
Filename => "libc::c_char",
Expand Down
7 changes: 7 additions & 0 deletions src/codegen/sys/ffi_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ fn ffi_inner(env: &Env, tid: library::TypeId, mut inner: String) -> Result {
ULong => "c_ulong",
Size => "size_t",
SSize => "ssize_t",
TimeT => "time_t",
OffT => "off_t",
DevT => "dev_t",
GidT => "gid_t",
PidT => "pid_t",
SockLenT => "socklen_t",
UidT => "uid_t",
Float => "c_float",
Double => "c_double",
UniChar => "u32",
Expand Down
5 changes: 4 additions & 1 deletion src/codegen/sys/statics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ pub fn after_extern_crates(w: &mut dyn Write) -> Result<()> {
"#[allow(unused_imports)]",
"use libc::{c_int, c_char, c_uchar, c_float, c_uint, c_double,",
" c_short, c_ushort, c_long, c_ulong,",
" c_void, size_t, ssize_t, intptr_t, uintptr_t, FILE};",
" c_void, size_t, ssize_t, time_t, off_t, intptr_t, uintptr_t, FILE};",
"#[cfg(unix)]",
"#[allow(unused_imports)]",
"use libc::{dev_t, gid_t, pid_t, socklen_t, uid_t};",
];

write_vec(w, &v)
Expand Down
14 changes: 14 additions & 0 deletions src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ pub enum Basic {
Type,
IntPtr,
UIntPtr,
TimeT,
OffT,
DevT,
GidT,
PidT,
SockLenT,
UidT,
// Same encoding as Filename but can contains any string
// Not defined in GLib directly
OsString,
Expand Down Expand Up @@ -303,6 +310,13 @@ const BASIC: &[(&str, Basic)] = &[
// TODO: this is temporary name, change it when type added to GLib
("os_string", Basic::OsString),
("bool", Basic::Bool),
("time_t", Basic::TimeT),
("off_t", Basic::OffT),
("dev_t", Basic::DevT),
("gid_t", Basic::GidT),
("pid_t", Basic::PidT),
("socklen_t", Basic::SockLenT),
("uid_t", Basic::UidT),
];

#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq, PartialOrd, Ord)]
Expand Down

0 comments on commit eb5be4f

Please sign in to comment.