LDFLAGS += -soname libposix.so -Map map.txt -lc\r
\r
OBJ = main.o unistd.o dirent.o stat.o utmpx.o termios.o\r
-OBJ += pwd.o\r
+OBJ += pwd.o syslog.o sys_time.o sys_ioctl.o sys_resource.o\r
DEPFILES := $(OBJ:%.o=%.d)\r
BIN = libposix.so\r
\r
rlim_t rlim_max;
};
+// (get|set)r(limit|usage) resource values
enum
{
RLIMIT_AS, // Address space size
};
extern int getpriority(int, id_t);
-extern int getrlimit(int, struct rlimit *);
-extern int getrusage(int, struct rusage *);
+extern int getrlimit(int resource, struct rlimit *rlim);
+extern int getrusage(int resource, struct rusage *rusage);
extern int setpriority(int, id_t, int);
-extern int setrlimit(int, const struct rlimit *);
+extern int setrlimit(int resource, const struct rlimit *rlim);
#endif
suseconds_t tv_usec;
};
+// struct timezone . tz_dsttime
+enum
+{
+ DST_NONE, // No DST
+ DST_USA, // USA style DST
+ DST_AUST, // Australian style DST
+ DST_WET, // Western European DST
+ DST_MET, // Middle European DST
+ DST_EET, // Eastern European DST
+ DST_CAN, // Canada
+ DST_GB, // Great Britain and Eire
+ DST_RUM, // Rumania
+ DST_TUR, // Turkey
+ DST_AUSTALT, // Australia with 1986 shift
+};
+
+struct timezone
+{
+ int tz_minuteswest;
+ int tz_dsttime;
+};
+
struct itimerval
{
struct timeval it_interval;
// TODO: This should also define fd_set and select()
-extern int getitimer(int, struct itimerval *);
-extern int setitimer(int, const struct itimerval *, struct itimerval *);
-extern int gettimeofday(struct timeval *, void *);
+extern int getitimer(int which, struct itimerval *current_value);
+extern int setitimer(int which, const struct itimerval *new_value, struct itimerval *old_value);
+extern int gettimeofday(struct timeval *tv, struct timezone *tz);
+// extern int settimeofday(const struct timeval *tv, const struct timezone *tz); //ifdef _BSD_SOURCE
// select
extern int utimes(const char *, const struct timeval [2]);
* - By John Hodge (thePowersGang)
*
* syslog.h
- * - Centra Loggin
+ * - Central Logging
*/
#ifndef _LIBPOSIX__SYSLOG_H_
#define _LIBPOSIX__SYSLOG_H_
#define S_IXOTH 00001
extern int chmod(const char *path, mode_t mode);
+extern pid_t setsid(void);
+
extern uid_t getuid(void);
extern uid_t geteuid(void);
extern pid_t getpid(void);
#define SIGTSTP 102
extern int kill(pid_t pid, int sig);
+extern int chdir(const char *dir);
+
+// Deprecated POSIX.1-2001
+#define PASS_MAX 63
+extern char *getpass(void);
#endif
--- /dev/null
+/*
+ * Acess2 POSIX Emulation
+ * - By John Hodge (thePowersGang)
+ *
+ * sys_ioctl.c
+ * - IOCtl hacks
+ */
+#include <sys/ioctl.h>
+#include <acess/sys.h>
+#include <errno.h>
+
+// === CODE ===
+int ioctl(int fd, int request, ...)
+{
+ if( fd < 0 ) {
+ errno = EBADF;
+ return -1;
+ }
+
+ if( request < 0 ) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ // #1. Get device type (IOCtl 0)
+ int devtype = _SysIOCtl(fd, 0, NULL);
+
+ switch(devtype)
+ {
+ // 0: Normal file (no ioctls we care about)
+ case 0:
+ // 1: Has the ident set of ioctls, nothing else
+ case 1:
+ return -1;
+ // TODO: Terminals
+
+ // NFI
+ default:
+ return -1;
+ }
+
+ return 0;
+}
+
+
--- /dev/null
+/*
+ * Acess2 POSIX Emulation
+ * - By John Hodge (thePowersGang)
+ *
+ * sys_resource.c
+ * - (XSI) Resource Operations
+ */
+#include <sys/resource.h>
+#include <acess/sys.h>
+
+// === CODE ===
+int getrlimit(int resource, struct rlimit *rlim)
+{
+ _SysDebug("TODO: getrlimit(%i)", resource);
+ rlim->rlim_cur = 0;
+ rlim->rlim_max = 0;
+ return 0;
+}
+
+int setrlimit(int resource, const struct rlimit *rlim)
+{
+ _SysDebug("TODO: setrlimit(%i,{%i,%i})", resource, rlim->rlim_cur, rlim->rlim_max);
+ return 0;
+}
+
--- /dev/null
+/*
+ * Acess2 POSIX Emulation
+ * - By John Hodge (thePowersGang)
+ *
+ * sys/time.h
+ * - Timing calls
+ */
+#include <sys/time.h>
+#include <acess/sys.h>
+
+// === CODE ===
+#if 0
+int getitimer(int which, struct itimerval *current_value)
+{
+
+}
+
+int setitimer(int which, const struct itimerval *new_value, struct itimerval *old_value)
+{
+
+}
+#endif
+
+int gettimeofday(struct timeval *tv, struct timezone *tz)
+{
+ const int correction_2k_to_unix = 30*365*24*3600;
+ long long int ts = _SysTimestamp();
+ if( tv )
+ {
+ tv->tv_sec = ts / 1000 + correction_2k_to_unix;
+ tv->tv_usec = (ts % 1000) * 1000;
+ }
+ if( tz )
+ {
+ // TODO: Determine timezone?
+ tz->tz_minuteswest = 0;
+ tz->tz_dsttime = 0;
+ }
+ return 0;
+}
+
+// ifdef _BSD_SOURCE
+//int settimeofday(const struct timeval *tv, const struct timezone *tz);
--- /dev/null
+/*
+ * Acess2 POSIX Emulation
+ * - By John Hodge (thePowersGang)
+ *
+ * syslog.h
+ * - Central Logging
+ */
+#include <syslog.h>
+#include <stdio.h> // vsnprintf
+#include <stdlib.h> // free
+#include <string.h> // strdup
+#include <stdarg.h>
+#include <acess/sys.h>
+
+// === GLOBALS ===
+char *gsSyslogPrefix = NULL;
+ int gSyslogOptions;
+ int gSyslogFacility;
+ int gSyslogMask = -1;
+
+// === CODE ===
+/*
+ * Close global logging handle
+ */
+void closelog(void)
+{
+}
+
+void openlog(const char *name, int option, int facility)
+{
+ if( gsSyslogPrefix )
+ free(gsSyslogPrefix);
+ gsSyslogPrefix = strdup(name);
+ gSyslogOptions = option;
+ gSyslogFacility = facility;
+
+ if( option & LOG_NOWAIT )
+ {
+ // Open the logging handle!
+ }
+}
+
+extern int setlogmask(int mask)
+{
+ int ret = gSyslogMask;
+ gSyslogMask = mask;
+ return ret;
+}
+
+extern void syslog(int priority, const char *str, ...)
+{
+ char staticbuf[512];
+ va_list args;
+ va_start(args, str);
+ vsnprintf(staticbuf, sizeof(staticbuf), str, args);
+ va_end(args);
+ if( gSyslogOptions & (1 << priority) )
+ {
+ // TODO: Proper syslog
+ _SysDebug("syslog(%i: %s) - %s", priority, gsSyslogPrefix, staticbuf);
+ }
+}
+
#include <acess/sys.h>
#include <stdarg.h>
#include <sys/select.h>
+#include <stdio.h>
// === CODE ===
int unlink(const char *pathname)
return _SysCopyFD(oldfd, newfd);
}
+
+/*
+ * Set session ID to PID
+ */
+pid_t setsid(void)
+{
+ // TODO: actual syscall for this
+ return _SysGetPID();
+}
+
pid_t getpid(void)
{
return _SysGetPID();
return _SysGetUID();
}
+uid_t geteuid(void)
+{
+ // TODO: Impliment EUIDs in-kernel?
+ return _SysGetUID();
+}
+
int kill(pid_t pid, int signal)
{
// TODO: Need special handling?
return 0;
}
+int chdir(const char *dir)
+{
+ return _SysChdir(dir);
+}
+
+int mkdir(const char *pathname, mode_t mode)
+{
+ _SysDebug("TODO: POSIX mkdir(%i, 0%o)", pathname, mode);
+ return -1;
+}
+
+char *getpass(void)
+{
+ static char passbuf[PASS_MAX+1];
+ fprintf(stderr, "Password: ");
+ fgets(passbuf, PASS_MAX+1, stdin);
+ fprintf(stderr, "\n");
+ return passbuf;
+}
+
return 0;
}
+int shutdown(int socket, int how)
+{
+ return 0;
+}
+