boot loader: Add pwrite(), lseek(), ftruncate()
ftruncate() is just a stub (needed for BFdIO).
This commit is contained in:
parent
c55a06055f
commit
01e6d687c0
|
@ -57,6 +57,7 @@ class Descriptor {
|
|||
ssize_t Write(const void *buffer, size_t bufferSize);
|
||||
|
||||
void Stat(struct stat &stat);
|
||||
status_t Seek(off_t position, int mode);
|
||||
|
||||
off_t Offset() const { return fOffset; }
|
||||
int32 RefCount() const { return fRefCount; }
|
||||
|
@ -391,6 +392,37 @@ Descriptor::Stat(struct stat &stat)
|
|||
}
|
||||
|
||||
|
||||
status_t
|
||||
Descriptor::Seek(off_t position, int mode)
|
||||
{
|
||||
off_t newPosition;
|
||||
switch (mode)
|
||||
{
|
||||
case SEEK_SET:
|
||||
newPosition = position;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
newPosition = fOffset + position;
|
||||
break;
|
||||
case SEEK_END:
|
||||
{
|
||||
struct stat st;
|
||||
Stat(st);
|
||||
newPosition = st.st_size + position;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
if (newPosition < 0)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
fOffset = newPosition;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
Descriptor::Acquire()
|
||||
{
|
||||
|
@ -866,6 +898,29 @@ dup(int fd)
|
|||
}
|
||||
|
||||
|
||||
off_t
|
||||
lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
Descriptor* descriptor = get_descriptor(fd);
|
||||
if (descriptor == NULL)
|
||||
RETURN_AND_SET_ERRNO(B_FILE_ERROR);
|
||||
|
||||
status_t error = descriptor->Seek(offset, whence);
|
||||
if (error != B_OK)
|
||||
RETURN_AND_SET_ERRNO(B_FILE_ERROR);
|
||||
|
||||
return descriptor->Offset();
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ftruncate(int fd, off_t newSize)
|
||||
{
|
||||
dprintf("ftruncate() not implemented!\n");
|
||||
RETURN_AND_SET_ERRNO(B_FILE_ERROR);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
read_pos(int fd, off_t offset, void *buffer, size_t bufferSize)
|
||||
{
|
||||
|
@ -906,6 +961,13 @@ write_pos(int fd, off_t offset, const void *buffer, size_t bufferSize)
|
|||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
pwrite(int fd, const void* buffer, size_t bufferSize, off_t offset)
|
||||
{
|
||||
return write_pos(fd, offset, buffer, bufferSize);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
write(int fd, const void *buffer, size_t bufferSize)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue