mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:47:34 +00:00
LibC: Add fseeko/ftello
This changes the signatures for FILE::seek and FILE::tell, to use `off_t` as they use lseek internally. `fpos_t` is also redefined to use `off_t`. Dr. POSIX says that fpos_t is: > A non-array type containing all information needed to specify uniquely > every position within a file. In practice, most *NIX typedef it to `off_t`, or a struct containing an `off_t` and some internal state.
This commit is contained in:
parent
bee1774b92
commit
1867c928a9
2 changed files with 21 additions and 7 deletions
|
@ -71,8 +71,8 @@ public:
|
||||||
bool gets(u8*, size_t);
|
bool gets(u8*, size_t);
|
||||||
bool ungetc(u8 byte) { return m_buffer.enqueue_front(byte); }
|
bool ungetc(u8 byte) { return m_buffer.enqueue_front(byte); }
|
||||||
|
|
||||||
int seek(long offset, int whence);
|
int seek(off_t offset, int whence);
|
||||||
long tell();
|
off_t tell();
|
||||||
|
|
||||||
pid_t popen_child() { return m_popen_child; }
|
pid_t popen_child() { return m_popen_child; }
|
||||||
void set_popen_child(pid_t child_pid) { m_popen_child = child_pid; }
|
void set_popen_child(pid_t child_pid) { m_popen_child = child_pid; }
|
||||||
|
@ -392,7 +392,7 @@ bool FILE::gets(u8* data, size_t size)
|
||||||
return total_read > 0;
|
return total_read > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FILE::seek(long offset, int whence)
|
int FILE::seek(off_t offset, int whence)
|
||||||
{
|
{
|
||||||
bool ok = flush();
|
bool ok = flush();
|
||||||
if (!ok)
|
if (!ok)
|
||||||
|
@ -408,7 +408,7 @@ int FILE::seek(long offset, int whence)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
long FILE::tell()
|
off_t FILE::tell()
|
||||||
{
|
{
|
||||||
bool ok = flush();
|
bool ok = flush();
|
||||||
if (!ok)
|
if (!ok)
|
||||||
|
@ -795,18 +795,30 @@ int fseek(FILE* stream, long offset, int whence)
|
||||||
return stream->seek(offset, whence);
|
return stream->seek(offset, whence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int fseeko(FILE* stream, off_t offset, int whence)
|
||||||
|
{
|
||||||
|
ASSERT(stream);
|
||||||
|
return stream->seek(offset, whence);
|
||||||
|
}
|
||||||
|
|
||||||
long ftell(FILE* stream)
|
long ftell(FILE* stream)
|
||||||
{
|
{
|
||||||
ASSERT(stream);
|
ASSERT(stream);
|
||||||
return stream->tell();
|
return stream->tell();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
off_t ftello(FILE* stream)
|
||||||
|
{
|
||||||
|
ASSERT(stream);
|
||||||
|
return stream->tell();
|
||||||
|
}
|
||||||
|
|
||||||
int fgetpos(FILE* stream, fpos_t* pos)
|
int fgetpos(FILE* stream, fpos_t* pos)
|
||||||
{
|
{
|
||||||
ASSERT(stream);
|
ASSERT(stream);
|
||||||
ASSERT(pos);
|
ASSERT(pos);
|
||||||
|
|
||||||
long val = stream->tell();
|
off_t val = stream->tell();
|
||||||
if (val == -1L)
|
if (val == -1L)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
@ -819,7 +831,7 @@ int fsetpos(FILE* stream, const fpos_t* pos)
|
||||||
ASSERT(stream);
|
ASSERT(stream);
|
||||||
ASSERT(pos);
|
ASSERT(pos);
|
||||||
|
|
||||||
return stream->seek((long)*pos, SEEK_SET);
|
return stream->seek(*pos, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rewind(FILE* stream)
|
void rewind(FILE* stream)
|
||||||
|
|
|
@ -55,12 +55,14 @@ extern FILE* stdin;
|
||||||
extern FILE* stdout;
|
extern FILE* stdout;
|
||||||
extern FILE* stderr;
|
extern FILE* stderr;
|
||||||
|
|
||||||
typedef long fpos_t;
|
typedef off_t fpos_t;
|
||||||
|
|
||||||
int fseek(FILE*, long offset, int whence);
|
int fseek(FILE*, long offset, int whence);
|
||||||
|
int fseeko(FILE*, off_t offset, int whence);
|
||||||
int fgetpos(FILE*, fpos_t*);
|
int fgetpos(FILE*, fpos_t*);
|
||||||
int fsetpos(FILE*, const fpos_t*);
|
int fsetpos(FILE*, const fpos_t*);
|
||||||
long ftell(FILE*);
|
long ftell(FILE*);
|
||||||
|
off_t ftello(FILE*);
|
||||||
char* fgets(char* buffer, int size, FILE*);
|
char* fgets(char* buffer, int size, FILE*);
|
||||||
int fputc(int ch, FILE*);
|
int fputc(int ch, FILE*);
|
||||||
int fileno(FILE*);
|
int fileno(FILE*);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue