[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tyndur-devel] [PATCH] Shell: readlink() und symlink() benutzen
* Shell: readlink() und symlink() benutzen, statt selbst mit fopen()
rumzufrickeln.
Signed-off-by: Antoine Kaufmann <toni@xxxxxxxxxx>
---
src/modules/c/shell/cmds/readlink.c | 8 ++------
src/modules/c/shell/cmds/symlink.c | 8 +-------
2 files changed, 3 insertions(+), 13 deletions(-)
diff --git a/src/modules/c/shell/cmds/readlink.c b/src/modules/c/shell/cmds/readlink.c
index 2c31bd3..e0015ab 100644
--- a/src/modules/c/shell/cmds/readlink.c
+++ b/src/modules/c/shell/cmds/readlink.c
@@ -49,22 +49,18 @@ void readlink_display_usage(void);
#endif
{
char buffer[4096];
- size_t len;
+ ssize_t len;
if (argc != 2) {
readlink_display_usage();
return -1;
}
- FILE* file = fopen(argv[1], "lr");
- if (file == NULL) {
+ if ((len = readlink(argv[1], buffer, sizeof(buffer) - 1)) < 0) {
puts("Fehler: Symlink konnte nicht gelesen werden.");
return -1;
}
-
- len = fread(buffer, 1, 4095, file);
buffer[len] = 0;
- fclose(file);
puts(buffer);
diff --git a/src/modules/c/shell/cmds/symlink.c b/src/modules/c/shell/cmds/symlink.c
index c1dcc43..1379f2b 100644
--- a/src/modules/c/shell/cmds/symlink.c
+++ b/src/modules/c/shell/cmds/symlink.c
@@ -54,16 +54,10 @@ void symlink_display_usage(void);
return -1;
}
- FILE* file = fopen(argv[1], "lw");
-
- if (file == NULL) {
+ if (symlink(argv[2], argv[1])) {
puts("Fehler: Symlink konnte nicht erstellt werden.");
return -1;
}
-
- char* dest = io_get_absolute_path(argv[2]);
- fwrite(dest, 1, strlen(dest) + 1, file);
- fclose(file);
return EXIT_SUCCESS;
}
--
1.6.4.4