[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tyndur-devel] [PATCH v2 6/6] libc: fopen-Modus "l" entfernt
- libc: Der fopen-Modus "l" war eine tyndur-spezifischer Hack für
libc-interne Benutzung
* libc: Alles, was mit Links arbeitet benutzt jetzt direkt lio_compat_*
Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
src/modules/lib/lost_link.c | 11 +++++++----
src/modules/lib/posix/link.c | 8 +++++---
src/modules/lib/posix/stat.c | 10 ++++++----
src/modules/lib/stdlibc/file.c | 5 -----
4 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/src/modules/lib/lost_link.c b/src/modules/lib/lost_link.c
index c4ad030..a9cca01 100644
--- a/src/modules/lib/lost_link.c
+++ b/src/modules/lib/lost_link.c
@@ -51,23 +51,26 @@ int io_create_link(const char* target_path, const char* link_path,
{
int result;
FILE* target_file;
- FILE* link_dir;
if (!hardlink) {
- link_dir = fopen(link_path, "lw");
+ io_resource_t* link_dir = lio_compat_open(link_path,
+ IO_OPEN_MODE_WRITE | IO_OPEN_MODE_CREATE |
+ IO_OPEN_MODE_TRUNC | IO_OPEN_MODE_LINK);
if (link_dir == NULL) {
return -1;
}
- fwrite(target_path, 1, strlen(target_path) + 1, link_dir);
- fclose(link_dir);
+ lio_compat_write(target_path, 1, strlen(target_path) + 1, link_dir);
+ lio_compat_close(link_dir);
+
return 0;
}
// Jetzt werden Datei- und Verzeichnisname geholt
+ FILE* link_dir;
char* link_filename = io_split_filename(link_path);
char* link_dirname = io_split_dirname(link_path);
if ((link_filename == NULL) || (link_dirname == NULL)) {
diff --git a/src/modules/lib/posix/link.c b/src/modules/lib/posix/link.c
index d11439a..715898e 100644
--- a/src/modules/lib/posix/link.c
+++ b/src/modules/lib/posix/link.c
@@ -30,6 +30,7 @@
#include <errno.h>
#include <stdio.h>
#include <io.h>
+#include <lostio.h>
/**
* Einen Hardlink erstellen.
@@ -74,15 +75,16 @@ int symlink(const char* oldpath, const char* newpath)
ssize_t readlink(const char* path, char* buf, size_t bufsize)
{
ssize_t len;
+ io_resource_t* file;
- FILE* file = fopen(path, "lr");
+ file = lio_compat_open(path, IO_OPEN_MODE_READ | IO_OPEN_MODE_LINK);
if (file == NULL) {
errno = EIO;
return -1;
}
- len = fread(buf, 1, bufsize, file);
- fclose(file);
+ len = lio_compat_read(buf, 1, bufsize, file);
+ lio_compat_close(file);
return len;
}
diff --git a/src/modules/lib/posix/stat.c b/src/modules/lib/posix/stat.c
index d5440ae..946a947 100644
--- a/src/modules/lib/posix/stat.c
+++ b/src/modules/lib/posix/stat.c
@@ -160,14 +160,16 @@ int stat(const char* filename, struct stat* stat_buf)
int lstat(const char* filename, struct stat* stat_buf)
{
int result = stat(filename, stat_buf);
- FILE* f;
+ io_resource_t* f;
- if (!result && (f = fopen(filename, "lr"))) {
+ if (!result &&
+ (f = lio_compat_open(filename, IO_OPEN_MODE_READ | IO_OPEN_MODE_LINK)))
+ {
char buf[256];
stat_buf->st_mode = ~(stat_buf->st_mode & S_IFMT) | S_IFLNK;
- stat_buf->st_size = fread(buf, 1, sizeof(buf), f);
+ stat_buf->st_size = lio_compat_read(buf, 1, sizeof(buf), f);
stat_buf->st_blocks = 1;
- fclose(f);
+ lio_compat_close(f);
}
return result;
diff --git a/src/modules/lib/stdlibc/file.c b/src/modules/lib/stdlibc/file.c
index c8aa4cf..573a2a9 100644
--- a/src/modules/lib/stdlibc/file.c
+++ b/src/modules/lib/stdlibc/file.c
@@ -84,11 +84,6 @@ FILE* fopen (const char* filename, const char* mode)
case 'd':
attr |= IO_OPEN_MODE_DIRECTORY;
break;
-
- case 'l':
- attr |= IO_OPEN_MODE_LINK;
- break;
-
}
}
--
1.6.0.2