tools/toollib: remove from main Makefile.in
[AROS.git] / compiler / posixc / truncate.c
blobecbef140aa7feb99caf41def9994761efc059ce1
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 POSIX.1-2008 function truncate().
6 */
8 #include <unistd.h>
9 #include <errno.h>
10 #include <fcntl.h>
12 /*****************************************************************************
14 NAME */
15 #include <unistd.h>
17 int truncate (
19 /* SYNOPSIS */
20 const char *path,
21 off_t length)
23 /* FUNCTION
24 Truncate a file to a specified length
26 INPUTS
27 path - the path of the file being truncated
28 lenght - The file will have at most this size
30 RESULT
31 0 on success or -1 on errorr.
33 NOTES
34 If the file previously was larger than this size, the extra data
35 is lost. If the file previously was shorter, it is
36 unspecified whether the file is left unchanged or is
37 extended. In the latter case the extended part reads as
38 zero bytes.
41 EXAMPLE
43 BUGS
45 SEE ALSO
46 open()
48 INTERNALS
50 ******************************************************************************/
52 int fd, ret = -1;
54 if (!path) /* safety check */
56 errno = EFAULT;
57 return -1;
60 if ((fd = open(path, O_WRONLY)) != -1)
62 ret = ftruncate(fd, length);
63 close(fd);
66 return ret;