source: rtems/cpukit/libcsupport/src/rmdir.c @ 0aea082

4.115
Last change on this file since 0aea082 was 0aea082, checked in by Joel Sherrill <joel.sherrill@…>, on 07/30/10 at 22:36:32

2010-07-30 Joel Sherrill <joel.sherrill@…>

  • libcsupport/src/fstat.c, libcsupport/src/rmdir.c, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_debug.c, libfs/src/imfs/imfs_getchild.c, libfs/src/imfs/memfile.c: Add IMFS_assert. Clean up and remove all checks which are redundant with system call layer. Formatting.
  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 *  rmdir() - POSIX 1003.1b - 5.2.2 - Remove a Directory
3 *
4 *  COPYRIGHT (c) 1989-1999.
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 <sys/types.h>
19#include <fcntl.h>
20#include <unistd.h>
21#include <errno.h>
22#include <stdlib.h>
23
24#include <rtems/libio_.h>
25#include <rtems/seterr.h>
26
27int rmdir(
28  const char *pathname
29)
30{
31  int                               parentpathlen;
32  const char                       *name;
33  rtems_filesystem_location_info_t  parentloc;
34  rtems_filesystem_location_info_t  loc;
35  int                               i;
36  int                               result;
37  bool                              free_parentloc = false;
38
39  /*
40   *  Get the parent node of the node we wish to remove. Find the parent path.
41   */
42
43  parentpathlen = rtems_filesystem_dirname ( pathname );
44
45  if ( parentpathlen == 0 )
46    rtems_filesystem_get_start_loc( pathname, &i, &parentloc );
47  else {
48    result = rtems_filesystem_evaluate_path(pathname, parentpathlen,
49                                            RTEMS_LIBIO_PERMS_WRITE,
50                                            &parentloc,
51                                            false );
52    if ( result != 0 )
53      return -1;
54
55    free_parentloc = true;
56  }
57
58  /*
59   * Start from the parent to find the node that should be under it.
60   */
61
62  loc = parentloc;
63  name = pathname + parentpathlen;
64  name += rtems_filesystem_prefix_separators( name, strlen( name ) );
65
66  result = rtems_filesystem_evaluate_relative_path( name , strlen( name ),
67                                                    0, &loc, false );
68  if ( result != 0 ) {
69    if ( free_parentloc )
70      rtems_filesystem_freenode( &parentloc );
71    return -1;
72  }
73
74  /*
75   * Verify you can remove this node as a directory.
76   */
77  if ( (*loc.ops->node_type_h)( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ) {
78    rtems_filesystem_freenode( &loc );
79    if ( free_parentloc )
80      rtems_filesystem_freenode( &parentloc );
81    rtems_set_errno_and_return_minus_one( ENOTDIR );
82  }
83
84  /*
85   * Use the filesystems rmnod to remove the node.
86   */
87
88  result =  (*loc.handlers->rmnod_h)( &parentloc, &loc );
89
90  rtems_filesystem_freenode( &loc );
91  if ( free_parentloc )
92    rtems_filesystem_freenode( &parentloc );
93
94  return result;
95}
Note: See TracBrowser for help on using the repository browser.