]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tools/nolibc: Add fseek() to stdio.h
authorDaniel Palmer <daniel@thingy.jp>
Mon, 5 Jan 2026 02:36:28 +0000 (11:36 +0900)
committerThomas Weißschuh <linux@weissschuh.net>
Sun, 11 Jan 2026 11:47:47 +0000 (12:47 +0100)
A very basic wrapper around lseek() that implements fseek().

Signed-off-by: Daniel Palmer <daniel@thingy.jp>
Link: https://patch.msgid.link/20260105023629.1502801-3-daniel@thingy.jp
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
tools/include/nolibc/stdio.h

index 6904252df97dff31f43c0a2f2e2014bacef89938..233318b0d0f016795117eb61f4300523bebb029d 100644 (file)
@@ -272,6 +272,25 @@ char *fgets(char *s, int size, FILE *stream)
 }
 
 
+/* fseek */
+static __attribute__((unused))
+int fseek(FILE *stream, long offset, int whence)
+{
+       int fd = fileno(stream);
+       off_t ret;
+
+       ret = lseek(fd, offset, whence);
+
+       /* lseek() and fseek() differ in that lseek returns the new
+        * position or -1, fseek() returns either 0 or -1.
+        */
+       if (ret >= 0)
+               return 0;
+
+       return -1;
+}
+
+
 /* minimal printf(). It supports the following formats:
  *  - %[l*]{d,u,c,x,p}
  *  - %s