1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Added fseeko(3) and ftello(3).

This commit is contained in:
Jonas 'Sortie' Termansen 2011-12-30 00:36:39 +01:00
parent 912b2f78f0
commit 064b69d2b6
3 changed files with 16 additions and 6 deletions

View file

@ -15,7 +15,7 @@ typedef struct _FILE
void* user;
size_t (*read_func)(void* ptr, size_t size, size_t nmemb, void* user);
size_t (*write_func)(const void* ptr, size_t size, size_t nmemb, void* user);
int (*seek_func)(void* user, long offset, int whence);
int (*seek_func)(void* user, off_t offset, int whence);
long (*tell_func)(void* user);
void (*clearerr_func)(void* user);
int (*eof_func)(void* user);

View file

@ -74,16 +74,16 @@ static size_t fdio_write(const void* ptr, size_t size, size_t nmemb, void* user)
return sofar;
}
static int fdio_seek(void* user, long offset, int whence)
static int fdio_seek(void* user, off_t offset, int whence)
{
fdio_t* fdio = (fdio_t*) user;
return (int) lseek(fdio->fd, offset, whence);
}
static long fdio_tell(void* user)
static off_t fdio_tell(void* user)
{
fdio_t* fdio = (fdio_t*) user;
return (int) lseek(fdio->fd, 0, SEEK_CUR);
return lseek(fdio->fd, 0, SEEK_CUR);
}
static void fdio_clearerr(void* user)

View file

@ -91,11 +91,16 @@ size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE* fp)
return sofar;
}
int fseek(FILE* fp, long offset, int whence)
int fseeko(FILE* fp, off_t offset, int whence)
{
return (fp->seek_func) ? fp->seek_func(fp->user, offset, whence) : 0;
}
int fseek(FILE* fp, long offset, int whence)
{
return fseeko(fp, offset, whence);
}
void clearerr(FILE* fp)
{
if ( fp->clearerr_func ) { fp->clearerr_func(fp->user); }
@ -119,12 +124,17 @@ void rewind(FILE* fp)
clearerr(fp);
}
long ftell(FILE* fp)
off_t ftello(FILE* fp)
{
if ( !fp->tell_func ) { errno = EBADF; return -1; }
return fp->tell_func(fp->user);
}
long ftell(FILE* fp)
{
return (long) ftello(fp);
}
int fflush(FILE* fp)
{
if ( !fp )