OBJ = main.o unistd.o dirent.o stat.o utmpx.o termios.o\r
OBJ += pwd.o syslog.o sys_time.o sys_ioctl.o sys_resource.o\r
OBJ += fcntl.o clocks.o sys_wait.o unistd_crypt.o\r
-OBJ += grp.o pty.o\r
+OBJ += grp.o pty.o mktemp.o\r
DEPFILES := $(OBJ:%.o=%.d)\r
BIN = libposix.so\r
\r
#include "sys/stat.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#define NAME_MAX 255
struct dirent
extern void seekdir(DIR *, long int);
extern long int telldir(DIR *);
+#ifdef __cplusplus
+}
+#endif
+
#endif
--- /dev/null
+/*
+ * Acess2 POSIX Emulation
+ * - By John Hodge (thePowersGang)
+ *
+ * stdlib.h (libposix version)
+ * - Misc functions
+ *
+ * NOTE: Included by libc's stdlib.h
+ */
+#ifndef _LIBPOSIX__STDLIB_H_
+#define _LIBPOSIX__STDLIB_H_
+
+extern int mkstemp(char *_template);
+
+
+#endif
+
--- /dev/null
+/*
+ * Acess2 POSIX Emulation Layer
+ * - By John Hodge
+ *
+ * sys/mman.h
+ * - Memory Management (mmap and friends)
+ */
+#ifndef _LIBPOSIX__SYS_MMAN_H_
+#define _LIBPOSIX__SYS_MMAN_H_
+
+extern void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
+extern int munmap(void *addr, size_t length);
+
+
+#endif
+
#include <stdint.h>
#include "sys/types.h" // off_t
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef void *dev_t; /* TODO: How to identify a device with Acess */
typedef uint64_t ino_t;
typedef unsigned int blksize_t;
#define S_IFSOCK 0140000 /* socket */
#define S_IFIFO 0010000 /* fifo */
+#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
struct stat
{
extern int fstat(int fd, struct stat *buf);
extern int mkdir(const char *pathname, mode_t mode);
+#ifdef __cplusplus
+}
+#endif
+
#endif
#include <time.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef unsigned long suseconds_t;
struct timeval
// select
extern int utimes(const char *, const struct timeval [2]);
+#ifdef __cplusplus
+}
+#endif
+
#endif
#include <stddef.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
//! \brief flags for open(2)
#define O_WRONLY 0x01
#define O_RDONLY 0x02
#define S_IXOTH 00001
extern int chmod(const char *path, mode_t mode);
+extern int unlink(const char *pathname);
+
+extern int access(const char *pathname, int mode);
+
extern pid_t setsid(void);
extern uid_t getuid(void);
extern unsigned int sleep(unsigned int seconds);
extern int usleep(useconds_t usec);
+extern unsigned int alarm(unsigned int seconds);
// - crypt.c
extern char *crypt(const char *key, const char *salt);
#define PASS_MAX 63
extern char *getpass(const char *prompt);
+#if __cplusplus
+}
+#endif
+
#endif
--- /dev/null
+/*
+ * Acess2 POSIX Emulation Layer
+ * - By John Hodge
+ *
+ * utime.h
+ * -
+ */
+#ifndef _LIBPOSIX__UTIME_H_
+#define _LIBPOSIX__UTIME_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <sys/types.h> // time_t
+
+struct utimbuf {
+ time_t actime; // access time
+ time_t modtime; // modifcation time
+};
+
+extern int utime(const char *filename, const struct utimbuf *times);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
--- /dev/null
+/*
+ * Acess2 POSIX Emulation Layer
+ * - By John Hodge
+ *
+ * mkstemp.c
+ * - mkstemp/mktemp
+ */
+#include <unistd.h> // mktemp
+#include <stdlib.h> // mkstemp
+#include <string.h> // str*
+#include <errno.h>
+
+// === CODE ===
+int mkstemp(char *template)
+{
+ size_t tpl_len = strlen(template);
+ if( tpl_len < 6 ) {
+ errno = EINVAL;
+ return -1;
+ }
+ if( strcmp(template+tpl_len-6, "XXXXXX") != 0 ) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ for( int i = 0; i < 1000000; i ++ )
+ {
+ sprintf(template+tpl_len-6, "%06d", i);
+ int fd = open(template, O_EXCL|O_CREAT, 0600);
+ if(fd == -1) continue ;
+
+ return fd;
+ }
+
+ errno = EEXIST;
+ template[0] = '\0';
+ return -1;
+}
+
+char *mktemp(char *template)
+{
+ int fd = mkstemp(template);
+ if( fd == -1 )
+ return NULL;
+ close(fd);
+ return template;
+}
+
+
return 0;
}
+unsigned int alarm(unsigned int seconds)
+{
+ static int64_t alarm_time;
+ if( seconds > 0 )
+ {
+ alarm_time = _SysTimestamp() + seconds * 1000;
+ // TODO: Schedule SIGALRM
+ }
+ return (alarm_time - _SysTimestamp()) / 1000;
+}
+
int kill(pid_t pid, int signal)
{
// TODO: Need special handling?