mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-03 17:58:49 +00:00
LibCore/Userland: Introduce a simple tail implementation
Also introduce more seek modes on CIODevice, and an out param to find the current position inside the file -- this means less syscalls (and less potential races) than requesting it through a separate pos() accessor or something.
This commit is contained in:
parent
805e87a21c
commit
c8fda23a03
Notes:
sideshowbarker
2024-07-19 14:05:01 +09:00
Author: https://github.com/rburchell
Commit: c8fda23a03
Pull-request: https://github.com/SerenityOS/serenity/pull/48
Reviewed-by: https://github.com/awesomekling
3 changed files with 143 additions and 4 deletions
|
@ -174,15 +174,31 @@ bool CIODevice::close()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CIODevice::seek(signed_qword offset)
|
||||
bool CIODevice::seek(signed_qword offset, SeekMode mode, off_t *pos)
|
||||
{
|
||||
int rc = lseek(m_fd, offset, SEEK_SET);
|
||||
int m = SEEK_SET;
|
||||
switch (mode) {
|
||||
case SeekMode::SetPosition:
|
||||
m = SEEK_SET;
|
||||
break;
|
||||
case SeekMode::FromCurrentPosition:
|
||||
m = SEEK_CUR;
|
||||
break;
|
||||
case SeekMode::FromEndPosition:
|
||||
m = SEEK_END;
|
||||
break;
|
||||
}
|
||||
off_t rc = lseek(m_fd, offset, m);
|
||||
if (rc < 0) {
|
||||
perror("CIODevice::seek: lseek");
|
||||
set_error(errno);
|
||||
if (pos)
|
||||
*pos = -1;
|
||||
return false;
|
||||
}
|
||||
m_buffered_data.clear();
|
||||
m_eof = false;
|
||||
if (pos)
|
||||
*pos = rc;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue