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

4.115
Last change on this file since c499856 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: 1.7 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Create a new link
5 *  @ingroup libcsupport
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-1999.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18  #include "config.h"
19#endif
20
21#include <unistd.h>
22
23#include <rtems/libio_.h>
24
25/**
26 *  link() - POSIX 1003.1b - 5.3.4 - Create a new link
27 */
28int link( const char *path1, const char *path2 )
29{
30  int rv = 0;
31  rtems_filesystem_eval_path_context_t ctx_1;
32  rtems_filesystem_eval_path_context_t ctx_2;
33  int eval_flags_1 = RTEMS_FS_FOLLOW_LINK;
34  int eval_flags_2 = RTEMS_FS_FOLLOW_LINK
35    | RTEMS_FS_MAKE
36    | RTEMS_FS_EXCLUSIVE;
37  const rtems_filesystem_location_info_t *currentloc_1 =
38    rtems_filesystem_eval_path_start( &ctx_1, path1, eval_flags_1 );
39  const rtems_filesystem_location_info_t *currentloc_2 =
40    rtems_filesystem_eval_path_start( &ctx_2, path2, eval_flags_2 );
41
42  rv = rtems_filesystem_location_exists_in_same_instance_as(
43    currentloc_1,
44    currentloc_2
45  );
46  if ( rv == 0 ) {
47    rv = (*currentloc_2->mt_entry->ops->link_h)(
48      currentloc_2,
49      currentloc_1,
50      rtems_filesystem_eval_path_get_token( &ctx_2 ),
51      rtems_filesystem_eval_path_get_tokenlen( &ctx_2 )
52    );
53  }
54
55  rtems_filesystem_eval_path_cleanup( &ctx_1 );
56  rtems_filesystem_eval_path_cleanup( &ctx_2 );
57
58  return rv;
59}
60
61#if defined(RTEMS_NEWLIB)
62
63#include <reent.h>
64
65/**
66 *  This is the Newlib dependent reentrant version of link().
67 */
68int _link_r(
69  struct _reent *ptr __attribute__((unused)),
70  const char    *path1,
71  const char    *path2
72)
73{
74  return link( path1, path2 );
75}
76#endif
Note: See TracBrowser for help on using the repository browser.