From 354c7f58737fb10dca1758dbf78e7766bdf8eb43 Mon Sep 17 00:00:00 2001 From: mengfansheng Date: Tue, 4 Jun 2024 09:54:04 +0800 Subject: [PATCH] add file_isdir --- utshell-0.5/r_general/src/lib.rs | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/utshell-0.5/r_general/src/lib.rs b/utshell-0.5/r_general/src/lib.rs index 5eef791d..f2591c8a 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 -- Gitee