mirror of
https://github.com/touchHLE/touchHLE.git
synced 2026-01-31 01:25:24 +01:00
Constant pointers to stdin, stdout, and stderr file descriptors
Change-Id: I2f8841c2953d7d67d3439eff84f56b71c30e79c0 Co-authored-by: alborrajo <alvarolopezborr@gmail.com>
This commit is contained in:
@@ -12,6 +12,7 @@ use crate::libc;
|
||||
/// All the lists of constants that the linker should search through.
|
||||
pub const CONSTANT_LISTS: &[super::ConstantExports] = &[
|
||||
libc::ctype::CONSTANTS,
|
||||
libc::stdio::CONSTANTS,
|
||||
core_foundation::cf_allocator::CONSTANTS,
|
||||
core_foundation::cf_run_loop::CONSTANTS,
|
||||
core_graphics::cg_affine_transform::CONSTANTS,
|
||||
|
||||
@@ -45,11 +45,9 @@ fn fd_to_file_idx(fd: FileDescriptor) -> usize {
|
||||
|
||||
/// File descriptor type. This alias is for readability, POSIX just uses `int`.
|
||||
pub type FileDescriptor = i32;
|
||||
#[allow(dead_code)]
|
||||
const STDIN_FILENO: FileDescriptor = 0;
|
||||
#[allow(dead_code)]
|
||||
const STDOUT_FILENO: FileDescriptor = 1;
|
||||
const STDERR_FILENO: FileDescriptor = 2;
|
||||
pub const STDIN_FILENO: FileDescriptor = 0;
|
||||
pub const STDOUT_FILENO: FileDescriptor = 1;
|
||||
pub const STDERR_FILENO: FileDescriptor = 2;
|
||||
const NORMAL_FILENO_BASE: FileDescriptor = STDERR_FILENO + 1;
|
||||
|
||||
/// Flags bitfield for `open`. This alias is for readability, POSIX just uses
|
||||
|
||||
@@ -5,11 +5,14 @@
|
||||
*/
|
||||
//! `stdio.h`
|
||||
|
||||
use super::posix_io::{self, off_t, O_APPEND, O_CREAT, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY};
|
||||
use crate::dyld::{export_c_func, FunctionExports};
|
||||
use super::posix_io::{
|
||||
self, off_t, O_APPEND, O_CREAT, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY, STDERR_FILENO,
|
||||
STDIN_FILENO, STDOUT_FILENO,
|
||||
};
|
||||
use crate::dyld::{export_c_func, ConstantExports, FunctionExports, HostConstant};
|
||||
use crate::fs::GuestPath;
|
||||
use crate::libc::string::strlen;
|
||||
use crate::mem::{ConstPtr, ConstVoidPtr, GuestUSize, MutPtr, MutVoidPtr, Ptr, SafeRead};
|
||||
use crate::mem::{ConstPtr, ConstVoidPtr, GuestUSize, Mem, MutPtr, MutVoidPtr, Ptr, SafeRead};
|
||||
use crate::Environment;
|
||||
use std::io::Write;
|
||||
|
||||
@@ -219,6 +222,30 @@ fn fileno(env: &mut Environment, file_ptr: MutPtr<FILE>) -> posix_io::FileDescri
|
||||
fd
|
||||
}
|
||||
|
||||
pub const CONSTANTS: ConstantExports = &[
|
||||
(
|
||||
"___stdinp",
|
||||
HostConstant::Custom(|mem: &mut Mem| -> ConstVoidPtr {
|
||||
let ptr = mem.alloc_and_write(FILE { fd: STDIN_FILENO });
|
||||
mem.alloc_and_write(ptr).cast().cast_const()
|
||||
}),
|
||||
),
|
||||
(
|
||||
"___stdoutp",
|
||||
HostConstant::Custom(|mem: &mut Mem| -> ConstVoidPtr {
|
||||
let ptr = mem.alloc_and_write(FILE { fd: STDOUT_FILENO });
|
||||
mem.alloc_and_write(ptr).cast().cast_const()
|
||||
}),
|
||||
),
|
||||
(
|
||||
"___stderrp",
|
||||
HostConstant::Custom(|mem: &mut Mem| -> ConstVoidPtr {
|
||||
let ptr = mem.alloc_and_write(FILE { fd: STDERR_FILENO });
|
||||
mem.alloc_and_write(ptr).cast().cast_const()
|
||||
}),
|
||||
),
|
||||
];
|
||||
|
||||
pub const FUNCTIONS: FunctionExports = &[
|
||||
// Standard C functions
|
||||
export_c_func!(fopen(_, _)),
|
||||
|
||||
Reference in New Issue
Block a user