]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
tools/nolibc: add ftruncate()
authorThomas Weißschuh <linux@weissschuh.net>
Thu, 21 May 2026 17:31:04 +0000 (19:31 +0200)
committerThomas Weißschuh <linux@weissschuh.net>
Sun, 24 May 2026 21:58:04 +0000 (23:58 +0200)
commit835fa43a4d36bd66ad0dd052f9fa15f7bd365fa8
tree3e0c781168f0d563a73487d5fa1206cbea11e5a2
parentacbbec15195b40adefd24993661c93022f6de2b7
tools/nolibc: add ftruncate()

On architectures with 32-bit longs, call the compat syscall
__NR_ftruncate64. As off_t is 64-bit it must be split into 2 registers.
Unlike llseek() which passes the high and low parts in explicitly named
arguments, the order here is endian independent.

Some architectures (arm, mips, ppc) require this pair of registers to
be aligned to an even register, so add custom _sys_ftruncate64()
wrappers for those.

A test case for ftruncate is added which validates negative length or
invalid fd return the appropriate error, and checks the length is
correct on success.

Co-developed-by: Jordan Richards <jordanrichards@google.com>
Signed-off-by: Jordan Richards <jordanrichards@google.com>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Willy Tarreau <w@1wt.eu>
Reviewed-by: Daniel Palmer <daniel@thingy.jp>
Link: https://patch.msgid.link/20260521-nolibc-ftruncate-v1-3-5384a83b2402@weissschuh.net
tools/include/nolibc/arch-arm.h
tools/include/nolibc/arch-mips.h
tools/include/nolibc/arch-powerpc.h
tools/include/nolibc/unistd.h
tools/testing/selftests/nolibc/nolibc-test.c