From: Alan Cox Date: Sun, 28 Dec 2014 22:43:50 +0000 (+0000) Subject: sysconf/pathconf: Add pathconf, update sysconf X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=6590fddf2ef30003bfd8bfcdd2cc2e2f635d37ee;p=FUZIX.git sysconf/pathconf: Add pathconf, update sysconf Add load average interface Add pathconf interfaces, first cut --- diff --git a/Library/include/unistd.h b/Library/include/unistd.h index 0116954d..65cb3169 100644 --- a/Library/include/unistd.h +++ b/Library/include/unistd.h @@ -43,7 +43,10 @@ extern int pause __P((void)); extern int fork __P((void)); extern char *getcwd __P((char *, int)); -extern long sysconf(int name); +extern long sysconf __P((int name)); +extern long fpathconf __P((int fd, int name)); +extern long pathconf __P((const char *path, int name)); +extern long _pathconf __P((int name)); #define _SC_ARG_MAX 1 #define _SC_CHILD_MAX 2 @@ -67,6 +70,29 @@ extern long sysconf(int name); #define _SC_JOB_CONTROL 19 #define _SC_SAVED_IDS 20 +#define _SC_FUZIX_LOADAVG1 64 +#define _SC_FUZIX_LOADAVG5 65 +#define _SC_FUZIX_LOADAVG15 66 + +#define _PC_LINK_MAX 1 +#define _PC_MAX_CANON 2 +#define _PC_MAX_INPUT 3 +#define _PC_NAME_MAX 4 +#define _PC_PATH_MAX 5 +#define _PC_PIPE_BUF 6 +#define _PC_CHOWN_RESTRICTED 7 +#define _PC_NO_TRUNC 8 +#define _PC_VDISABLE 9 + +#define _POSIX_LINK_MAX _pathconf(_PC_LINK_MAX) +#define _POSIX_MAX_CANON _pathconf(_PC_MAX_CANON) +#define _POSIX_MAX_INPUT _pathconf(_PC_MAX_INPUT) +#define _POSIX_NAME_MAX _pathconf(_PC_NAME_MAX) +#define _POSIX_PATH_MAX _pathconf(_PC_PATH_MAX) +#define _POSIX_PIPE_BUF _pathconf(_PC_PIPE_BUF) +#define _POSIX_CHOWN_RESTRICTED _pathconf(_PC_CHOWN_RESTRICTED) +#define _POSIX_NO_TRUNC _pathconf(_PC_NO_TRUNC) + extern int gethostname(char *name, size_t len); extern int sethostname(const char *name, size_t len); @@ -86,15 +112,4 @@ extern void exit __P((int)); #define F_TLOCK 2 #define F_TEST 3 - -#define _PC_LINK_MAX 0 -#define _PC_MAX_CANON 1 -#define _PC_MAX_INPUT 2 -#define _PC_NAME_MAX 3 -#define _PC_PATH_MAX 4 -#define _PC_PIPE_BUF 5 -#define _PC_CHOWN_RESTRICTED 6 -#define _PC_NO_TRUNC 7 -#define _PC_VDISABLE 8 - #endif /* __UNISTD_H */ diff --git a/Library/libs/Makefile b/Library/libs/Makefile index fcf44a57..254e6ce7 100644 --- a/Library/libs/Makefile +++ b/Library/libs/Makefile @@ -30,7 +30,7 @@ SRC_C += strdup.c stricmp.c strncasecmp.c SRC_C += strnicmp.c strsep.c SRC_C += strtod.c strtol.c system.c time.c tmpnam.c ttyname.c SRC_C += tzset.c ungetc.c utent.c utsname.c -SRC_C += vfprintf.c vprintf.c wait.c xitoa.c +SRC_C += vfprintf.c vprintf.c wait.c xitoa.c pathconf.c SRC_C += gethostname.c sysconf.c confstr.c memccpy.c getpass.c # tty layer SRC_C += tcgetattr.c tcsetattr.c tcdrain.c tcflow.c tcflush.c diff --git a/Library/libs/pathconf.c b/Library/libs/pathconf.c new file mode 100644 index 00000000..1751b0cc --- /dev/null +++ b/Library/libs/pathconf.c @@ -0,0 +1,43 @@ +#include +#include + +long _pathconf(int name) +{ + struct _uzisysinfoblk info; + + _uname(&info, sizeof(info)); + + switch(name) { + case _PC_LINK_MAX: + return 65535; + case _PC_MAX_CANON: + case _PC_MAX_INPUT: + return 132; /* In theory must be 256+ .. */ + case _PC_NAME_MAX: + return 30; + case _PC_PATH_MAX: + return 512; + case _PC_PIPE_BUF: + return 4096; /* FIXME: wrong but need to sort socket + buffers out to know the right answers */ + case _PC_CHOWN_RESTRICTED: + return 1; + case _PC_NO_TRUNC: + return 0; + case _PC_VDISABLE: + return 1; + } + return -1; +} + +long pathconf(char *p, int name) +{ + p; + return _pathconf(name); +} + +long fpathconf(int fd, int name) +{ + fd; + return _pathconf(name); +} diff --git a/Library/libs/sysconf.c b/Library/libs/sysconf.c index 62a6d0d5..d502f78d 100644 --- a/Library/libs/sysconf.c +++ b/Library/libs/sysconf.c @@ -53,6 +53,12 @@ long sysconf(int name) case _SC_NPROCESSORS_CONF: case _SC_NPROCESSORS_ONLN: return 1; + case _SC_FUZIX_LOADAVG1: + return info.loadavg[0]; + case _SC_FUZIX_LOADAVG5: + return info.loadavg[1]; + case _SC_FUZIX_LOADAVG15: + return info.loadavg[2]; default: errno = EINVAL; return -1;