Compare commits

..

No commits in common. "25a47f0df3f5218d9677503463af3123e5acfbb6" and "45ffa1b79ca8c4776f74598c998f5a6492018417" have entirely different histories.

2 changed files with 11 additions and 36 deletions

View File

@ -217,23 +217,23 @@ namespace Kernel
{
TRY(validate_fd(fd));
off_t base_offset;
off_t new_offset = 0;
switch (whence)
{
case SEEK_SET:
base_offset = 0;
break;
case SEEK_CUR:
base_offset = m_open_files[fd]->offset;
new_offset = m_open_files[fd]->offset + offset;
break;
case SEEK_END:
base_offset = m_open_files[fd]->inode->size();
new_offset = m_open_files[fd]->inode->size() - offset;
break;
case SEEK_SET:
new_offset = offset;
break;
default:
return BAN::Error::from_errno(EINVAL);
}
const off_t new_offset = base_offset + offset;
if (new_offset < 0)
return BAN::Error::from_errno(EINVAL);

View File

@ -23,8 +23,6 @@ struct FILE
int pid { -1 };
int unget_char { EOF };
unsigned char inline_buffer_storage[BUFSIZ] {};
unsigned char* buffer = inline_buffer_storage;
uint32_t buffer_size = BUFSIZ;
@ -151,8 +149,6 @@ int fflush(FILE* file)
ScopeLock _(file);
file->unget_char = EOF;
if (file->buffer_index == 0)
return 0;
@ -286,16 +282,9 @@ size_t fread(void* buffer, size_t size, size_t nitems, FILE* file)
size_t target = size * nitems;
size_t nread = 0;
if (file->unget_char != EOF)
{
*static_cast<unsigned char*>(buffer) = file->unget_char;
file->unget_char = EOF;
nread++;
}
while (nread < target)
{
ssize_t ret = syscall(SYS_READ, file->fd, static_cast<unsigned char*>(buffer) + nread, target - nread);
ssize_t ret = syscall(SYS_READ, file->fd, (uint8_t*)buffer + nread, target - nread);
if (ret < 0)
file->error = true;
@ -361,7 +350,6 @@ int fseek(FILE* file, long offset, int whence)
int fseeko(FILE* file, off_t offset, int whence)
{
ScopeLock _(file);
file->unget_char = EOF;
long ret = syscall(SYS_SEEK, file->fd, offset, whence);
if (ret < 0)
return -1;
@ -385,7 +373,7 @@ off_t ftello(FILE* file)
long ret = syscall(SYS_TELL, file->fd);
if (ret < 0)
return -1;
return ret - (file->unget_char != EOF);
return ret;
}
int ftrylockfile(FILE*)
@ -425,13 +413,6 @@ int getc_unlocked(FILE* file)
if (file->eof)
return EOF;
if (file->unget_char != EOF)
{
int ch = file->unget_char;
file->unget_char = EOF;
return (unsigned char)ch;
}
unsigned char c;
long ret = syscall(SYS_READ, file->fd, &c, 1);
@ -768,14 +749,8 @@ char* tmpnam(char* storage)
int ungetc(int c, FILE* stream)
{
if (c == EOF)
return EOF;
ScopeLock _(stream);
if (stream->unget_char != EOF)
return EOF;
stream->unget_char = c;
stream->eof = false;
return (unsigned char)c;
dwarnln("FIXME: ungetc({}, {})", c, stream);
ASSERT_NOT_REACHED();
}
int vfprintf(FILE* file, const char* format, va_list arguments)