[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH] cp: Kopieren mit Verzeichnis als Ziel gefixt.



---
 trunk/src/modules/c/shell/cmds/cp.c |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/trunk/src/modules/c/shell/cmds/cp.c b/trunk/src/modules/c/shell/cmds/cp.c
index 0d66eaf..afd84e5 100644
--- a/trunk/src/modules/c/shell/cmds/cp.c
+++ b/trunk/src/modules/c/shell/cmds/cp.c
@@ -1,8 +1,8 @@
 /*
- * Copyright (c) 2007 The tyndur Project. All rights reserved.
+ * Copyright (c) 2007-2009 The tyndur Project. All rights reserved.
  *
  * This code is derived from software contributed to the tyndur Project
- * by Kevin Wolf.
+ * by Kevin Wolf, Alexander Siol
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -226,18 +226,13 @@ int cp_file(char* src_path, char* dst_path) {
         return -1;
     }
 
+    int free_dst_path = 0;
     FILE* dst = NULL;
     if (is_directory(dst_path)) {
         char* filename = io_split_filename(src_path);
-        size_t length = strlen(filename) + strlen(dst_path) + 1;
-
-        char dst_file_path[length + 1];
-        strcpy(dst_file_path, dst_path);
-        dst_file_path[strlen(dst_file_path) + 1] = '\0';
-        dst_file_path[strlen(dst_file_path)] = '/';
-        strcat(dst_file_path, filename);
-        dst_file_path[length] = '\0';
-        dst_path = dst_file_path;
+        asprintf(&dst_path, "%s/%s", dst_path, filename);
+        free(filename);
+        free_dst_path = 1;
     }
     dst = fopen(dst_path, "w");
 
@@ -263,6 +258,10 @@ int cp_file(char* src_path, char* dst_path) {
         fwrite(buffer, length, 1, dst);
     }
 
+    if (free_dst_path) {
+        free(dst_path);
+    }
+
     fclose(src);
     fclose(dst);
 
-- 
1.5.6.5