Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relibc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
redox-os
relibc
Commits
330b50d7
Commit
330b50d7
authored
1 year ago
by
Henri Hannetel
Committed by
Jeremy Soller
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add UTIME_OMIT and UTIME_NOW
parent
2c7ec0dc
No related branches found
No related tags found
1 merge request
!427
Add UTIME_OMIT and UTIME_NOW
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/header/sys_stat/mod.rs
+3
-0
3 additions, 0 deletions
src/header/sys_stat/mod.rs
tests/futimens.c
+42
-12
42 additions, 12 deletions
tests/futimens.c
with
45 additions
and
12 deletions
src/header/sys_stat/mod.rs
+
3
−
0
View file @
330b50d7
...
...
@@ -37,6 +37,9 @@ pub const S_ISUID: c_int = 0o4_000;
pub
const
S_ISGID
:
c_int
=
0o2_000
;
pub
const
S_ISVTX
:
c_int
=
0o1_000
;
pub
const
UTIME_NOW
:
useconds_t
=
(
1
<<
30
)
-
1
;
pub
const
UTIME_OMIT
:
useconds_t
=
(
1
<<
30
)
-
2
;
#[repr(C)]
#[derive(Default)]
pub
struct
stat
{
...
...
This diff is collapsed.
Click to expand it.
tests/futimens.c
+
42
−
12
View file @
330b50d7
...
...
@@ -6,8 +6,31 @@
#include
<string.h>
#include
<errno.h>
#include
<stdio.h>
#include
<time.h>
#include
<unistd.h>
int
check_mtime
(
char
*
path
,
int
expected_sec
,
int
expected_nsec
,
int
err_gap
)
{
// Checks whether the moditication time of the file located at *path* match the provided times.
// When err_gap is set, only checks for a match on sec with a margin of error of +/- err_gap.
struct
stat
sb
;
if
(
stat
(
path
,
&
sb
)
!=
0
)
{
fprintf
(
stderr
,
"stat: %s
\n
"
,
strerror
(
errno
));
return
-
1
;
}
if
(
err_gap
>
0
)
{
if
(
sb
.
st_mtim
.
tv_sec
<
expected_sec
+
err_gap
&&
sb
.
st_mtim
.
tv_sec
>
expected_sec
-
err_gap
)
{
return
0
;
}
}
else
{
if
(
sb
.
st_mtim
.
tv_sec
==
expected_sec
&&
sb
.
st_mtim
.
tv_nsec
==
expected_nsec
)
{
return
0
;
}
}
fprintf
(
stderr
,
"Wrong modified time: %d.%d
\n
"
,
sb
.
st_mtim
.
tv_sec
,
sb
.
st_mtim
.
tv_nsec
);
return
-
1
;
}
int
main
(
int
argc
,
char
**
argv
)
{
char
temp
[]
=
"/tmp/stattest-XXXXXX"
;
const
char
file
[]
=
"/mkfifo_fifo"
;
...
...
@@ -47,21 +70,28 @@ int main(int argc, char** argv) {
fprintf
(
stderr
,
"futimens: %s
\n
"
,
strerror
(
errno
));
exit
(
1
);
}
if
(
check_mtime
(
path
,
20
,
0
,
0
)
!=
0
)
{
exit
(
1
);
}
// Access times are not flushed to disk, so atime checks can't be (currently) performed
struct
stat
sb
;
if
(
stat
(
path
,
&
sb
)
!=
0
)
{
fprintf
(
stderr
,
"stat: %s
\n
"
,
strerror
(
errno
));
const
struct
timespec
omit_times
[]
=
{
{
25
,
UTIME_OMIT
},
{
12
,
UTIME_OMIT
}
};
if
(
futimens
(
fd
,
omit_times
)
==
-
1
)
{
fprintf
(
stderr
,
"futimens: %s
\n
"
,
strerror
(
errno
));
exit
(
1
);
}
if
(
check_mtime
(
path
,
20
,
0
,
0
)
!=
0
)
{
exit
(
1
);
}
if
(
sb
.
st_mtim
.
tv_sec
!=
20
||
sb
.
st_mtim
.
tv_nsec
!=
0
)
{
fprintf
(
stderr
,
"Wrong modified time: %d.%d
\n
"
,
sb
.
st_mtim
.
tv_sec
,
sb
.
st_mtim
.
tv_nsec
);
const
struct
timespec
now_times
[]
=
{
{
25
,
UTIME_NOW
},
{
12
,
UTIME_NOW
}
};
if
(
futimens
(
fd
,
now_times
)
==
-
1
)
{
fprintf
(
stderr
,
"futimens: %s
\n
"
,
strerror
(
errno
));
exit
(
1
);
}
int
now_ts
=
time
(
NULL
);
if
(
check_mtime
(
path
,
now_ts
,
0
,
1
)
!=
0
)
{
exit
(
1
);
}
// Access times are not flushed to disk, so this check can't be (currently) performed
/*
* if (sb.st_atim.tv_sec != 10 || sb.st_atim.tv_nsec != 0) {
* fprintf(stderr, "Wrong accessed time: %d.%d\n", sb.st_atim.tv_sec, sb.st_atim.tv_nsec);
* exit(1);
* }
*/
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment