libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / system / libroot / posix / unistd / truncate.c
blobcd5dd152b063ba9d0e9f02e308e8f06ba6c105a5
1 /*
2 * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <fs_interface.h>
8 #include <NodeMonitor.h>
10 #include <unistd.h>
11 #include <syscalls.h>
12 #include <errno.h>
14 #include <errno_private.h>
17 #define RETURN_AND_SET_ERRNO(err) \
18 if (err < 0) { \
19 __set_errno(err); \
20 return -1; \
21 } \
22 return err;
25 int
26 truncate(const char *path, off_t newSize)
28 struct stat stat;
29 status_t status;
31 stat.st_size = newSize;
32 status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat),
33 B_STAT_SIZE);
35 RETURN_AND_SET_ERRNO(status);
39 int
40 ftruncate(int fd, off_t newSize)
42 struct stat stat;
43 status_t status;
45 stat.st_size = newSize;
46 status = _kern_write_stat(fd, NULL, false, &stat, sizeof(struct stat),
47 B_STAT_SIZE);
49 RETURN_AND_SET_ERRNO(status);