/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include namespace Kernel { ErrorOr Process::sys$ftruncate(int fd, Userspace userspace_length) { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this) REQUIRE_PROMISE(stdio); off_t length; TRY(copy_from_user(&length, userspace_length)); if (length < 0) return EINVAL; auto description = TRY(fds().open_file_description(fd)); if (!description->is_writable()) return EBADF; TRY(description->truncate(static_cast(length))); return 0; } }