Skip to content
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

pcre2grep: workaround a common optimization in BSD fseek(stdin) #36

Merged
merged 1 commit into from
Nov 9, 2021

Conversation

carenas
Copy link
Contributor

@carenas carenas commented Nov 2, 2021

When BSD's fseek moves the position of a read stream within the
current buffer space, will avoid calling lseek for performance reasons, and therefore will
not update that position in the corresponding file handle, breaking the current implementation for -m (that supports stdin as a shared file)

There is ongoing discussion with NetBSD to change that, but the code has been around this way for decades and is likely to affect other UNIX (ex: AIX has been confirmed affected), so it is better to avoid that.

Fixes: #10

To allow pcre2grep to do an early exit in a resumable way, -m uses
fseek on stdin, which is sadly not supported in several platforms.

Most of the conflicting issues come from the fact that managing the
position while buffering is not trivial, and is therefore an optional
feature[1] of POSIX.1-2017

Workaround this by removing the buffer to stdin, if the -m option is
being used.  There is likely not a significant performance benefit
even for the platforms that support it, but it could be conditionally
added in that case, later.

Fixes: PCRE2Project#10

[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/fseek.html
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.

RunGrepTest issue on OpenBSD
2 participants