Skip to content

Documentation for Whence. #730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2017
Merged

Documentation for Whence. #730

merged 1 commit into from
Aug 15, 2017

Conversation

hilias
Copy link
Contributor

@hilias hilias commented Aug 10, 2017

No description provided.

@hilias hilias mentioned this pull request Aug 10, 2017
4 tasks
src/unistd.rs Outdated
pub enum Whence {
/// The file offset shall be set to offset bytes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Specify an offset relative to the start of the file"

src/unistd.rs Outdated
SeekSet,
/// The file offset shall be set to its current location plus offset.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Specify an offset relative to the current file location"

src/unistd.rs Outdated
SeekCur,
/// The file offset shall be set to the size of the file plus offset.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Specify an offset relative to the end of the file"

src/unistd.rs Outdated
SeekEnd,
/// Adjust the file offset to the next location in the file greater than
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Specify a file offset relative to the next location in the file greater than or equal to offset containing data. If offset points to data, then the file offset is set to offset."

That being said I really don't understand what "data" is in this context and how "offset" relates to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data is supposed to mean a part of the file that's been written to. Maybe it should be called 'some data'?

src/unistd.rs Outdated
SeekData,
/// Adjust the file offset to the next hole in the file greater than or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this only "specifies", it doesn't "adjust". The *seek() functions adjust, these constants are just specifying a position.

src/unistd.rs Outdated
@@ -737,11 +737,23 @@ pub fn write(fd: RawFd, buf: &[u8]) -> Result<usize> {
Errno::result(res).map(|r| r as usize)
}

/// Directive that tells lseek how to reposition the offset of the file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reference lseek and lseek64 and specify them as Markdown links to the documentation. See here for an example. You'll need to figure out the exact paths for lseek/lseek64, but the premise is the same.

src/unistd.rs Outdated
@@ -737,11 +737,25 @@ pub fn write(fd: RawFd, buf: &[u8]) -> Result<usize> {
Errno::result(res).map(|r| r as usize)
}

/// Directive that tells [`lseek`] and [`lseek64`] how to reposition the offset of the file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Directive for [lseek] and [lseek64] that specifies what the offset is relative to."

@Susurrus
Copy link
Contributor

If you're planning on tackling all of #676, we can keep that as part of this same PR as additional commits.

@Susurrus
Copy link
Contributor

Can you squash these commits all into one (lookup the git rebase command if you're unfamiliar with doing this)?

Otherwise are you planning on adding the other parts of #676 to this PR or we just going to merge the documentation part in this one?

@hilias
Copy link
Contributor Author

hilias commented Aug 11, 2017

I was thinking on tackling all of #676. I have a question with the conditional availabilty part, SEEK_DATA and SEEK_HOLE are defined on libc only on the linux module, so should I consider that the only platform where they are available?

@Susurrus
Copy link
Contributor

You'll want to check all applicable platforms. They should at least be added to DragonFlyBSD (declared here). FreeBSD also has them. It looks like it's not in uclibc or linux/musl. So I think those platforms are the only two missing it. I checked NetBSD, OpenBSD, and Mac and they don't have either of them, so that's fine.

@Susurrus
Copy link
Contributor

@ncaracci You'll need to add these constants to libc before this will work. You should file a PR against libc adding these constants here. Then your changes will work.

src/unistd.rs Outdated
@@ -751,8 +767,10 @@ impl Whence {
&Whence::SeekSet => libc::SEEK_SET,
&Whence::SeekCur => libc::SEEK_CUR,
&Whence::SeekEnd => libc::SEEK_END,
&Whence::SeekData => 3,
&Whence::SeekHole => 4
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this here, delete this whole impl and just assign values within the enum like SeekSet = libc::SEEK_SET,. You'll also want to say that it's a i32 datatype. Look at how it's implemented for Signal.

src/unistd.rs Outdated
/// Specify an offset relative to the next location in the file greater than or
/// equal to offset that contains some data. If offset points to
/// some data, then the file offset is set to offset.
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd"))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please alphabetize the OS names here and below.

@hilias
Copy link
Contributor Author

hilias commented Aug 14, 2017

Would adding not(target_env="musl", target_arch="mips") to the cfg fix the build errors?

@Susurrus
Copy link
Contributor

Use a whitelist for Linux instead: #[cfg(any(target_os = "dragonfly", target_os = "freebsd", all(target_os = "linux", not(any(target_env = "musl", target_arch = "mips"))))]

@Susurrus
Copy link
Contributor

You'll need to exclude arch mip64 as well.

Changed SeekData and SeekHole hardcoded values to libc ones and
added availability only to linux freebsd and dragonflybsd.

Removed impl Whence and assigned the libc values directly in the enum definition.
@asomers
Copy link
Member

asomers commented Aug 15, 2017

Thanks for the improvements, @ncaracci

bors r+

bors bot added a commit that referenced this pull request Aug 15, 2017
730: Documentation for Whence. r=asomers
@bors
Copy link
Contributor

bors bot commented Aug 15, 2017

Timed out

@asomers
Copy link
Member

asomers commented Aug 15, 2017

bors timed out because of a known bug in buildbot, triggered by the non-ascii character in the author's name. I'll manually merge it.

@asomers asomers merged commit fb329e8 into nix-rust:master Aug 15, 2017
@hilias hilias deleted the whence branch August 15, 2017 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants