source: rtems/c/src/lib/libc/link.c @ 98f3cfa

4.104.114.84.95
Last change on this file since 98f3cfa was 9c49db4, checked in by Joel Sherrill <joel.sherrill@…>, on 01/08/01 at 18:26:44

2001-01-08 Ralf Corsepius <corsepiu@…>

  • configure.in: Add libc/config.h
  • libc/Makefile.am: Add INCLUDES += -I. to pickup config.h
  • libc/.cvsignore: Add config.h and stamp-h
  • libc/*.c: Add config.h support.
  • Property mode set to 100644
File size: 2.4 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    rtems_filesystem_freenode( &parent_loc );
52    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_filesystem_freenode( &parent_loc );
59    set_errno_and_return_minus_one( result );
60  }
61
62  /*
63   *  Check to see if the caller is trying to link across file system
64   *  boundaries.
65   */
66
67  if ( parent_loc.mt_entry != existing_loc.mt_entry ) {
68    rtems_filesystem_freenode( &existing_loc );
69    rtems_filesystem_freenode( &parent_loc );
70    set_errno_and_return_minus_one( EXDEV );
71  }
72
73  if ( !parent_loc.ops->link_h ) {
74    rtems_filesystem_freenode( &existing_loc );
75    rtems_filesystem_freenode( &parent_loc );
76    set_errno_and_return_minus_one( ENOTSUP );
77  }
78
79  result = (*parent_loc.ops->link_h)( &existing_loc, &parent_loc, name_start );
80 
81  rtems_filesystem_freenode( &existing_loc );
82  rtems_filesystem_freenode( &parent_loc );
83
84  return result;
85}
86
87/*
88 *  _link_r
89 *
90 *  This is the Newlib dependent reentrant version of link().
91 */
92
93#if defined(RTEMS_NEWLIB)
94
95#include <reent.h>
96
97int _link_r(
98  struct _reent *ptr,
99  const char    *existing,
100  const char    *new
101)
102{
103  return link( existing, new );
104}
105#endif
106
Note: See TracBrowser for help on using the repository browser.