Add getdirentries() and stat() for Mac OS X.
authorGeorge Koehler <xkernigh@netscape.net>
Mon, 28 Nov 2016 19:32:49 +0000 (14:32 -0500)
committerGeorge Koehler <xkernigh@netscape.net>
Mon, 28 Nov 2016 19:32:49 +0000 (14:32 -0500)
Also add fstat() and lstat().  I don't #define the constants for
st_mode or d_type, but I provide enough to get the block size of a
file and to list the names in a directory.  Some fields of struct stat
get truncated, see XXX in plat/osx/include/sys/stat.h.

In struct dirent, the inode field might be d_ino or d_fileno.  I
picked d_ino because Apple's sys/dirent.h uses d_ino (but Apple's
manual pages use d_fileno).

15 files changed:
plat/osx/include/build.lua
plat/osx/include/sys/dirent.h [new file with mode: 0644]
plat/osx/include/sys/stat.h [new file with mode: 0644]
plat/osx/include/sys/types.h
plat/osx/include/unistd.h
plat/osx386/libsys/build.lua
plat/osx386/libsys/fstat.s [new file with mode: 0644]
plat/osx386/libsys/getdirentries.s [new file with mode: 0644]
plat/osx386/libsys/lstat.s [new file with mode: 0644]
plat/osx386/libsys/stat.s [new file with mode: 0644]
plat/osxppc/libsys/build.lua
plat/osxppc/libsys/fstat.s [new file with mode: 0644]
plat/osxppc/libsys/getdirentries.s [new file with mode: 0644]
plat/osxppc/libsys/lstat.s [new file with mode: 0644]
plat/osxppc/libsys/stat.s [new file with mode: 0644]

index 7eb73f3..ff7c87a 100644 (file)
@@ -9,7 +9,9 @@ local function addheader(h)
 end
 
 addheader("ack/config.h")
+addheader("sys/dirent.h")
 addheader("sys/mman.h")
+addheader("sys/stat.h")
 addheader("sys/types.h")
 addheader("unistd.h")
 
diff --git a/plat/osx/include/sys/dirent.h b/plat/osx/include/sys/dirent.h
new file mode 100644 (file)
index 0000000..073c845
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef _SYS_DIRENT_H
+#define _SYS_DIRENT_H
+
+#include <sys/types.h>
+
+struct dirent {
+       ino_t           d_ino;
+       unsigned short  d_reclen;
+       unsigned char   d_type;
+       unsigned char   d_namlen;
+#define MAXNAMLEN 255
+       char            d_name[MAXNAMLEN + 1];
+};
+
+int getdirentries(int, char *, int, long *);
+
+#endif
diff --git a/plat/osx/include/sys/stat.h b/plat/osx/include/sys/stat.h
new file mode 100644 (file)
index 0000000..6cb2490
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef _SYS_STAT_H
+#define _SYS_STAT_H
+
+#include <sys/types.h>
+#include <sys/time.h> /* for timespec */
+
+struct stat {
+       dev_t           st_dev;
+       ino_t           st_ino;
+       mode_t          st_mode;
+       nlink_t         st_nlink;
+       uid_t           st_uid;
+       gid_t           st_gid;
+       dev_t           st_rdev;
+       struct timespec st_atim;
+       struct timespec st_mtim;
+       struct timespec st_ctim;
+#define st_atime st_atim.tv_sec
+#define st_mtime st_mtim.tv_sec
+#define st_ctime st_ctim.tv_sec
+       /*
+        * XXX - We don't have 64-bit integers, so we only expose the
+        * lower 32 bits of 64-bit fields.  We insert dummy fields for
+        * the higher 32 bits.
+        */
+#if defined(__i386)
+       off_t           st_size;
+       off_t           _st_size_hi;
+       blkcnt_t        st_blocks;
+       blkcnt_t        _st_blkcnt_hi;
+#elif defined(__powerpc)
+       off_t           _st_size_hi;
+       off_t           st_size;
+       blkcnt_t        _st_blkcnt_hi;
+       blkcnt_t        st_blkcnt;
+#else
+#error unknown arch
+#endif
+       blksize_t       st_blksize;
+       unsigned int    st_flags;
+       unsigned int    st_gen;
+       unsigned int    _st_spare[5];
+};
+
+int fstat(int, struct stat *);
+int lstat(const char *, struct stat *);
+int stat(const char *, struct stat *);
+
+#endif
index a9fb632..b4561b7 100644 (file)
@@ -3,7 +3,15 @@
 
 #include <stddef.h> /* for off_t, ptrdiff_t, size_t */
 
-typedef int pid_t;
-typedef ptrdiff_t ssize_t;
+typedef int                    blkcnt_t; /* XXX should have 64 bits */
+typedef int                    blksize_t;
+typedef int                    dev_t;
+typedef unsigned int           gid_t;
+typedef unsigned int           ino_t;
+typedef unsigned short         mode_t;
+typedef unsigned short         nlink_t;
+typedef int                    pid_t;
+typedef ptrdiff_t              ssize_t;
+typedef unsigned int           uid_t;
 
 #endif
index 24eaf4e..320db4a 100644 (file)
@@ -22,6 +22,11 @@ int ioctl(int, unsigned long, ...);
 typedef long _libsys_time_t;
 typedef int suseconds_t;
 
+struct timespec {
+       _libsys_time_t tv_sec;
+       long tv_nsec;
+};
+
 struct timeval {
        _libsys_time_t tv_sec;
        suseconds_t tv_usec;
@@ -48,8 +53,6 @@ int gettimeofday(struct timeval *, struct timezone *);
 #define O_TRUNC                0x0400
 #define O_EXCL         0x0800
 
-typedef int mode_t;
-
 int creat(const char *, mode_t);
 int open(const char *, int, ...);
 
index a5356ee..b3a04c8 100644 (file)
@@ -3,17 +3,21 @@ acklibrary {
        srcs = {
                "./_exit.s",
                "./close.s",
+               "./fstat.s",
+               "./getdirentries.s",
                "./getpid.s",
                "./gettimeofday.s",
                "./ioctl.s",
                "./kill.s",
                "./lseek.s",
+               "./lstat.s",
                "./mmap.s",
                "./mprotect.s",
                "./open.s",
                "./read.s",
                "./set_errno.s",
                "./sigaction.s",
+               "./stat.s",
                "./write.s",
                "plat/linux/libsys/errno.s",
                "plat/osx/libsys/brk.c",
diff --git a/plat/osx386/libsys/fstat.s b/plat/osx386/libsys/fstat.s
new file mode 100644 (file)
index 0000000..1b49ae0
--- /dev/null
@@ -0,0 +1,7 @@
+.sect .text
+.define _fstat
+_fstat:
+       mov eax, 189
+       int 0x80
+       jb .set_errno
+       ret
diff --git a/plat/osx386/libsys/getdirentries.s b/plat/osx386/libsys/getdirentries.s
new file mode 100644 (file)
index 0000000..9c59c62
--- /dev/null
@@ -0,0 +1,7 @@
+.sect .text
+.define _getdirentries
+_getdirentries:
+       mov eax, 196
+       int 0x80
+       jb .set_errno
+       ret
diff --git a/plat/osx386/libsys/lstat.s b/plat/osx386/libsys/lstat.s
new file mode 100644 (file)
index 0000000..a492cc3
--- /dev/null
@@ -0,0 +1,7 @@
+.sect .text
+.define _lstat
+_lstat:
+       mov eax, 190
+       int 0x80
+       jb .set_errno
+       ret
diff --git a/plat/osx386/libsys/stat.s b/plat/osx386/libsys/stat.s
new file mode 100644 (file)
index 0000000..858d84d
--- /dev/null
@@ -0,0 +1,7 @@
+.sect .text
+.define _stat
+_stat:
+       mov eax, 188
+       int 0x80
+       jb .set_errno
+       ret
index a595ed0..2accf6e 100644 (file)
@@ -3,17 +3,21 @@ acklibrary {
        srcs = {
                "./_exit.s",
                "./close.s",
+               "./fstat.s",
+               "./getdirentries.s",
                "./getpid.s",
                "./gettimeofday.s",
                "./ioctl.s",
                "./kill.s",
                "./lseek.s",
+               "./lstat.s",
                "./mmap.s",
                "./mprotect.s",
                "./open.s",
                "./read.s",
                "./set_errno.s",
                "./sigaction.s",
+               "./stat.s",
                "./write.s",
                "plat/linuxppc/libsys/trap.s",
                "plat/osx/libsys/brk.c",
diff --git a/plat/osxppc/libsys/fstat.s b/plat/osxppc/libsys/fstat.s
new file mode 100644 (file)
index 0000000..d641cbd
--- /dev/null
@@ -0,0 +1,9 @@
+.sect .text
+.define _fstat
+_fstat:
+       addi r0, r0, 189        ! fstat
+       lwz r3, 0(sp)           ! fd
+       lwz r4, 4(sp)           ! stat pointer
+       sc 0
+       b .set_errno
+       bclr 20, 0, 0
diff --git a/plat/osxppc/libsys/getdirentries.s b/plat/osxppc/libsys/getdirentries.s
new file mode 100644 (file)
index 0000000..d038c59
--- /dev/null
@@ -0,0 +1,11 @@
+.sect .text
+.define _getdirentries
+_getdirentries:
+       addi r0, r0, 196        ! getdirentries
+       lwz r3, 0(sp)           ! fd
+       lwz r4, 4(sp)           ! buffer
+       lwz r5, 8(sp)           ! buffer size
+       lwz r6, 12(sp)          ! base pointer
+       sc 0
+       b .set_errno
+       bclr 20, 0, 0
diff --git a/plat/osxppc/libsys/lstat.s b/plat/osxppc/libsys/lstat.s
new file mode 100644 (file)
index 0000000..24d7c44
--- /dev/null
@@ -0,0 +1,9 @@
+.sect .text
+.define _lstat
+_lstat:
+       addi r0, r0, 190        ! lstat
+       lwz r3, 0(sp)           ! path
+       lwz r4, 4(sp)           ! stat pointer
+       sc 0
+       b .set_errno
+       bclr 20, 0, 0
diff --git a/plat/osxppc/libsys/stat.s b/plat/osxppc/libsys/stat.s
new file mode 100644 (file)
index 0000000..ab8422c
--- /dev/null
@@ -0,0 +1,9 @@
+.sect .text
+.define _stat
+_stat:
+       addi r0, r0, 188        ! stat
+       lwz r3, 0(sp)           ! path
+       lwz r4, 4(sp)           ! stat pointer
+       sc 0
+       b .set_errno
+       bclr 20, 0, 0