source: rtems/cpukit/libcsupport/src/_rename_r.c @ e02d5dd9

4.115
Last change on this file since e02d5dd9 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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