From b5c3bc6a71339d39ab3e7080be5d19b7e9819564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Cholewa?= Date: Fri, 27 Dec 2019 22:50:14 +0100 Subject: [PATCH] LibC: implement fgetpos and fsetpos They're just "front ends" for ftell and fseek, but they do their job. Fixes #913 --- Libraries/LibC/stdio.cpp | 20 ++++++++++++++++++++ Libraries/LibC/stdio.h | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Libraries/LibC/stdio.cpp b/Libraries/LibC/stdio.cpp index 926ad4d1c1..5f93aba2bb 100644 --- a/Libraries/LibC/stdio.cpp +++ b/Libraries/LibC/stdio.cpp @@ -327,6 +327,26 @@ long ftell(FILE* stream) return lseek(stream->fd, 0, SEEK_CUR); } +int fgetpos(FILE* stream, fpos_t* pos) +{ + assert(stream); + assert(pos); + + long val = ftell(stream); + if (val == -1L) + return 1; + + *pos = val; + return 0; +} + +int fsetpos(FILE* stream, const fpos_t* pos) +{ + assert(stream); + assert(pos); + return fseek(stream, (long) *pos, SEEK_SET); +} + void rewind(FILE* stream) { ASSERT(stream); diff --git a/Libraries/LibC/stdio.h b/Libraries/LibC/stdio.h index 197056e783..85086d13d4 100644 --- a/Libraries/LibC/stdio.h +++ b/Libraries/LibC/stdio.h @@ -45,7 +45,7 @@ extern FILE* stdin; extern FILE* stdout; extern FILE* stderr; -typedef size_t fpos_t; +typedef long fpos_t; int fseek(FILE*, long offset, int whence); int fgetpos(FILE*, fpos_t*);