Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
56b96a3b
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
56b96a3b
编写于
9月 26, 2013
作者:
K
Kevin Ballard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
path2: Implement stat support
上级
7fcdcaed
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
393 addition
and
0 deletion
+393
-0
src/libstd/path2/mod.rs
src/libstd/path2/mod.rs
+221
-0
src/libstd/path2/posix.rs
src/libstd/path2/posix.rs
+99
-0
src/libstd/path2/windows.rs
src/libstd/path2/windows.rs
+73
-0
未找到文件。
src/libstd/path2/mod.rs
浏览文件 @
56b96a3b
...
...
@@ -650,3 +650,224 @@ unsafe fn push_str_unchecked(&mut self, path: &str) {
fn
contains_nul
(
v
:
&
[
u8
])
->
bool
{
v
.iter
()
.any
(|
&
x
|
x
==
0
)
}
// FIXME (#9537): libc::stat should derive Default
#[cfg(target_os
=
"linux"
)]
#[cfg(target_os
=
"android"
)]
mod
stat
{
#[allow(missing_doc)]
;
#[cfg(target_arch
=
"x86"
)]
pub
mod
arch
{
use
libc
;
pub
fn
default_stat
()
->
libc
::
stat
{
libc
::
stat
{
st_dev
:
0
,
__
pad1
:
0
,
st_ino
:
0
,
st_mode
:
0
,
st_nlink
:
0
,
st_uid
:
0
,
st_gid
:
0
,
st_rdev
:
0
,
__
pad2
:
0
,
st_size
:
0
,
st_blksize
:
0
,
st_blocks
:
0
,
st_atime
:
0
,
st_atime_nsec
:
0
,
st_mtime
:
0
,
st_mtime_nsec
:
0
,
st_ctime
:
0
,
st_ctime_nsec
:
0
,
__u
nused4
:
0
,
__u
nused5
:
0
,
}
}
}
#[cfg(target_arch
=
"arm"
)]
pub
mod
arch
{
use
libc
;
pub
fn
default_stat
()
->
libc
::
stat
{
libc
::
stat
{
st_dev
:
0
,
__
pad0
:
[
0
,
..
4
],
__
st_ino
:
0
,
st_mode
:
0
,
st_nlink
:
0
,
st_uid
:
0
,
st_gid
:
0
,
st_rdev
:
0
,
__
pad3
:
[
0
,
..
4
],
st_size
:
0
,
st_blksize
:
0
,
st_blocks
:
0
,
st_atime
:
0
,
st_atime_nsec
:
0
,
st_mtime
:
0
,
st_mtime_nsec
:
0
,
st_ctime
:
0
,
st_ctime_nsec
:
0
,
st_ino
:
0
}
}
}
#[cfg(target_arch
=
"mips"
)]
pub
mod
arch
{
use
libc
;
pub
fn
default_stat
()
->
libc
::
stat
{
libc
::
stat
{
st_dev
:
0
,
st_pad1
:
[
0
,
..
3
],
st_ino
:
0
,
st_mode
:
0
,
st_nlink
:
0
,
st_uid
:
0
,
st_gid
:
0
,
st_rdev
:
0
,
st_pad2
:
[
0
,
..
2
],
st_size
:
0
,
st_pad3
:
0
,
st_atime
:
0
,
st_atime_nsec
:
0
,
st_mtime
:
0
,
st_mtime_nsec
:
0
,
st_ctime
:
0
,
st_ctime_nsec
:
0
,
st_blksize
:
0
,
st_blocks
:
0
,
st_pad5
:
[
0
,
..
14
],
}
}
}
#[cfg(target_arch
=
"x86_64"
)]
pub
mod
arch
{
use
libc
;
pub
fn
default_stat
()
->
libc
::
stat
{
libc
::
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_atime
:
0
,
st_atime_nsec
:
0
,
st_mtime
:
0
,
st_mtime_nsec
:
0
,
st_ctime
:
0
,
st_ctime_nsec
:
0
,
__u
nused
:
[
0
,
0
,
0
],
}
}
}
}
#[cfg(target_os
=
"freebsd"
)]
mod
stat
{
#[allow(missing_doc)]
;
#[cfg(target_arch
=
"x86_64"
)]
pub
mod
arch
{
use
libc
;
pub
fn
default_stat
()
->
libc
::
stat
{
libc
::
stat
{
st_dev
:
0
,
st_ino
:
0
,
st_mode
:
0
,
st_nlink
:
0
,
st_uid
:
0
,
st_gid
:
0
,
st_rdev
:
0
,
st_atime
:
0
,
st_atime_nsec
:
0
,
st_mtime
:
0
,
st_mtime_nsec
:
0
,
st_ctime
:
0
,
st_ctime_nsec
:
0
,
st_size
:
0
,
st_blocks
:
0
,
st_blksize
:
0
,
st_flags
:
0
,
st_gen
:
0
,
st_lspare
:
0
,
st_birthtime
:
0
,
st_birthtime_nsec
:
0
,
__u
nused
:
[
0
,
0
],
}
}
}
}
#[cfg(target_os
=
"macos"
)]
mod
stat
{
#[allow(missing_doc)]
;
pub
mod
arch
{
use
libc
;
pub
fn
default_stat
()
->
libc
::
stat
{
libc
::
stat
{
st_dev
:
0
,
st_mode
:
0
,
st_nlink
:
0
,
st_ino
:
0
,
st_uid
:
0
,
st_gid
:
0
,
st_rdev
:
0
,
st_atime
:
0
,
st_atime_nsec
:
0
,
st_mtime
:
0
,
st_mtime_nsec
:
0
,
st_ctime
:
0
,
st_ctime_nsec
:
0
,
st_birthtime
:
0
,
st_birthtime_nsec
:
0
,
st_size
:
0
,
st_blocks
:
0
,
st_blksize
:
0
,
st_flags
:
0
,
st_gen
:
0
,
st_lspare
:
0
,
st_qspare
:
[
0
,
0
],
}
}
}
}
#[cfg(target_os
=
"win32"
)]
mod
stat
{
#[allow(missing_doc)]
;
pub
mod
arch
{
use
libc
;
pub
fn
default_stat
()
->
libc
::
stat
{
libc
::
stat
{
st_dev
:
0
,
st_ino
:
0
,
st_mode
:
0
,
st_nlink
:
0
,
st_uid
:
0
,
st_gid
:
0
,
st_rdev
:
0
,
st_size
:
0
,
st_atime
:
0
,
st_mtime
:
0
,
st_ctime
:
0
,
}
}
}
}
src/libstd/path2/posix.rs
浏览文件 @
56b96a3b
...
...
@@ -26,6 +26,9 @@
use
vec
::{
Vector
,
VectorVector
};
use
super
::{
GenericPath
,
GenericPathUnsafe
};
#[cfg(not(target_os
=
"win32"
))]
use
libc
;
/// Iterator that yields successive components of a Path
pub
type
ComponentIter
<
'self
>
=
vec
::
SplitIterator
<
'self
,
u8
>
;
...
...
@@ -422,6 +425,102 @@ fn contains_nul(v: &[u8]) -> bool {
static
dot_static
:
&
'static
[
u8
]
=
&
'static
[
'.'
as
u8
];
static
dot_dot_static
:
&
'static
[
u8
]
=
&
'static
[
'.'
as
u8
,
'.'
as
u8
];
// Stat support
#[cfg(not(target_os
=
"win32"
))]
impl
Path
{
/// Calls stat() on the represented file and returns the resulting libc::stat
pub
fn
stat
(
&
self
)
->
Option
<
libc
::
stat
>
{
#[fixed_stack_segment]
;
#[inline(never)]
;
do
self
.with_c_str
|
buf
|
{
let
mut
st
=
super
::
stat
::
arch
::
default_stat
();
match
unsafe
{
libc
::
stat
(
buf
as
*
libc
::
c_char
,
&
mut
st
)
}
{
0
=>
Some
(
st
),
_
=>
None
}
}
}
/// Returns whether the represented file exists
pub
fn
exists
(
&
self
)
->
bool
{
match
self
.stat
()
{
None
=>
false
,
Some
(
_
)
=>
true
}
}
/// Returns the filesize of the represented file
pub
fn
get_size
(
&
self
)
->
Option
<
i64
>
{
match
self
.stat
()
{
None
=>
None
,
Some
(
st
)
=>
Some
(
st
.st_size
as
i64
)
}
}
/// Returns the mode of the represented file
pub
fn
get_mode
(
&
self
)
->
Option
<
uint
>
{
match
self
.stat
()
{
None
=>
None
,
Some
(
st
)
=>
Some
(
st
.st_mode
as
uint
)
}
}
}
#[cfg(target_os
=
"freebsd"
)]
#[cfg(target_os
=
"linux"
)]
#[cfg(target_os
=
"macos"
)]
impl
Path
{
/// Returns the atime of the represented file, as (secs, nsecs)
pub
fn
get_atime
(
&
self
)
->
Option
<
(
i64
,
int
)
>
{
match
self
.stat
()
{
None
=>
None
,
Some
(
st
)
=>
Some
((
st
.st_atime
as
i64
,
st
.st_atime_nsec
as
int
))
}
}
/// Returns the mtime of the represented file, as (secs, nsecs)
pub
fn
get_mtime
(
&
self
)
->
Option
<
(
i64
,
int
)
>
{
match
self
.stat
()
{
None
=>
None
,
Some
(
st
)
=>
Some
((
st
.st_mtime
as
i64
,
st
.st_mtime_nsec
as
int
))
}
}
/// Returns the ctime of the represented file, as (secs, nsecs)
pub
fn
get_ctime
(
&
self
)
->
Option
<
(
i64
,
int
)
>
{
match
self
.stat
()
{
None
=>
None
,
Some
(
st
)
=>
Some
((
st
.st_ctime
as
i64
,
st
.st_ctime_nsec
as
int
))
}
}
}
#[cfg(unix)]
impl
Path
{
/// Calls lstat() on the represented file and returns the resulting libc::stat
pub
fn
lstat
(
&
self
)
->
Option
<
libc
::
stat
>
{
#[fixed_stack_segment]
;
#[inline(never)]
;
do
self
.with_c_str
|
buf
|
{
let
mut
st
=
super
::
stat
::
arch
::
default_stat
();
match
unsafe
{
libc
::
lstat
(
buf
,
&
mut
st
)
}
{
0
=>
Some
(
st
),
_
=>
None
}
}
}
}
#[cfg(target_os
=
"freebsd"
)]
#[cfg(target_os
=
"macos"
)]
impl
Path
{
/// Returns the birthtime of the represented file
pub
fn
get_birthtime
(
&
self
)
->
Option
<
(
i64
,
int
)
>
{
match
self
.stat
()
{
None
=>
None
,
Some
(
st
)
=>
Some
((
st
.st_birthtime
as
i64
,
st
.st_birthtime_nsec
as
int
))
}
}
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
...
...
src/libstd/path2/windows.rs
浏览文件 @
56b96a3b
...
...
@@ -24,6 +24,9 @@
use
vec
::
Vector
;
use
super
::{
GenericPath
,
GenericPathUnsafe
};
#[cfg(target_os
=
"win32"
)]
use
libc
;
/// Iterator that yields successive components of a Path
pub
type
ComponentIter
<
'self
>
=
str
::
CharSplitIterator
<
'self
,
char
>
;
...
...
@@ -1060,6 +1063,76 @@ fn prefix_is_sep(p: Option<PathPrefix>, c: u8) -> bool {
else
{
is_sep
(
c
as
char
)
}
}
// Stat support
#[cfg(target_os
=
"win32"
)]
impl
Path
{
/// Calls stat() on the represented file and returns the resulting libc::stat
pub
fn
stat
(
&
self
)
->
Option
<
libc
::
stat
>
{
#[fixed_stack_segment]
;
#[inline(never)]
;
do
self
.with_c_str
|
buf
|
{
let
mut
st
=
super
::
stat
::
arch
::
default_stat
();
match
unsafe
{
libc
::
stat
(
buf
,
&
mut
st
)
}
{
0
=>
Some
(
st
),
_
=>
None
}
}
}
/// Returns whether the represented file exists
pub
fn
exists
(
&
self
)
->
bool
{
match
self
.stat
()
{
None
=>
None
,
Some
(
st
)
=>
Some
(
st
.st_size
as
i64
)
}
}
/// Returns the filesize of the represented file
pub
fn
get_size
(
&
self
)
->
Option
<
i64
>
{
match
self
.stat
()
{
None
=>
None
,
Some
(
st
)
=>
Some
(
st
.st_size
as
i64
)
}
}
/// Returns the mode of the represented file
pub
fn
get_mode
(
&
self
)
->
Option
<
uint
>
{
match
self
.stat
()
{
None
=>
None
,
Some
(
st
)
=>
Some
(
st
.st_mode
as
uint
)
}
}
/// Returns the atime of the represented file, as (secs, nsecs)
///
/// nsecs is always 0
pub
fn
get_atime
(
&
self
)
->
Option
<
(
i64
,
int
)
>
{
match
self
.stat
()
{
None
=>
None
,
Some
(
st
)
=>
Some
((
st
.st_atime
as
i64
,
0
))
}
}
/// Returns the mtime of the represented file, as (secs, nsecs)
///
/// nsecs is always 0
pub
fn
get_mtime
(
&
self
)
->
Option
<
(
i64
,
int
)
>
{
match
self
.stat
()
{
None
=>
None
,
Some
(
st
)
=>
Some
((
st
.st_mtime
as
i64
,
0
))
}
}
/// Returns the ctime of the represented file, as (secs, nsecs)
///
/// nsecs is always 0
pub
fn
get_ctime
(
&
self
)
->
Option
<
(
i64
,
int
)
>
{
match
self
.stat
()
{
None
=>
None
,
Some
(
st
)
=>
Some
((
st
.st_ctime
as
i64
,
0
))
}
}
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录