2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
5 POSIX function ftruncate().
15 /*****************************************************************************
27 Truncate a file to a specified length
30 fd - the descriptor of the file being truncated.
31 The file must be open for writing
32 lenght - The file will have at most this size
35 0 on success or -1 on errorr.
38 If the file previously was larger than this size, the extra data
39 is lost. If the file previously was shorter, it is
40 unspecified whether the file is left unchanged or is
41 extended. In the latter case the extended part reads as
54 ******************************************************************************/
59 fdesc
*fdesc
= __getfdesc(fd
);
67 if (!(fdesc
->flags
& (O_WRONLY
|O_RDWR
)))
73 oldpos
= Seek(fdesc
->fh
, 0, OFFSET_END
);
74 size
= Seek(fdesc
->fh
, 0, OFFSET_CURRENT
);
75 Seek(fdesc
->fh
, oldpos
, OFFSET_BEGINNING
);
77 if ((length
= SetFileSize(fdesc
->fh
, length
, OFFSET_BEGINNING
)) == -1)
79 errno
= IoErr2errno(IoErr());
85 char buf
[16]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
89 oldpos
= Seek(fdesc
->fh
, size
, OFFSET_BEGINNING
);
93 FWrite(fdesc
->fh
, buf
, 16, 1);
97 FWrite(fdesc
->fh
, buf
, length
, 1);
100 Seek(fdesc
->fh
, oldpos
, OFFSET_BEGINNING
);