Add getdirentries() and stat() for Mac OS X.
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).
This commit is contained in:
		
							parent
							
								
									b6b707d9df
								
							
						
					
					
						commit
						466bc555fe
					
				
					 15 changed files with 157 additions and 4 deletions
				
			
		|  | @ -9,7 +9,9 @@ local function addheader(h) | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| addheader("ack/config.h") | addheader("ack/config.h") | ||||||
|  | addheader("sys/dirent.h") | ||||||
| addheader("sys/mman.h") | addheader("sys/mman.h") | ||||||
|  | addheader("sys/stat.h") | ||||||
| addheader("sys/types.h") | addheader("sys/types.h") | ||||||
| addheader("unistd.h") | addheader("unistd.h") | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										17
									
								
								plat/osx/include/sys/dirent.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								plat/osx/include/sys/dirent.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
							
								
								
									
										49
									
								
								plat/osx/include/sys/stat.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								plat/osx/include/sys/stat.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
|  | @ -3,7 +3,15 @@ | ||||||
| 
 | 
 | ||||||
| #include <stddef.h> /* for off_t, ptrdiff_t, size_t */ | #include <stddef.h> /* for off_t, ptrdiff_t, size_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 int			pid_t; | ||||||
| typedef ptrdiff_t		ssize_t; | typedef ptrdiff_t		ssize_t; | ||||||
|  | typedef unsigned int		uid_t; | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | @ -22,6 +22,11 @@ int ioctl(int, unsigned long, ...); | ||||||
| typedef long _libsys_time_t; | typedef long _libsys_time_t; | ||||||
| typedef int suseconds_t; | typedef int suseconds_t; | ||||||
| 
 | 
 | ||||||
|  | struct timespec { | ||||||
|  | 	_libsys_time_t tv_sec; | ||||||
|  | 	long tv_nsec; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| struct timeval { | struct timeval { | ||||||
| 	_libsys_time_t tv_sec; | 	_libsys_time_t tv_sec; | ||||||
| 	suseconds_t tv_usec; | 	suseconds_t tv_usec; | ||||||
|  | @ -48,8 +53,6 @@ int gettimeofday(struct timeval *, struct timezone *); | ||||||
| #define O_TRUNC		0x0400 | #define O_TRUNC		0x0400 | ||||||
| #define O_EXCL		0x0800 | #define O_EXCL		0x0800 | ||||||
| 
 | 
 | ||||||
| typedef int mode_t; |  | ||||||
| 
 |  | ||||||
| int creat(const char *, mode_t); | int creat(const char *, mode_t); | ||||||
| int open(const char *, int, ...); | int open(const char *, int, ...); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,17 +3,21 @@ acklibrary { | ||||||
| 	srcs = { | 	srcs = { | ||||||
| 		"./_exit.s", | 		"./_exit.s", | ||||||
| 		"./close.s", | 		"./close.s", | ||||||
|  | 		"./fstat.s", | ||||||
|  | 		"./getdirentries.s", | ||||||
| 		"./getpid.s", | 		"./getpid.s", | ||||||
| 		"./gettimeofday.s", | 		"./gettimeofday.s", | ||||||
| 		"./ioctl.s", | 		"./ioctl.s", | ||||||
| 		"./kill.s", | 		"./kill.s", | ||||||
| 		"./lseek.s", | 		"./lseek.s", | ||||||
|  | 		"./lstat.s", | ||||||
| 		"./mmap.s", | 		"./mmap.s", | ||||||
| 		"./mprotect.s", | 		"./mprotect.s", | ||||||
| 		"./open.s", | 		"./open.s", | ||||||
| 		"./read.s", | 		"./read.s", | ||||||
| 		"./set_errno.s", | 		"./set_errno.s", | ||||||
| 		"./sigaction.s", | 		"./sigaction.s", | ||||||
|  | 		"./stat.s", | ||||||
| 		"./write.s", | 		"./write.s", | ||||||
| 		"plat/linux/libsys/errno.s", | 		"plat/linux/libsys/errno.s", | ||||||
| 		"plat/osx/libsys/brk.c", | 		"plat/osx/libsys/brk.c", | ||||||
|  |  | ||||||
							
								
								
									
										7
									
								
								plat/osx386/libsys/fstat.s
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								plat/osx386/libsys/fstat.s
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,7 @@ | ||||||
|  | .sect .text | ||||||
|  | .define _fstat
 | ||||||
|  | _fstat: | ||||||
|  | 	mov eax, 189 | ||||||
|  | 	int 0x80 | ||||||
|  | 	jb .set_errno | ||||||
|  | 	ret | ||||||
							
								
								
									
										7
									
								
								plat/osx386/libsys/getdirentries.s
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								plat/osx386/libsys/getdirentries.s
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,7 @@ | ||||||
|  | .sect .text | ||||||
|  | .define _getdirentries
 | ||||||
|  | _getdirentries: | ||||||
|  | 	mov eax, 196 | ||||||
|  | 	int 0x80 | ||||||
|  | 	jb .set_errno | ||||||
|  | 	ret | ||||||
							
								
								
									
										7
									
								
								plat/osx386/libsys/lstat.s
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								plat/osx386/libsys/lstat.s
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,7 @@ | ||||||
|  | .sect .text | ||||||
|  | .define _lstat
 | ||||||
|  | _lstat: | ||||||
|  | 	mov eax, 190 | ||||||
|  | 	int 0x80 | ||||||
|  | 	jb .set_errno | ||||||
|  | 	ret | ||||||
							
								
								
									
										7
									
								
								plat/osx386/libsys/stat.s
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								plat/osx386/libsys/stat.s
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,7 @@ | ||||||
|  | .sect .text | ||||||
|  | .define _stat
 | ||||||
|  | _stat: | ||||||
|  | 	mov eax, 188 | ||||||
|  | 	int 0x80 | ||||||
|  | 	jb .set_errno | ||||||
|  | 	ret | ||||||
|  | @ -3,17 +3,21 @@ acklibrary { | ||||||
| 	srcs = { | 	srcs = { | ||||||
| 		"./_exit.s", | 		"./_exit.s", | ||||||
| 		"./close.s", | 		"./close.s", | ||||||
|  | 		"./fstat.s", | ||||||
|  | 		"./getdirentries.s", | ||||||
| 		"./getpid.s", | 		"./getpid.s", | ||||||
| 		"./gettimeofday.s", | 		"./gettimeofday.s", | ||||||
| 		"./ioctl.s", | 		"./ioctl.s", | ||||||
| 		"./kill.s", | 		"./kill.s", | ||||||
| 		"./lseek.s", | 		"./lseek.s", | ||||||
|  | 		"./lstat.s", | ||||||
| 		"./mmap.s", | 		"./mmap.s", | ||||||
| 		"./mprotect.s", | 		"./mprotect.s", | ||||||
| 		"./open.s", | 		"./open.s", | ||||||
| 		"./read.s", | 		"./read.s", | ||||||
| 		"./set_errno.s", | 		"./set_errno.s", | ||||||
| 		"./sigaction.s", | 		"./sigaction.s", | ||||||
|  | 		"./stat.s", | ||||||
| 		"./write.s", | 		"./write.s", | ||||||
| 		"plat/linuxppc/libsys/trap.s", | 		"plat/linuxppc/libsys/trap.s", | ||||||
| 		"plat/osx/libsys/brk.c", | 		"plat/osx/libsys/brk.c", | ||||||
|  |  | ||||||
							
								
								
									
										9
									
								
								plat/osxppc/libsys/fstat.s
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								plat/osxppc/libsys/fstat.s
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
							
								
								
									
										11
									
								
								plat/osxppc/libsys/getdirentries.s
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								plat/osxppc/libsys/getdirentries.s
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
							
								
								
									
										9
									
								
								plat/osxppc/libsys/lstat.s
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								plat/osxppc/libsys/lstat.s
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
							
								
								
									
										9
									
								
								plat/osxppc/libsys/stat.s
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								plat/osxppc/libsys/stat.s
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue