[rtems commit] IMFS: Simplify IMFS_symlink()

Sebastian Huber sebh at rtems.org
Thu Feb 12 20:48:07 UTC 2015


Module:    rtems
Branch:    master
Commit:    9247d3faeefcfd2223cd5b12340127aecc319c1c
Changeset: http://git.rtems.org/rtems/commit/?id=9247d3faeefcfd2223cd5b12340127aecc319c1c

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Feb  5 16:58:09 2015 +0100

IMFS: Simplify IMFS_symlink()

---

 cpukit/libfs/src/imfs/imfs_symlink.c | 33 +++++++--------------------------
 1 file changed, 7 insertions(+), 26 deletions(-)

diff --git a/cpukit/libfs/src/imfs/imfs_symlink.c b/cpukit/libfs/src/imfs/imfs_symlink.c
index 2ddf99c..0f06446 100644
--- a/cpukit/libfs/src/imfs/imfs_symlink.c
+++ b/cpukit/libfs/src/imfs/imfs_symlink.c
@@ -20,7 +20,6 @@
 
 #include "imfs.h"
 
-#include <stdlib.h>
 #include <string.h>
 
 static const IMFS_node_control IMFS_node_control_sym_link;
@@ -32,33 +31,23 @@ int IMFS_symlink(
   const char *target
 )
 {
-  char         *dup_target;
   IMFS_jnode_t *new_node;
 
   /*
-   * Duplicate link name
-   */
-  dup_target = strdup(target);
-  if (dup_target == NULL) {
-    rtems_set_errno_and_return_minus_one(ENOMEM);
-  }
-
-  /*
    *  Create a new link node.
    */
   new_node = IMFS_create_node(
     parentloc,
     &IMFS_node_control_sym_link,
-    sizeof( IMFS_sym_link_t ),
+    sizeof( IMFS_sym_link_t ) + strlen( target ) + 1,
     name,
     namelen,
     ( S_IFLNK | ( S_IRWXU | S_IRWXG | S_IRWXO )),
-    dup_target
+    RTEMS_DECONST( char *, target )
   );
 
-  if (new_node == NULL) {
-    free(dup_target);
-    rtems_set_errno_and_return_minus_one(ENOMEM);
+  if ( new_node == NULL ) {
+    rtems_set_errno_and_return_minus_one( ENOMEM );
   }
 
   return 0;
@@ -118,23 +107,15 @@ static IMFS_jnode_t *IMFS_node_initialize_sym_link(
 {
   IMFS_sym_link_t *sym_link = (IMFS_sym_link_t *) node;
 
-  sym_link->name = arg;
+  sym_link->name = (char *) sym_link + sizeof( *sym_link );
+  strcpy( sym_link->name, arg );
 
   return node;
 }
 
-static void IMFS_node_destroy_sym_link( IMFS_jnode_t *node )
-{
-  IMFS_sym_link_t *sym_link = (IMFS_sym_link_t *) node;
-
-  free( sym_link->name );
-
-  IMFS_node_destroy_default( node );
-}
-
 static const IMFS_node_control IMFS_node_control_sym_link = {
   .handlers = &IMFS_link_handlers,
   .node_initialize = IMFS_node_initialize_sym_link,
   .node_remove = IMFS_node_remove_default,
-  .node_destroy = IMFS_node_destroy_sym_link
+  .node_destroy = IMFS_node_destroy_default
 };



More information about the vc mailing list