Skip to content

Commit 00ce4a4

Browse files
committed
libc bindings for glob.h
only tested on linux/x86_64, but i got the values for other platforms from their system header files. no bindings for win32, because win32 doesn't include glob.h. also, glob() takes a callback for error handling, but i'm just making this a *c_void for now, since i don't know how to represent c calling back into rust (if that's even currently possible).
1 parent 1f98233 commit 00ce4a4

File tree

1 file changed

+106
-2
lines changed

1 file changed

+106
-2
lines changed

src/libcore/libc.rs

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub use libc::funcs::posix88::unistd::*;
104104

105105
pub use libc::funcs::posix01::stat_::*;
106106
pub use libc::funcs::posix01::unistd::*;
107+
pub use libc::funcs::posix01::glob::*;
107108
pub use libc::funcs::posix08::unistd::*;
108109

109110
pub use libc::funcs::bsd44::*;
@@ -210,7 +211,21 @@ pub mod types {
210211
#[cfg(target_os = "android")]
211212
pub mod os {
212213
pub mod common {
213-
pub mod posix01 {}
214+
pub mod posix01 {
215+
use libc::types::common::c95::{c_void};
216+
use libc::types::os::arch::c95::{c_char, size_t};
217+
pub struct glob_t {
218+
gl_pathc: size_t,
219+
gl_pathv: **c_char,
220+
gl_offs: size_t,
221+
222+
__unused1: *c_void,
223+
__unused2: *c_void,
224+
__unused3: *c_void,
225+
__unused4: *c_void,
226+
__unused5: *c_void,
227+
}
228+
}
214229
}
215230

216231
#[cfg(target_arch = "x86")]
@@ -369,7 +384,25 @@ pub mod types {
369384
#[cfg(target_os = "freebsd")]
370385
pub mod os {
371386
pub mod common {
372-
pub mod posix01 {}
387+
pub mod posix01 {
388+
use libc::types::common::c95::{c_void};
389+
use libc::types::os::arch::c95::{c_char, c_int, size_t};
390+
struct glob_t {
391+
gl_pathc: size_t,
392+
__unused1: size_t,
393+
gl_offs: size_t,
394+
__unused2: c_int,
395+
gl_pathv: **c_char,
396+
397+
__unused3: *c_void,
398+
399+
__unused4: *c_void,
400+
__unused5: *c_void,
401+
__unused6: *c_void,
402+
__unused7: *c_void,
403+
__unused8: *c_void,
404+
}
405+
}
373406
}
374407

375408
#[cfg(target_arch = "x86_64")]
@@ -571,6 +604,23 @@ pub mod types {
571604
pub mod os {
572605
pub mod common {
573606
pub mod posix01 {
607+
use libc::types::common::c95::{c_void};
608+
use libc::types::os::arch::c95::{c_char, c_int, size_t};
609+
struct glob_t {
610+
gl_pathc: size_t,
611+
__unused1: c_int,
612+
gl_offs: size_t,
613+
__unused2: c_int,
614+
gl_pathv: **c_char,
615+
616+
__unused3: *c_void,
617+
618+
__unused4: *c_void,
619+
__unused5: *c_void,
620+
__unused6: *c_void,
621+
__unused7: *c_void,
622+
__unused8: *c_void,
623+
}
574624
}
575625
}
576626

@@ -877,6 +927,18 @@ pub mod consts {
877927
}
878928
pub mod posix01 {
879929
pub static SIGTRAP : int = 5;
930+
931+
pub static GLOB_ERR : int = 1 << 0;
932+
pub static GLOB_MARK : int = 1 << 1;
933+
pub static GLOB_NOSORT : int = 1 << 2;
934+
pub static GLOB_DOOFFS : int = 1 << 3;
935+
pub static GLOB_NOCHECK : int = 1 << 4;
936+
pub static GLOB_APPEND : int = 1 << 5;
937+
pub static GLOB_NOESCAPE : int = 1 << 6;
938+
939+
pub static GLOB_NOSPACE : int = 1;
940+
pub static GLOB_ABORTED : int = 2;
941+
pub static GLOB_NOMATCH : int = 3;
880942
}
881943
pub mod posix08 {
882944
}
@@ -956,6 +1018,18 @@ pub mod consts {
9561018
}
9571019
pub mod posix01 {
9581020
pub static SIGTRAP : int = 5;
1021+
1022+
pub static GLOB_APPEND : int = 0x0001;
1023+
pub static GLOB_DOOFFS : int = 0x0002;
1024+
pub static GLOB_ERR : int = 0x0004;
1025+
pub static GLOB_MARK : int = 0x0008;
1026+
pub static GLOB_NOCHECK : int = 0x0010;
1027+
pub static GLOB_NOSORT : int = 0x0020;
1028+
pub static GLOB_NOESCAPE : int = 0x2000;
1029+
1030+
pub static GLOB_NOSPACE : int = -1;
1031+
pub static GLOB_ABORTED : int = -2;
1032+
pub static GLOB_NOMATCH : int = -3;
9591033
}
9601034
pub mod posix08 {
9611035
}
@@ -1036,6 +1110,18 @@ pub mod consts {
10361110
}
10371111
pub mod posix01 {
10381112
pub static SIGTRAP : int = 5;
1113+
1114+
pub static GLOB_APPEND : int = 0x0001;
1115+
pub static GLOB_DOOFFS : int = 0x0002;
1116+
pub static GLOB_ERR : int = 0x0004;
1117+
pub static GLOB_MARK : int = 0x0008;
1118+
pub static GLOB_NOCHECK : int = 0x0010;
1119+
pub static GLOB_NOSORT : int = 0x0020;
1120+
pub static GLOB_NOESCAPE : int = 0x2000;
1121+
1122+
pub static GLOB_NOSPACE : int = -1;
1123+
pub static GLOB_ABORTED : int = -2;
1124+
pub static GLOB_NOMATCH : int = -3;
10391125
}
10401126
pub mod posix08 {
10411127
}
@@ -1606,6 +1692,21 @@ pub mod funcs {
16061692
-> pid_t;
16071693
}
16081694
}
1695+
1696+
#[nolink]
1697+
#[abi = "cdecl"]
1698+
pub mod glob {
1699+
use libc::types::common::c95::{c_void};
1700+
use libc::types::os::arch::c95::{c_char, c_int};
1701+
use libc::types::os::common::posix01::{glob_t};
1702+
1703+
pub extern {
1704+
unsafe fn glob(pattern: *c_char, flags: c_int,
1705+
errfunc: *c_void, // XXX callback
1706+
pglob: *mut glob_t);
1707+
unsafe fn globfree(pglob: *mut glob_t);
1708+
}
1709+
}
16091710
}
16101711

16111712
#[cfg(target_os = "win32")]
@@ -1615,6 +1716,9 @@ pub mod funcs {
16151716

16161717
pub mod unistd {
16171718
}
1719+
1720+
pub mod glob {
1721+
}
16181722
}
16191723

16201724

0 commit comments

Comments
 (0)