Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
P
pager-rs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
6
Issues
6
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Cyril Plisko
pager-rs
Commits
3b848699
Commit
3b848699
authored
Nov 08, 2020
by
Cyril Plisko
🤔
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rust 2018
parent
c5405433
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
25 deletions
+25
-25
Cargo.toml
Cargo.toml
+1
-0
src/lib.rs
src/lib.rs
+16
-13
src/utils.rs
src/utils.rs
+8
-12
No files found.
Cargo.toml
View file @
3b848699
...
...
@@ -8,6 +8,7 @@ name = "pager"
readme
=
"README.md"
repository
=
"https://gitlab.com/imp/pager-rs.git"
version
=
"0.15.0"
# remember to update html_root_url
edition
=
"2018"
categories
=
[
"command-line-interface"
,
"text-processing"
]
[badges]
...
...
src/lib.rs
View file @
3b848699
...
...
@@ -77,13 +77,16 @@
//! reflect the fact that no Pager is active.
#![doc(html_root_url
=
"https://docs.rs/pager/0.15.0"
)]
#![cfg_attr(
all(feature
=
"cargo-clippy"
,
feature
=
"pedantic"
),
warn(clippy_pedantic)
)]
extern
crate
errno
;
extern
crate
libc
;
#![cfg_attr(feature
=
"pedantic"
,
warn(clippy::pedantic))]
#![warn(clippy::use_self)]
#![warn(deprecated_in_future)]
#![warn(future_incompatible)]
#![warn(unreachable_pub)]
#![warn(missing_debug_implementations)]
#![warn(rust_2018_compatibility)]
#![warn(rust_2018_idioms)]
#![warn(unused)]
#![deny(warnings)]
mod
utils
;
...
...
@@ -248,21 +251,21 @@ mod tests {
fn
new
<
S
:
AsRef
<
OsStr
>>
(
env
:
S
)
->
Self
{
let
env
=
env
.as_ref
()
.into
();
if
let
Some
(
value
)
=
env
::
var_os
(
&
env
)
{
PagerEnv
::
Reinstate
(
env
,
value
)
Self
::
Reinstate
(
env
,
value
)
}
else
{
PagerEnv
::
Remove
(
env
)
Self
::
Remove
(
env
)
}
}
fn
set
<
S
:
AsRef
<
OsStr
>>
(
&
self
,
value
:
S
)
{
match
self
{
PagerEnv
::
Reinstate
(
env
,
_
)
|
PagerEnv
::
Remove
(
env
)
=>
env
::
set_var
(
env
,
value
),
Self
::
Reinstate
(
env
,
_
)
|
Self
::
Remove
(
env
)
=>
env
::
set_var
(
env
,
value
),
}
}
fn
remove
(
&
self
)
{
match
self
{
PagerEnv
::
Reinstate
(
env
,
_
)
|
PagerEnv
::
Remove
(
env
)
=>
env
::
remove_var
(
env
),
Self
::
Reinstate
(
env
,
_
)
|
Self
::
Remove
(
env
)
=>
env
::
remove_var
(
env
),
}
}
}
...
...
@@ -270,8 +273,8 @@ mod tests {
impl
Drop
for
PagerEnv
{
fn
drop
(
&
mut
self
)
{
match
self
{
PagerEnv
::
Reinstate
(
env
,
value
)
=>
env
::
set_var
(
env
,
value
),
PagerEnv
::
Remove
(
env
)
=>
env
::
remove_var
(
env
),
Self
::
Reinstate
(
env
,
value
)
=>
env
::
set_var
(
env
,
value
),
Self
::
Remove
(
env
)
=>
env
::
remove_var
(
env
),
}
}
}
...
...
src/utils.rs
View file @
3b848699
...
...
@@ -2,9 +2,6 @@ use std::ffi::{CString, OsString};
use
std
::
os
::
unix
::
ffi
::
OsStringExt
;
use
std
::
ptr
;
use
errno
;
use
libc
;
fn
osstring2cstring
(
s
:
OsString
)
->
CString
{
unsafe
{
CString
::
from_vec_unchecked
(
s
.into_vec
())
}
}
...
...
@@ -17,11 +14,11 @@ fn split_string(s: &OsString) -> Vec<OsString> {
}
// Helper wrappers around libc::* API
pub
fn
fork
()
->
libc
::
pid_t
{
pub
(
crate
)
fn
fork
()
->
libc
::
pid_t
{
unsafe
{
libc
::
fork
()
}
}
pub
fn
execvp
(
cmd
:
&
OsString
)
{
pub
(
crate
)
fn
execvp
(
cmd
:
&
OsString
)
{
let
cstrings
=
split_string
(
cmd
)
.into_iter
()
.map
(
osstring2cstring
)
...
...
@@ -32,7 +29,7 @@ pub fn execvp(cmd: &OsString) {
unsafe
{
libc
::
execvp
(
args
[
0
],
args
.as_ptr
())
};
}
pub
fn
execvpe
(
cmd
:
&
OsString
,
envs
:
&
[
OsString
])
{
pub
(
crate
)
fn
execvpe
(
cmd
:
&
OsString
,
envs
:
&
[
OsString
])
{
let
cstrings
=
split_string
(
cmd
)
.into_iter
()
.map
(
osstring2cstring
)
...
...
@@ -56,21 +53,20 @@ pub fn execvpe(cmd: &OsString, envs: &[OsString]) {
unsafe
{
libc
::
execvpe
(
args
[
0
],
args
.as_ptr
(),
envs
.as_ptr
())
};
}
pub
fn
dup2
(
fd1
:
i32
,
fd2
:
i32
)
{
pub
(
crate
)
fn
dup2
(
fd1
:
i32
,
fd2
:
i32
)
{
assert
!
(
unsafe
{
libc
::
dup2
(
fd1
,
fd2
)
}
>
-
1
);
}
pub
fn
close
(
fd
:
i32
)
{
pub
(
crate
)
fn
close
(
fd
:
i32
)
{
assert_eq!
(
unsafe
{
libc
::
close
(
fd
)
},
0
);
}
pub
fn
pipe
()
->
(
i32
,
i32
)
{
pub
(
crate
)
fn
pipe
()
->
(
i32
,
i32
)
{
let
mut
fds
=
[
0
;
2
];
assert_eq!
(
unsafe
{
libc
::
pipe
(
fds
.as_mut_ptr
())
},
0
);
(
fds
[
0
],
fds
[
1
])
}
pub
fn
isatty
(
fd
:
i32
)
->
bool
{
let
isatty
=
unsafe
{
libc
::
isatty
(
fd
)
};
isatty
!=
0
pub
(
crate
)
fn
isatty
(
fd
:
i32
)
->
bool
{
unsafe
{
libc
::
isatty
(
fd
)
!=
0
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment