source: rtems/c/src/lib/libc/link.c @ 72650fcb

4.104.114.84.95
Last change on this file since 72650fcb was efb5450, checked in by Joel Sherrill <joel.sherrill@…>, on 10/17/01 at 17:57:42

2001-10-17 Till Straumann <strauman@…>

  • These changes were discussed and reviewed by many people but the primary people were Jennifer Averett <jennifer@…> and Eugeny Mints <jack@…>.
  • libc/utime.c: Add missing call to rtems_filesystem_freenode() at verification that utime is supported by the filesystem.
  • libc/link.c: Remove calls to freenode when the node was not successfully allocated.
  • libc/unmount.c: In the method file_systems_below_this_mountpoint() added calls to correctly free fs_root_loc when a failure occurs.
  • libc/open.c: Add freenode calls upon failure.
  • libc/open.c, lib/libc/close.c: (PENDING -- NOT INCLUDED THIS TIMER) Modifications the move the freenode from open() to close() (also part of this patch) are pending further discussion.
  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  link() - POSIX 1003.1b - 5.3.4 - Create a new link
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.OARcorp.com/rtems/license.html.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems.h>
19#include <rtems/libio.h>
20#include <errno.h>
21
22#include <rtems/libio_.h>
23
24int link(
25  const char *existing,
26  const char *new
27)
28{
29  rtems_filesystem_location_info_t    existing_loc;
30  rtems_filesystem_location_info_t    parent_loc;
31  int                                 i;
32  int                                 result;
33  const char                         *name_start;
34
35  /*
36   * Get the node we are linking to.
37   */
38
39  result = rtems_filesystem_evaluate_path( existing, 0, &existing_loc, TRUE );
40  if ( result != 0 )
41     return -1;
42
43  /*
44   * Get the parent of the node we are creating.
45   */
46
47  rtems_filesystem_get_start_loc( new, &i, &parent_loc );
48
49  if ( !parent_loc.ops->evalformake_h ) {
50    rtems_filesystem_freenode( &existing_loc );
51    set_errno_and_return_minus_one( ENOTSUP );
52  }
53
54  result = (*parent_loc.ops->evalformake_h)( &new[i], &parent_loc, &name_start );
55  if ( result != 0 ) {
56    rtems_filesystem_freenode( &existing_loc );
57    set_errno_and_return_minus_one( result );
58  }
59
60  /*
61   *  Check to see if the caller is trying to link across file system
62   *  boundaries.
63   */
64
65  if ( parent_loc.mt_entry != existing_loc.mt_entry ) {
66    rtems_filesystem_freenode( &existing_loc );
67    rtems_filesystem_freenode( &parent_loc );
68    set_errno_and_return_minus_one( EXDEV );
69  }
70
71  if ( !parent_loc.ops->link_h ) {
72    rtems_filesystem_freenode( &existing_loc );
73    rtems_filesystem_freenode( &parent_loc );
74    set_errno_and_return_minus_one( ENOTSUP );
75  }
76
77  result = (*parent_loc.ops->link_h)( &existing_loc, &parent_loc, name_start );
78 
79  rtems_filesystem_freenode( &existing_loc );
80  rtems_filesystem_freenode( &parent_loc );
81
82  return result;
83}
84
85/*
86 *  _link_r
87 *
88 *  This is the Newlib dependent reentrant version of link().
89 */
90
91#if defined(RTEMS_NEWLIB)
92
93#include <reent.h>
94
95int _link_r(
96  struct _reent *ptr,
97  const char    *existing,
98  const char    *new
99)
100{
101  return link( existing, new );
102}
103#endif
104
Note: See TracBrowser for help on using the repository browser.