truncate(2) System Calls Manual truncate(2) truncate, ftruncate - LIBRARY Standard C library (libc, -lc) #include int truncate(const char *path, off_t length); int ftruncate(int fd, off_t length); glibc (. feature_test_macros(7)): truncate(): _XOPEN_SOURCE >= 500 || /* glibc 2.12: */ _POSIX_C_SOURCE >= 200809L || /* glibc <= 2.19: */ _BSD_SOURCE ftruncate(): _XOPEN_SOURCE >= 500 || /* Since glibc 2.3.5: */ _POSIX_C_SOURCE >= 200112L || /* glibc <= 2.19: */ _BSD_SOURCE truncate() ftruncate() , path fd, , length ( ). If the file previously was larger than this size, the extra data is lost. If the file previously was shorter, it is extended, and the extended part reads as null bytes ('\0'). . , st_ctime st_mtime ( , ; inode(7)) , set-user-ID set-group-ID . ftruncate() ; truncate() . On success, zero is returned. On error, -1 is returned, and errno is set to indicate the error. truncate(): EACCES , ( path_resolution(7)). EFAULT path , . EFBIG length (XSI). EINTR ; fcntl(2) signal(7). EINVAL length . EIO (inode) /. EISDIR . ELOOP pathname . ENAMETOOLONG 255 , 1023 . ENOENT . ENOTDIR . EPERM . EPERM (file seal); fcntl(2). EROFS , . ETXTBSY , . ftruncate() , , , path, , fd: EBADF fd . EBADF EINVAL fd . EINVAL fd POSIX. EINVAL EBADF fd . POSIX (Linux EINVAL). XSI- . XSI- POSIX ftruncate(), length (, truncate() ): , . UNIX, Linux XSI, . , truncate() ftruncate() : , Linux VFAT. 32- , syscall(2). POSIX.1-2008. POSIX.1-2001, 4.4BSD, SVr4 (first appeared in 4.2BSD). truncate() ftruncate() Linux . , Linux 2.4 truncate64() ftruncate64() . , glibc, , . ftruncate() POSIX; shm_open(3). - glibc 2.12 _POSIX_C_SOURCE, ftruncate(), 200809L 200112L. glibc . . truncate(1), open(2), stat(2), path_resolution(7) Azamat Hackimov , Dmitry Bolkhovskikh , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . truncate(2)