[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tyndur-devel] [PATCH 1/9] Shell: readlink() und symlink() benutzen
From: Antoine Kaufmann <toni@xxxxxxxxxx>
* Shell: readlink() und symlink() benutzen, statt selbst mit fopen()
rumzufrickeln.
Signed-off-by: Antoine Kaufmann <toni@xxxxxxxxxx>
Signed-off-by: Kevin Wolf <kevin@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 46497c2..51ef146 100644
--- a/src/modules/c/shell/cmds/readlink.c
+++ b/src/modules/c/shell/cmds/readlink.c
@@ -50,23 +50,19 @@ 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) {
fprintf(stderr, TMS(readlink_error,
"Fehler: Symlink konnte nicht gelesen werden!\n"));
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 2d3eeef..b9886f4 100644
--- a/src/modules/c/shell/cmds/symlink.c
+++ b/src/modules/c/shell/cmds/symlink.c
@@ -55,17 +55,11 @@ void symlink_display_usage(void);
return -1;
}
- FILE* file = fopen(argv[1], "lw");
-
- if (file == NULL) {
+ if (symlink(argv[2], argv[1])) {
fprintf(stderr, TMS(symlink_error,
"Fehler: Symlink konnte nicht erstellt werden!\n"));
return -1;
}
-
- char* dest = io_get_absolute_path(argv[2]);
- fwrite(dest, 1, strlen(dest) + 1, file);
- fclose(file);
return EXIT_SUCCESS;
}
--
1.6.0.2