Update contrib.
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Name : ftruncate.cpp
16 // Contains the source for fchdir
24 #include <sys/types.h>
34 The reentrant version for ftruncate function.
36 int _truncate_r(struct _reent *r, int fd, off_t len)
40 if(fstat(fd,&st) != 0)
42 r->_errno = EINVAL; //KErrArgument
47 if (!(S_ISREG(st.st_mode)))
49 r->_errno = EBADF; //KErrBadHandle
54 return Backend()->Truncate( fd, len, r->_errno);
58 Truncates the given file (using file descriptor) to the length specified.
59 Calls the reentrant version.
60 The ftruncate() function shall cause the size of the file to be truncated
61 to length arument. If the size of the file previously exceeded length, the
62 extra data shall no longer be available to reads on the file. If the file
63 previously was smaller than this size, ftruncate() shall either increase
64 the size of the file or fail. Upon successful completion, ftruncate() shall
65 return 0; otherwise, -1 shall be returned and errno set to indicate the error.
67 EXPORT_C int ftruncate(int filedesc, off_t length)
69 return _truncate_r(_REENT, filedesc, length);
73 Truncates the given file (using file name) to the length specified.
74 Calls the reentrant version.
75 The truncate() function shall cause the size of the file to be truncated
76 to length arument. If the size of the file previously exceeded length, the
77 extra data shall no longer be available to reads on the file. If the file
78 previously was smaller than this size, truncate() shall either increase
79 the size of the file or fail. Upon successful completion, truncate() shall
80 return 0; otherwise, -1 shall be returned and errno set to indicate the error.
82 EXPORT_C int truncate(const char *file , off_t length)
88 if((fd = open(file , O_WRONLY)) < 0)
92 retval = ftruncate(fd , length);
95 errVal = errno; //Store the error value