diff --git a/utshell-0.5/r_general/src/lib.rs b/utshell-0.5/r_general/src/lib.rs index 5eef791d4003cd3f0d38964cfe9531460f6ff4aa..f2591c8ad12113bab1ae2535c67ca9c6e8f6f1f8 100644 --- a/utshell-0.5/r_general/src/lib.rs +++ b/utshell-0.5/r_general/src/lib.rs @@ -1227,3 +1227,72 @@ pub unsafe extern "C" fn sh_closepipe(mut pv: *mut libc::c_int) -> libc::c_int { *pv.offset(0 as isize) = *fresh1; return 0; } + +/* **************************************************************** */ +/* */ +/* Functions to inspect pathnames */ +/* */ +/* **************************************************************** */ +#[no_mangle] +pub unsafe extern "C" fn file_exists(mut fn_0: *const libc::c_char) -> libc::c_int { + let mut sb: stat = stat { + st_dev: 0, + st_ino: 0, + st_nlink: 0, + st_mode: 0, + st_uid: 0, + st_gid: 0, + __pad0: 0, + st_rdev: 0, + st_size: 0, + st_blksize: 0, + st_blocks: 0, + st_atim: timespec { + tv_sec: 0, + tv_nsec: 0, + }, + st_mtim: timespec { + tv_sec: 0, + tv_nsec: 0, + }, + st_ctim: timespec { + tv_sec: 0, + tv_nsec: 0, + }, + __glibc_reserved: [0; 3], + }; + + return (stat(fn_0, &mut sb) == 0 as libc::c_int) as libc::c_int; +} + +#[no_mangle] +pub unsafe extern "C" fn file_isdir(mut fn_0: *const libc::c_char) -> libc::c_int { + let mut sb: stat = stat { + st_dev: 0, + st_ino: 0, + st_nlink: 0, + st_mode: 0, + st_uid: 0, + st_gid: 0, + __pad0: 0, + st_rdev: 0, + st_size: 0, + st_blksize: 0, + st_blocks: 0, + st_atim: timespec { + tv_sec: 0, + tv_nsec: 0, + }, + st_mtim: timespec { + tv_sec: 0, + tv_nsec: 0, + }, + st_ctim: timespec { + tv_sec: 0, + tv_nsec: 0, + }, + __glibc_reserved: [0; 3], + }; + + return (stat(fn_0, &mut sb) == 0 && S_ISDIR!(sb.st_mode)) as libc::c_int; +} \ No newline at end of file