source: rtems/c/src/lib/libc/ftruncate.c @ cca4400

4.104.114.84.95
Last change on this file since cca4400 was cca4400, checked in by Joel Sherrill <joel.sherrill@…>, on 12/10/98 at 23:31:54

Merged Eric Norum's select patch that was based on 4.0 and resolved
all conflicts.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/*
2 *  ftruncate() - Truncate a File to the Specified Length
3 *
4 *  COPYRIGHT (c) 1989-1998.
5 *  On-Line Applications Research Corporation (OAR).
6 *  Copyright assigned to U.S. Government, 1994.
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#include <unistd.h>
16#include <errno.h>
17
18#include "libio_.h"
19
20int ftruncate(
21  int     fd,
22  off_t   length
23)
24{
25  rtems_libio_t                    *iop;
26  rtems_filesystem_location_info_t  loc;
27 
28  rtems_libio_check_fd( fd );
29  iop = rtems_libio_iop( fd );
30
31  /*
32   *  If this is not a file system based entity, it is an error.
33   */
34
35  if ( iop->flags & LIBIO_FLAGS_HANDLER_MASK )
36    set_errno_and_return_minus_one( EBADF );
37
38  /*
39   *  Now process the ftruncate() request.
40   */
41 
42  /*
43   *  Make sure we are not working on a directory
44   */
45
46  loc = iop->pathinfo;
47  if ( !loc.ops->node_type )
48    set_errno_and_return_minus_one( ENOTSUP );
49   
50  if ( (*loc.ops->node_type)( &loc ) == RTEMS_FILESYSTEM_DIRECTORY )
51    set_errno_and_return_minus_one( EISDIR );
52
53  rtems_libio_check_permissions( iop, LIBIO_FLAGS_WRITE );
54
55  if ( !iop->handlers->ftruncate )
56    set_errno_and_return_minus_one( ENOTSUP );
57
58  return (*iop->handlers->ftruncate)( iop, length );
59}
60 
Note: See TracBrowser for help on using the repository browser.