source: rtems/cpukit/libfs/src/imfs/imfs_symlink.c @ 8c29e98

4.104.115
Last change on this file since 8c29e98 was 8c29e98, checked in by Joel Sherrill <joel.sherrill@…>, on 01/18/10 at 18:24:53

2010-01-18 Joel Sherrill <joel.sherrill@…>

  • libfs/src/imfs/imfs_symlink.c: Add comment on Coverity CID22. This is not a resource leak.
  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*
2 *  IMFS_symlink
3 *
4 *  The following rouine creates a new symbolic link node under parent
5 *  with the name given in name.  The node is set to point to the node at
6 *  to_loc.
7 *
8 *  COPYRIGHT (c) 1989-2009.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 *  $Id$
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <errno.h>
23#include <string.h>
24#include <stdlib.h>
25#include "imfs.h"
26#include <rtems/libio_.h>
27#include <rtems/seterr.h>
28
29int IMFS_symlink(
30  rtems_filesystem_location_info_t  *parent_loc,
31  const char                        *link_name,
32  const char                        *node_name
33)
34{
35  IMFS_types_union   info;
36  IMFS_jnode_t      *new_node;
37  char               new_name[ IMFS_NAME_MAX + 1 ];
38  int                i;
39
40  /*
41   * Remove any separators at the end of the string.
42   */
43
44  IMFS_get_token( node_name, strlen( node_name ), new_name, &i );
45
46  /*
47   * Duplicate link name
48   */
49
50  info.sym_link.name = strdup(link_name);
51  if (info.sym_link.name == NULL) {
52    rtems_set_errno_and_return_minus_one(ENOMEM);
53  }
54
55  /*
56   *  Create a new link node.
57   *
58   *  NOTE: Coverity CID 22 notes this as a resource leak.  We are ignoring
59   *        this analysis because in this particular case it is wrong. This
60   *        method creates a symbolic link node for the IMFS.  The memory
61   *        allocated must persist for the life of the symbolic link not
62   *        the life of the method.
63   */
64
65  new_node = IMFS_create_node(
66    parent_loc,
67    IMFS_SYM_LINK,
68    new_name,
69    ( S_IFLNK | ( S_IRWXU | S_IRWXG | S_IRWXO )),
70    &info
71  );
72
73  if (new_node == NULL) {
74    free(info.sym_link.name);
75    rtems_set_errno_and_return_minus_one(ENOMEM);
76  }
77
78  return 0;
79}
Note: See TracBrowser for help on using the repository browser.