Skip to content

Commit 37010b7

Browse files
committed
Add a bunch of definitions
1 parent 5949f39 commit 37010b7

File tree

2 files changed

+293
-3
lines changed

2 files changed

+293
-3
lines changed

src/unix/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ pub const DT_REG: u8 = 8;
223223
pub const DT_LNK: u8 = 10;
224224
pub const DT_SOCK: u8 = 12;
225225

226+
#[cfg(not(target_os = "redox"))]
226227
pub const FD_CLOEXEC: ::c_int = 0x1;
227228

228229
pub const USRQUOTA: ::c_int = 0;

src/unix/redox/mod.rs

Lines changed: 292 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub type wchar_t = i32;
66
pub type blkcnt_t = ::c_ulong;
77
pub type blksize_t = ::c_long;
88
pub type clock_t = ::c_long;
9+
pub type clockid_t = ::c_int;
910
pub type dev_t = ::c_long;
1011
pub type fsblkcnt_t = ::c_ulong;
1112
pub type fsfilcnt_t = ::c_ulong;
@@ -64,6 +65,10 @@ s! {
6465
fds_bits: [::c_ulong; ::FD_SETSIZE / ULONG_SIZE],
6566
}
6667

68+
pub struct in_addr {
69+
pub s_addr: ::in_addr_t,
70+
}
71+
6772
pub struct lconv {
6873
pub currency_symbol: *const ::c_char,
6974
pub decimal_point: *const ::c_char,
@@ -107,6 +112,35 @@ s! {
107112
pub sa_data: [::c_char; 14],
108113
}
109114

115+
pub struct sockaddr_in {
116+
pub sin_family: ::sa_family_t,
117+
pub sin_port: ::in_port_t,
118+
pub sin_addr: ::in_addr,
119+
pub sin_zero: [::c_char; 8],
120+
}
121+
122+
pub struct sockaddr_in6 {
123+
pub sin6_family: ::sa_family_t,
124+
pub sin6_port: ::in_port_t,
125+
pub sin6_flowinfo: u32,
126+
pub sin6_addr: ::in6_addr,
127+
pub sin6_scope_id: u32,
128+
}
129+
130+
pub struct sockaddr_storage {
131+
pub ss_family: ::sa_family_t,
132+
__ss_padding: [
133+
u8;
134+
128 - ::core::mem::size_of::<sa_family_t>() - ::core::mem::size_of::<c_ulong>()
135+
],
136+
__ss_align: ::c_ulong,
137+
}
138+
139+
pub struct sockaddr_un {
140+
pub sun_family: ::sa_family_t,
141+
pub sun_path: [::c_char; 108]
142+
}
143+
110144
pub struct stat {
111145
pub st_dev: ::dev_t,
112146
pub st_ino: ::ino_t,
@@ -118,9 +152,12 @@ s! {
118152
pub st_size: ::off_t,
119153
pub st_blksize: ::blksize_t,
120154
pub st_blocks: ::blkcnt_t,
121-
pub st_atime: ::timespec,
122-
pub st_mtime: ::timespec,
123-
pub st_ctime: ::timespec,
155+
pub st_atime: ::time_t,
156+
pub st_atime_nsec: ::c_long,
157+
pub st_mtime: ::time_t,
158+
pub st_mtime_nsec: ::c_long,
159+
pub st_ctime: ::time_t,
160+
pub st_ctime_nsec: ::c_long,
124161
_pad: [::c_char; 24],
125162
}
126163

@@ -164,9 +201,261 @@ s! {
164201
}
165202
}
166203

204+
// TODO: relibc
205+
pub const RTLD_DEFAULT: *mut ::c_void = 0i64 as *mut ::c_void;
206+
207+
// errno.h
208+
pub const EPERM: ::c_int = 1;
209+
pub const ENOENT: ::c_int = 2;
210+
pub const ESRCH: ::c_int = 3;
211+
pub const EINTR: ::c_int = 4;
212+
pub const EIO: ::c_int = 5;
213+
pub const ENXIO: ::c_int = 6;
214+
pub const E2BIG: ::c_int = 7;
215+
pub const ENOEXEC: ::c_int = 8;
216+
pub const EBADF: ::c_int = 9;
217+
pub const ECHILD: ::c_int = 10;
218+
pub const EAGAIN: ::c_int = 11;
219+
pub const ENOMEM: ::c_int = 12;
220+
pub const EACCES: ::c_int = 13;
221+
pub const EFAULT: ::c_int = 14;
222+
pub const ENOTBLK: ::c_int = 15;
223+
pub const EBUSY: ::c_int = 16;
224+
pub const EEXIST: ::c_int = 17;
225+
pub const EXDEV: ::c_int = 18;
226+
pub const ENODEV: ::c_int = 19;
227+
pub const ENOTDIR: ::c_int = 20;
228+
pub const EISDIR: ::c_int = 21;
229+
pub const EINVAL: ::c_int = 22;
230+
pub const ENFILE: ::c_int = 23;
231+
pub const EMFILE: ::c_int = 24;
232+
pub const ENOTTY: ::c_int = 25;
233+
pub const ETXTBSY: ::c_int = 26;
234+
pub const EFBIG: ::c_int = 27;
235+
pub const ENOSPC: ::c_int = 28;
236+
pub const ESPIPE: ::c_int = 29;
237+
pub const EROFS: ::c_int = 30;
238+
pub const EMLINK: ::c_int = 31;
239+
pub const EPIPE: ::c_int = 32;
240+
pub const EDOM: ::c_int = 33;
241+
pub const ERANGE: ::c_int = 34;
242+
pub const EDEADLK: ::c_int = 35;
243+
pub const ENOSYS: ::c_int = 38;
244+
pub const EWOULDBLOCK: ::c_int = 41;
245+
pub const EADDRINUSE: ::c_int = 98;
246+
pub const EADDRNOTAVAIL: ::c_int = 99;
247+
pub const ECONNABORTED: ::c_int = 103;
248+
pub const ECONNRESET: ::c_int = 104;
249+
pub const ENOTCONN: ::c_int = 107;
250+
pub const ETIMEDOUT: ::c_int = 110;
251+
pub const ECONNREFUSED: ::c_int = 111;
252+
pub const EINPROGRESS: ::c_int = 115;
253+
254+
// fcntl.h
255+
pub const F_DUPFD: ::c_int = 0;
256+
pub const F_GETFD: ::c_int = 1;
257+
pub const F_SETFD: ::c_int = 2;
258+
pub const F_GETFL: ::c_int = 3;
259+
pub const F_SETFL: ::c_int = 4;
260+
// TODO: relibc
261+
pub const F_DUPFD_CLOEXEC: ::c_int = ::F_DUPFD;
262+
pub const FD_CLOEXEC: ::c_int = 0x0100_0000;
263+
pub const O_RDONLY: ::c_int = 0x0001_0000;
264+
pub const O_WRONLY: ::c_int = 0x0002_0000;
265+
pub const O_RDWR: ::c_int = 0x0003_0000;
266+
pub const O_ACCMODE: ::c_int = 0x0003_0000;
267+
pub const O_NONBLOCK: ::c_int = 0x0004_0000;
268+
pub const O_APPEND: ::c_int = 0x0008_0000;
269+
pub const O_SHLOCK: ::c_int = 0x0010_0000;
270+
pub const O_EXLOCK: ::c_int = 0x0020_0000;
271+
pub const O_ASYNC: ::c_int = 0x0040_0000;
272+
pub const O_FSYNC: ::c_int = 0x0080_0000;
273+
pub const O_CLOEXEC: ::c_int = 0x0100_0000;
274+
pub const O_CREAT: ::c_int = 0x0200_0000;
275+
pub const O_TRUNC: ::c_int = 0x0400_0000;
276+
pub const O_EXCL: ::c_int = 0x0800_0000;
277+
pub const O_DIRECTORY: ::c_int = 0x1000_0000;
278+
pub const O_PATH: ::c_int = 0x2000_0000;
279+
pub const O_SYMLINK: ::c_int = 0x4000_0000;
280+
// Negative to allow it to be used as int
281+
// TODO: Fix negative values missing from includes
282+
pub const O_NOFOLLOW: ::c_int = -0x8000_0000;
283+
284+
// malloc.h
285+
extern {
286+
pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void;
287+
}
288+
289+
// netdb.h
290+
pub const EAI_SYSTEM: ::c_int = -11;
291+
292+
// netinet/tcp.h
293+
pub const TCP_NODELAY: ::c_int = 1;
294+
295+
// poll.h
296+
pub const POLLIN: ::c_short = 0x001;
297+
pub const POLLPRI: ::c_short = 0x002;
298+
pub const POLLOUT: ::c_short = 0x004;
299+
pub const POLLERR: ::c_short = 0x008;
300+
pub const POLLHUP: ::c_short = 0x010;
301+
pub const POLLNVAL: ::c_short = 0x020;
302+
303+
// pthread.h
304+
pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0;
305+
pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1;
306+
pub const PTHREAD_MUTEX_INITIALIZER: ::pthread_mutex_t = -1isize as *mut _;
307+
pub const PTHREAD_COND_INITIALIZER: ::pthread_cond_t = -1isize as *mut _;
308+
pub const PTHREAD_RWLOCK_INITIALIZER: ::pthread_rwlock_t = -1isize as *mut _;
309+
310+
// signal.h
311+
pub const SIG_BLOCK: ::c_int = 0;
312+
pub const SIG_UNBLOCK: ::c_int = 1;
313+
pub const SIG_SETMASK: ::c_int = 2;
314+
pub const SIGHUP: ::c_int = 1;
315+
pub const SIGINT: ::c_int = 2;
316+
pub const SIGQUIT: ::c_int = 3;
317+
pub const SIGILL: ::c_int = 4;
318+
pub const SIGTRAP: ::c_int = 5;
319+
pub const SIGABRT: ::c_int = 6;
320+
pub const SIGBUS: ::c_int = 7;
321+
pub const SIGFPE: ::c_int = 8;
322+
pub const SIGKILL: ::c_int = 9;
323+
pub const SIGUSR1: ::c_int = 10;
324+
pub const SIGSEGV: ::c_int = 11;
325+
pub const SIGUSR2: ::c_int = 12;
326+
pub const SIGPIPE: ::c_int = 13;
327+
pub const SIGALRM: ::c_int = 14;
328+
pub const SIGTERM: ::c_int = 15;
329+
pub const SIGSTKFLT: ::c_int = 16;
330+
pub const SIGCHLD: ::c_int = 17;
331+
pub const SIGCONT: ::c_int = 18;
332+
pub const SIGSTOP: ::c_int = 19;
333+
pub const SIGTSTP: ::c_int = 20;
334+
pub const SIGTTIN: ::c_int = 21;
335+
pub const SIGTTOU: ::c_int = 22;
336+
pub const SIGURG: ::c_int = 23;
337+
pub const SIGXCPU: ::c_int = 24;
338+
pub const SIGXFSZ: ::c_int = 25;
339+
pub const SIGVTALRM: ::c_int = 26;
340+
pub const SIGPROF: ::c_int = 27;
341+
pub const SIGWINCH: ::c_int = 28;
342+
pub const SIGIO: ::c_int = 29;
343+
pub const SIGPWR: ::c_int = 30;
344+
pub const SIGSYS: ::c_int = 31;
345+
pub const NSIG: ::c_int = 32;
346+
347+
// stat.h
348+
pub const S_IFDIR: ::c_int = 0o040_000;
349+
pub const S_IFCHR: ::c_int = 0o020_000;
350+
pub const S_IFBLK: ::c_int = 0o060_000;
351+
pub const S_IFREG: ::c_int = 0o100_000;
352+
pub const S_IFIFO: ::c_int = 0o010_000;
353+
pub const S_IFLNK: ::c_int = 0o120_000;
354+
pub const S_IFSOCK: ::c_int = 0o140_000;
355+
pub const S_IFMT: ::c_int = 0o0_170_000;
356+
357+
// stdlib.h
358+
pub const EXIT_SUCCESS: ::c_int = 0;
359+
pub const EXIT_FAILURE: ::c_int = 1;
360+
361+
// sys/ioctl.h
362+
// TODO: relibc
363+
pub const FIONBIO: ::c_int = 0x5421;
364+
// TODO: relibc
365+
pub const FIOCLEX: ::c_int = 0x5451;
366+
extern {
367+
pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
368+
}
369+
370+
// sys/select.h
167371
pub const FD_SETSIZE: usize = 1024;
372+
373+
// sys/socket.h
374+
pub const AF_UNIX: ::c_int = 1;
375+
pub const AF_INET: ::c_int = 2;
376+
pub const AF_INET6: ::c_int = 10;
377+
pub const MSG_PEEK: ::c_int = 2;
378+
pub const SHUT_RD: ::c_int = 0;
379+
pub const SHUT_WR: ::c_int = 1;
380+
pub const SHUT_RDWR: ::c_int = 2;
381+
pub const SO_ERROR: ::c_int = 4;
382+
pub const SO_RCVTIMEO: ::c_int = 20;
383+
pub const SO_SNDTIMEO: ::c_int = 21;
384+
pub const SOCK_STREAM: ::c_int = 1;
385+
pub const SOCK_DGRAM: ::c_int = 2;
386+
pub const SOL_SOCKET: ::c_int = 1;
387+
extern {
388+
pub fn bind(socket: ::c_int, address: *const ::sockaddr,
389+
address_len: ::socklen_t) -> ::c_int;
390+
pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t,
391+
flags: ::c_int, addr: *mut ::sockaddr,
392+
addrlen: *mut ::socklen_t) -> ::ssize_t;
393+
}
394+
395+
// sys/uio.h
396+
extern {
397+
pub fn readv(fd: ::c_int,
398+
iov: *const ::iovec,
399+
iovcnt: ::c_int) -> ::ssize_t;
400+
pub fn writev(fd: ::c_int,
401+
iov: *const ::iovec,
402+
iovcnt: ::c_int) -> ::ssize_t;
403+
}
404+
405+
// sys/wait.h
406+
pub const WNOHANG: ::c_int = 1;
407+
408+
// termios.h
168409
pub const NCCS: usize = 32;
169410

411+
// time.h
412+
pub const CLOCK_REALTIME: ::c_int = 1;
413+
pub const CLOCK_MONOTONIC: ::c_int = 4;
414+
extern {
415+
pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
416+
}
417+
418+
// unistd.h
419+
pub const SEEK_SET: ::c_int = 0;
420+
pub const SEEK_CUR: ::c_int = 1;
421+
pub const SEEK_END: ::c_int = 2;
422+
pub const STDIN_FILENO: ::c_int = 0;
423+
pub const STDOUT_FILENO: ::c_int = 1;
424+
pub const STDERR_FILENO: ::c_int = 2;
425+
426+
// wait.h
427+
pub fn WIFSTOPPED(status: ::c_int) -> bool {
428+
(status & 0xff) == 0x7f
429+
}
430+
431+
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
432+
(status >> 8) & 0xff
433+
}
434+
435+
pub fn WIFCONTINUED(status: ::c_int) -> bool {
436+
status == 0xffff
437+
}
438+
439+
pub fn WIFSIGNALED(status: ::c_int) -> bool {
440+
((status & 0x7f) + 1) as i8 >= 2
441+
}
442+
443+
pub fn WTERMSIG(status: ::c_int) -> ::c_int {
444+
status & 0x7f
445+
}
446+
447+
pub fn WIFEXITED(status: ::c_int) -> bool {
448+
(status & 0x7f) == 0
449+
}
450+
451+
pub fn WEXITSTATUS(status: ::c_int) -> ::c_int {
452+
(status >> 8) & 0xff
453+
}
454+
455+
pub fn WCOREDUMP(status: ::c_int) -> bool {
456+
(status & 0x80) != 0
457+
}
458+
170459
// intentionally not public, only used for fd_set
171460
cfg_if! {
172461
if #[cfg(target_pointer_width = "32")] {

0 commit comments

Comments
 (0)