source: rtems/cpukit/libcsupport/src/fchdir.c @ 50f32b11

4.104.114.84.95
Last change on this file since 50f32b11 was 50f32b11, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/18/04 at 06:05:35

Remove stray white spaces.

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 *  fchdir() - compatible with SVr4, 4.4BSD and X/OPEN - Change Directory
3 *
4 *  COPYRIGHT (c) 1989-2000.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <unistd.h>
19#include <sys/stat.h>
20#include <errno.h>
21
22#include <rtems.h>
23#include <rtems/libio.h>
24#include <rtems/libio_.h>
25#include <rtems/seterr.h>
26
27int fchdir(
28  int       fd
29)
30{
31  rtems_libio_t *iop;
32  rtems_filesystem_location_info_t loc, saved;
33
34  rtems_libio_check_fd( fd );
35  iop = rtems_libio_iop( fd );
36  rtems_libio_check_is_open(iop);
37
38  /*
39   *  Now process the fchmod().
40   */
41
42  rtems_libio_check_permissions( iop, LIBIO_FLAGS_READ );
43
44  /*
45   * Verify you can change directory into this node.
46   */
47
48  if ( !iop->pathinfo.ops ) {
49    rtems_set_errno_and_return_minus_one( ENOTSUP );
50  }
51
52  if ( !iop->pathinfo.ops->node_type_h ) {
53    rtems_set_errno_and_return_minus_one( ENOTSUP );
54  }
55
56  if (  (*iop->pathinfo.ops->node_type_h)( &iop->pathinfo ) !=
57                                          RTEMS_FILESYSTEM_DIRECTORY ) {
58    rtems_set_errno_and_return_minus_one( ENOTDIR );
59  }
60
61
62  /*
63   * FIXME : I feel there should be another call to
64   *         actually take into account the extra reference to
65   *         this node which we are making here. I can
66   *         see the freenode interface but do not see
67   *         allocnode node interface. It maybe node_type.
68   *
69   * FIXED:  T.Straumann: it is evaluate_path()
70   *         but note the race condition. Threads who
71   *         share their rtems_filesystem_current better
72   *         be synchronized!
73   */
74
75  saved                    = rtems_filesystem_current;
76  rtems_filesystem_current = iop->pathinfo;
77
78  /* clone the current node */
79  if (rtems_filesystem_evaluate_path(".", 0, &loc, 0)) {
80    /* cloning failed; restore original and bail out */
81    rtems_filesystem_current = saved;
82        return -1;
83  }
84  /* release the old one */
85  rtems_filesystem_freenode( &saved );
86
87  rtems_filesystem_current = loc;
88
89  return 0;
90}
Note: See TracBrowser for help on using the repository browser.