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
40123541
Commit
40123541
authored
1 month ago
by
Jeremy Soller
Browse files
Options
Downloads
Plain Diff
Merge branch 'dirent-docs' into 'master'
Add docs for dirent.h See merge request
!606
parents
9c57e263
b4419162
No related branches found
No related tags found
1 merge request
!606
Add docs for dirent.h
Pipeline
#17670
passed
1 month ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/header/dirent/mod.rs
+53
-21
53 additions, 21 deletions
src/header/dirent/mod.rs
with
53 additions
and
21 deletions
src/header/dirent/mod.rs
+
53
−
21
View file @
40123541
//! dirent implementation following http://pubs.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html
//! `dirent.h` implementation.
//!
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/dirent.h.html>.
#![deny(unsafe_op_in_unsafe_fn)]
...
...
@@ -18,6 +20,7 @@ use super::errno::{EINVAL, EIO, ENOMEM};
const
INITIAL_BUFSIZE
:
usize
=
512
;
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/dirent.h.html>.
// No repr(C) needed, as this is a completely opaque struct. Being accessed as a pointer, in C it's
// just defined as `struct DIR`.
pub
struct
DIR
{
...
...
@@ -113,6 +116,7 @@ impl DIR {
}
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/dirent.h.html>.
#[repr(C)]
#[derive(Clone)]
pub
struct
dirent
{
...
...
@@ -145,28 +149,55 @@ const _: () = {
}
};
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/alphasort.html>.
#[no_mangle]
pub
unsafe
extern
"C"
fn
opendir
(
path
:
*
const
c_char
)
->
*
mut
DIR
{
let
path
=
unsafe
{
CStr
::
from_ptr
(
path
)
};
DIR
::
new
(
path
)
.or_errno_null_mut
()
pub
unsafe
extern
"C"
fn
alphasort
(
first
:
*
mut
*
const
dirent
,
second
:
*
mut
*
const
dirent
)
->
c_int
{
unsafe
{
string
::
strcoll
((
**
first
)
.d_name
.as_ptr
(),
(
**
second
)
.d_name
.as_ptr
())
}
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/closedir.html>.
#[no_mangle]
pub
extern
"C"
fn
closedir
(
dir
:
Box
<
DIR
>
)
->
c_int
{
dir
.close
()
.map
(|()|
0
)
.or_minus_one_errno
()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/dirfd.html>.
#[no_mangle]
pub
extern
"C"
fn
dirfd
(
dir
:
&
mut
DIR
)
->
c_int
{
*
dir
.file
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fdopendir.html>.
#[no_mangle]
pub
unsafe
extern
"C"
fn
opendir
(
path
:
*
const
c_char
)
->
*
mut
DIR
{
let
path
=
unsafe
{
CStr
::
from_ptr
(
path
)
};
DIR
::
new
(
path
)
.or_errno_null_mut
()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_getdents.html>.
// #[no_mangle]
pub
extern
"C"
fn
posix_getdents
(
fildes
:
c_int
,
buf
:
*
mut
c_void
,
nbyte
:
size_t
,
flags
:
c_int
,
)
->
ssize_t
{
unimplemented!
();
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/readdir.html>.
#[no_mangle]
pub
extern
"C"
fn
readdir
(
dir
:
&
mut
DIR
)
->
*
mut
dirent
{
dir
.next_dirent
()
.or_errno_null_mut
()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/readdir.html>.
///
/// # Deprecation
/// The `readdir_r()` function was marked obsolescent in the Open Group Base
/// Specifications Issue 8.
#[deprecated]
// #[no_mangle]
pub
extern
"C"
fn
readdir_r
(
_dir
:
*
mut
DIR
,
...
...
@@ -176,27 +207,13 @@ pub extern "C" fn readdir_r(
unimplemented!
();
// plus, deprecated
}
#[no_mangle]
pub
extern
"C"
fn
telldir
(
dir
:
&
mut
DIR
)
->
c_long
{
dir
.opaque_offset
as
c_long
}
#[no_mangle]
pub
extern
"C"
fn
seekdir
(
dir
:
&
mut
DIR
,
off
:
c_long
)
{
dir
.seek
(
off
.try_into
()
.expect
(
"off must come from telldir, thus never negative"
),
);
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/rewinddir.html>.
#[no_mangle]
pub
extern
"C"
fn
rewinddir
(
dir
:
&
mut
DIR
)
{
dir
.rewind
();
}
#[no_mangle]
pub
unsafe
extern
"C"
fn
alphasort
(
first
:
*
mut
*
const
dirent
,
second
:
*
mut
*
const
dirent
)
->
c_int
{
unsafe
{
string
::
strcoll
((
**
first
)
.d_name
.as_ptr
(),
(
**
second
)
.d_name
.as_ptr
())
}
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/alphasort.html>.
#[no_mangle]
pub
unsafe
extern
"C"
fn
scandir
(
dirp
:
*
const
c_char
,
...
...
@@ -269,3 +286,18 @@ pub unsafe extern "C" fn scandir(
len
as
c_int
}
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/seekdir.html>.
#[no_mangle]
pub
extern
"C"
fn
seekdir
(
dir
:
&
mut
DIR
,
off
:
c_long
)
{
dir
.seek
(
off
.try_into
()
.expect
(
"off must come from telldir, thus never negative"
),
);
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/telldir.html>.
#[no_mangle]
pub
extern
"C"
fn
telldir
(
dir
:
&
mut
DIR
)
->
c_long
{
dir
.opaque_offset
as
c_long
}
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