summaryrefslogtreecommitdiffstats
path: root/cpukit/libfs/src/imfs/imfs_rename.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/libfs/src/imfs/imfs_rename.c')
-rw-r--r--cpukit/libfs/src/imfs/imfs_rename.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/cpukit/libfs/src/imfs/imfs_rename.c b/cpukit/libfs/src/imfs/imfs_rename.c
index 46ef674075..b8f64c4ac1 100644
--- a/cpukit/libfs/src/imfs/imfs_rename.c
+++ b/cpukit/libfs/src/imfs/imfs_rename.c
@@ -30,31 +30,41 @@ int IMFS_rename(
size_t namelen
)
{
- int rv = 0;
IMFS_jnode_t *node = oldloc->node_access;
IMFS_jnode_t *new_parent = newparentloc->node_access;
+ char *allocated_name;
/*
* FIXME: Due to insufficient checks we can create inaccessible nodes with
* this operation.
*/
- if ( node->Parent != NULL ) {
- if ( namelen < IMFS_NAME_MAX ) {
- memcpy( node->name, name, namelen );
- node->name [namelen] = '\0';
-
- IMFS_remove_from_directory( node );
- IMFS_add_to_directory( new_parent, node );
- IMFS_update_ctime( node );
- } else {
- errno = ENAMETOOLONG;
- rv = -1;
- }
- } else {
- errno = EINVAL;
- rv = -1;
+ if ( node->Parent == NULL ) {
+ rtems_set_errno_and_return_minus_one( EINVAL );
}
- return rv;
+ if ( namelen >= IMFS_NAME_MAX ) {
+ rtems_set_errno_and_return_minus_one( ENAMETOOLONG );
+ }
+
+ allocated_name = malloc( namelen );
+ if ( allocated_name == NULL ) {
+ rtems_set_errno_and_return_minus_one( ENOMEM );
+ }
+
+ memcpy( allocated_name, name, namelen );
+
+ if ( ( node->flags & IMFS_NODE_FLAG_NAME_ALLOCATED ) != 0 ) {
+ free( node->name );
+ }
+
+ node->name = allocated_name;
+ node->namelen = namelen;
+ node->flags |= IMFS_NODE_FLAG_NAME_ALLOCATED;
+
+ IMFS_remove_from_directory( node );
+ IMFS_add_to_directory( new_parent, node );
+ IMFS_update_ctime( node );
+
+ return 0;
}