summaryrefslogtreecommitdiff
path: root/libpsx/src/libc/stat.c
diff options
context:
space:
mode:
Diffstat (limited to 'libpsx/src/libc/stat.c')
-rw-r--r--libpsx/src/libc/stat.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/libpsx/src/libc/stat.c b/libpsx/src/libc/stat.c
new file mode 100644
index 0000000..1c43b92
--- /dev/null
+++ b/libpsx/src/libc/stat.c
@@ -0,0 +1,31 @@
+#include <psx.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+
+int stat(const char *path, struct stat *sb)
+{
+ struct DIRENTRY dir_e;
+
+ if(firstfile((char*)path, &dir_e) == NULL)
+ return -1;
+
+ sb->st_size = dir_e.size;
+
+ if(strncmp(path, "cdrom:", 6) == 0)
+ sb->st_blksize = 2048;
+ else if(strncmp(path, "bu00:", 5) == 0 ||
+ strncmp(path, "bu10:", 5) == 0)
+ sb->st_blksize = 128;
+ else
+// not a real blocksize, will be there just as a placeholder
+ sb->st_blksize = 1024;
+
+ sb->st_blocks =
+ sb->st_size / sb->st_blksize;
+
+ if(sb->st_size % sb->st_blksize)
+ sb->st_blocks++;
+
+ return 0;
+}