[4779963] | 1 | /* |
---|
| 2 | * _rename_r() - POSIX 1003.1b - 5.3.4 - Rename a file |
---|
| 3 | * |
---|
| 4 | * COPYRIGHT (c) 1989-2007. |
---|
| 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * |
---|
[3b7c123] | 7 | * Modifications to support reference counting in the file system are |
---|
| 8 | * Copyright (c) 2012 embedded brains GmbH. |
---|
| 9 | * |
---|
[4779963] | 10 | * The license and distribution terms for this file may be |
---|
| 11 | * found in the file LICENSE in this distribution or at |
---|
| 12 | * http://www.rtems.com/license/LICENSE. |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #if HAVE_CONFIG_H |
---|
| 16 | #include "config.h" |
---|
| 17 | #endif |
---|
| 18 | |
---|
[00da59e4] | 19 | #if defined(RTEMS_NEWLIB) && !defined(HAVE__RENAME_R) |
---|
[3b7c123] | 20 | |
---|
| 21 | #include <stdio.h> |
---|
[00da59e4] | 22 | |
---|
[8ec7abb] | 23 | #include <rtems/libio_.h> |
---|
[8192e4ff] | 24 | |
---|
[4779963] | 25 | int _rename_r( |
---|
[9e14ca2] | 26 | struct _reent *ptr __attribute__((unused)), |
---|
[4779963] | 27 | const char *old, |
---|
| 28 | const char *new |
---|
| 29 | ) |
---|
| 30 | { |
---|
[3b7c123] | 31 | int rv = 0; |
---|
| 32 | rtems_filesystem_eval_path_context_t old_ctx; |
---|
| 33 | int old_eval_flags = 0; |
---|
| 34 | rtems_filesystem_location_info_t old_parentloc; |
---|
[2563410] | 35 | int old_parent_eval_flags = RTEMS_FS_PERMS_WRITE |
---|
| 36 | | RTEMS_FS_FOLLOW_HARD_LINK; |
---|
[3b7c123] | 37 | const rtems_filesystem_location_info_t *old_currentloc = |
---|
| 38 | rtems_filesystem_eval_path_start_with_parent( |
---|
| 39 | &old_ctx, |
---|
| 40 | old, |
---|
| 41 | old_eval_flags, |
---|
| 42 | &old_parentloc, |
---|
| 43 | old_parent_eval_flags |
---|
| 44 | ); |
---|
| 45 | rtems_filesystem_eval_path_context_t new_ctx; |
---|
| 46 | |
---|
| 47 | /* FIXME: This is not POSIX conform */ |
---|
[2563410] | 48 | int new_eval_flags = RTEMS_FS_FOLLOW_HARD_LINK |
---|
| 49 | | RTEMS_FS_MAKE |
---|
| 50 | | RTEMS_FS_EXCLUSIVE; |
---|
[3b7c123] | 51 | |
---|
| 52 | const rtems_filesystem_location_info_t *new_currentloc = |
---|
| 53 | rtems_filesystem_eval_path_start( &new_ctx, new, new_eval_flags ); |
---|
| 54 | |
---|
| 55 | rv = rtems_filesystem_location_exists_in_same_fs_instance_as( |
---|
| 56 | old_currentloc, |
---|
| 57 | new_currentloc |
---|
| 58 | ); |
---|
| 59 | if ( rv == 0 ) { |
---|
| 60 | rv = (*new_currentloc->ops->rename_h)( |
---|
| 61 | &old_parentloc, |
---|
| 62 | old_currentloc, |
---|
| 63 | new_currentloc, |
---|
| 64 | rtems_filesystem_eval_path_get_token( &new_ctx ), |
---|
| 65 | rtems_filesystem_eval_path_get_tokenlen( &new_ctx ) |
---|
| 66 | ); |
---|
[8ec7abb] | 67 | } |
---|
| 68 | |
---|
[3b7c123] | 69 | rtems_filesystem_eval_path_cleanup_with_parent( &old_ctx, &old_parentloc ); |
---|
| 70 | rtems_filesystem_eval_path_cleanup( &new_ctx ); |
---|
[8ec7abb] | 71 | |
---|
[3b7c123] | 72 | return rv; |
---|
[8ec7abb] | 73 | } |
---|
[00da59e4] | 74 | #endif |
---|