source: rtems/cpukit/libcsupport/src/unlink.c @ 86042ae9

Last change on this file since 86042ae9 was 86042ae9, checked in by Jennifer Averett <Jennifer.Averett@…>, on 11/25/03 at 17:27:55

2003-11-25 Jennifer Averett <jennifer@…>

PR 519/filesystem

  • include/rtems/libio_.h, src/eval.c, src/rmdir.c, src/unlink.c: Check write permissions in parent directory for file or directory delete
  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[07a3253d]1/*
2 *  unlink() - POSIX 1003.1b - 5.5.1 - Remove an existing link
3 *
[08311cc3]4 *  COPYRIGHT (c) 1989-1999.
[07a3253d]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
[8638d32b]9 *  http://www.rtems.com/license/LICENSE.
[07a3253d]10 *
11 *  $Id$
12 */
13
[9c49db4]14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
[07a3253d]18#include <errno.h>
19
[3ba74c73]20#include <rtems/libio_.h>
[a02224e]21#include <rtems/seterr.h>
[07a3253d]22
23int unlink(
24  const char *path
25)
26{
27  rtems_filesystem_location_info_t  loc;
28  int                               result;
29
30  /*
31   * Get the node to be unlinked.
32   */
33
34  result = rtems_filesystem_evaluate_path( path, 0, &loc, FALSE );
35  if ( result != 0 )
36     return -1;
37 
[86042ae9]38  result = rtems_filesystem_evaluate_parent(RTEMS_LIBIO_PERMS_WRITE, &loc );
39  if (result != 0){
40    rtems_filesystem_freenode( &loc );
41    return -1;
42  }
43
[9c3fa30]44  if ( !loc.ops->node_type_h ) {
[dd0f326]45    rtems_filesystem_freenode( &loc );
[a02224e]46    rtems_set_errno_and_return_minus_one( ENOTSUP );
[d71fcab]47  }
[07a3253d]48
[9c3fa30]49  if (  (*loc.ops->node_type_h)( &loc ) == RTEMS_FILESYSTEM_DIRECTORY ) {
[dd0f326]50    rtems_filesystem_freenode( &loc );
[a02224e]51    rtems_set_errno_and_return_minus_one( EISDIR );
[d71fcab]52  }
53
[9c3fa30]54  if ( !loc.ops->unlink_h ) {
[dd0f326]55    rtems_filesystem_freenode( &loc );
[a02224e]56    rtems_set_errno_and_return_minus_one( ENOTSUP );
[d71fcab]57  }
[07a3253d]58
[9c3fa30]59  result = (*loc.ops->unlink_h)( &loc );
[d71fcab]60
[dd0f326]61  rtems_filesystem_freenode( &loc );
[d71fcab]62 
63  return result;
[07a3253d]64}
[d006519b]65
66/*
67 *  _unlink_r
68 *
69 *  This is the Newlib dependent reentrant version of unlink().
70 */
71
72#if defined(RTEMS_NEWLIB)
73
74#include <reent.h>
75
76int _unlink_r(
77  struct _reent *ptr,
78  const char    *path
79)
80{
81  return unlink( path );
82}
83#endif
84
Note: See TracBrowser for help on using the repository browser.