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

[tyndur-devel] [PATCH] POSIX: lstat() ein bisschen brauchbarer machen



+ POSIX: Damit tut lstat wenigstens schon mal was, wenn auch nicht genug ;-)

Signed-off-by: Antoine Kaufmann <toni@xxxxxxxxxx>
---
 src/modules/lib/posix/stat.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/modules/lib/posix/stat.c b/src/modules/lib/posix/stat.c
index 02b4f5d..56f6104 100644
--- a/src/modules/lib/posix/stat.c
+++ b/src/modules/lib/posix/stat.c
@@ -156,8 +156,18 @@ int stat(const char* filename, struct stat* stat_buf)
  */
 int lstat(const char* filename, struct stat* stat_buf)
 {
-    // TODO
-    return -1;
+    int result = stat(filename, stat_buf);
+    FILE* f;
+
+    if (!result && (f = fopen(filename, "lr"))) {
+        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_blocks = 1;
+        fclose(f);
+    }
+
+    return result;
 }
 
 /**
-- 
1.6.0.6