[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 | |
---|
| 23 | int 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 | |
---|
| 76 | int _unlink_r( |
---|
| 77 | struct _reent *ptr, |
---|
| 78 | const char *path |
---|
| 79 | ) |
---|
| 80 | { |
---|
| 81 | return unlink( path ); |
---|
| 82 | } |
---|
| 83 | #endif |
---|
| 84 | |
---|