source: rtems/cpukit/libcsupport/src/link.c @ f26145b

4.104.114.84.95
Last change on this file since f26145b was 50f32b11, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/18/04 at 06:05:35

Remove stray white spaces.

  • 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.rtems.com/license/LICENSE.
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#include <rtems/seterr.h>
24
25int link(
26  const char *existing,
27  const char *new
28)
29{
30  rtems_filesystem_location_info_t    existing_loc;
31  rtems_filesystem_location_info_t    parent_loc;
32  int                                 i;
33  int                                 result;
34  const char                         *name_start;
35
36  /*
37   * Get the node we are linking to.
38   */
39
40  result = rtems_filesystem_evaluate_path( existing, 0, &existing_loc, TRUE );
41  if ( result != 0 )
42     return -1;
43
44  /*
45   * Get the parent of the node we are creating.
46   */
47
48  rtems_filesystem_get_start_loc( new, &i, &parent_loc );
49
50  if ( !parent_loc.ops->evalformake_h ) {
51    rtems_filesystem_freenode( &existing_loc );
52    rtems_set_errno_and_return_minus_one( ENOTSUP );
53  }
54
55  result = (*parent_loc.ops->evalformake_h)( &new[i], &parent_loc, &name_start );
56  if ( result != 0 ) {
57    rtems_filesystem_freenode( &existing_loc );
58    rtems_set_errno_and_return_minus_one( result );
59  }
60
61  /*
62   *  Check to see if the caller is trying to link across file system
63   *  boundaries.
64   */
65
66  if ( parent_loc.mt_entry != existing_loc.mt_entry ) {
67    rtems_filesystem_freenode( &existing_loc );
68    rtems_filesystem_freenode( &parent_loc );
69    rtems_set_errno_and_return_minus_one( EXDEV );
70  }
71
72  if ( !parent_loc.ops->link_h ) {
73    rtems_filesystem_freenode( &existing_loc );
74    rtems_filesystem_freenode( &parent_loc );
75    rtems_set_errno_and_return_minus_one( ENOTSUP );
76  }
77
78  result = (*parent_loc.ops->link_h)( &existing_loc, &parent_loc, name_start );
79
80  rtems_filesystem_freenode( &existing_loc );
81  rtems_filesystem_freenode( &parent_loc );
82
83  return result;
84}
85
86/*
87 *  _link_r
88 *
89 *  This is the Newlib dependent reentrant version of link().
90 */
91
92#if defined(RTEMS_NEWLIB)
93
94#include <reent.h>
95
96int _link_r(
97  struct _reent *ptr,
98  const char    *existing,
99  const char    *new
100)
101{
102  return link( existing, new );
103}
104#endif
Note: See TracBrowser for help on using the repository browser.