add a missing section header table index conversion
[tangerine.git] / compiler / clib / truncate.c
blob7163da3cce31793b49a017dcb32eee05d744722a
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C function truncate().
6 */
8 #include <unistd.h>
9 #include <errno.h>
10 #include <fcntl.h>
11 #include "__errno.h"
13 /*****************************************************************************
15 NAME */
16 #include <unistd.h>
18 int truncate (
20 /* SYNOPSIS */
21 const char *path,
22 off_t length)
24 /* FUNCTION
25 Truncate a file to a specified length
27 INPUTS
28 path - the path of the file being truncated
29 lenght - The file will have at most this size
31 RESULT
32 0 on success or -1 on errorr.
34 NOTES
35 If the file previously was larger than this size, the extra data
36 is lost. If the file previously was shorter, it is
37 unspecified whether the file is left unchanged or is
38 extended. In the latter case the extended part reads as
39 zero bytes.
42 EXAMPLE
44 BUGS
46 SEE ALSO
47 open()
49 INTERNALS
51 ******************************************************************************/
53 int fd, ret = -1;
55 if (!path) /* safety check */
57 errno = EFAULT;
58 return -1;
61 if ((fd = open(path, O_WRONLY)) != -1)
63 ret = ftruncate(fd, length);
64 close(fd);
67 return ret;