summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2008-06-12 13:26:16 -0700
committerRob Pike <r@golang.org>2008-06-12 13:26:16 -0700
commitc348f82e29356fc95dcb6331b4860b2d76fa07aa (patch)
treef571b5448e5f72870de933c01d9a6dcf04879e85 /include
parent4732d2a3518bda35334461950464d2dffcd008b2 (diff)
downloadgo-c348f82e29356fc95dcb6331b4860b2d76fa07aa.tar.gz
import the plan 9 libraries libc (lib9) and libbio into the tree.
remove the dependency on /home/r. SVN=122482
Diffstat (limited to 'include')
-rw-r--r--include/bio.h117
-rw-r--r--include/fmt.h116
-rw-r--r--include/libc.h364
-rw-r--r--include/u.h208
4 files changed, 805 insertions, 0 deletions
diff --git a/include/bio.h b/include/bio.h
new file mode 100644
index 000000000..a56e320e0
--- /dev/null
+++ b/include/bio.h
@@ -0,0 +1,117 @@
+/*
+http://code.google.com/p/inferno-os/source/browse/include/bio.h
+
+ Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
+ Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef _BIO_H_
+#define _BIO_H_ 1
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#ifdef AUTOLIB
+AUTOLIB(bio)
+#endif
+
+#include <sys/types.h> /* for off_t */
+#include <fcntl.h> /* for O_RDONLY, O_WRONLY */
+
+typedef struct Biobuf Biobuf;
+
+enum
+{
+ Bsize = 8*1024,
+ Bungetsize = 4, /* space for ungetc */
+ Bmagic = 0x314159,
+ Beof = -1,
+ Bbad = -2,
+
+ Binactive = 0, /* states */
+ Bractive,
+ Bwactive,
+ Bracteof,
+
+ Bend
+};
+
+struct Biobuf
+{
+ int icount; /* neg num of bytes at eob */
+ int ocount; /* num of bytes at bob */
+ int rdline; /* num of bytes after rdline */
+ int runesize; /* num of bytes of last getrune */
+ int state; /* r/w/inactive */
+ int fid; /* open file */
+ int flag; /* magic if malloc'ed */
+ off_t offset; /* offset of buffer in file */
+ int bsize; /* size of buffer */
+ unsigned char* bbuf; /* pointer to beginning of buffer */
+ unsigned char* ebuf; /* pointer to end of buffer */
+ unsigned char* gbuf; /* pointer to good data in buf */
+ unsigned char b[Bungetsize+Bsize];
+};
+
+#define BGETC(bp)\
+ ((bp)->icount?(bp)->bbuf[(bp)->bsize+(bp)->icount++]:Bgetc((bp)))
+#define BPUTC(bp,c)\
+ ((bp)->ocount?(bp)->bbuf[(bp)->bsize+(bp)->ocount++]=(c),0:Bputc((bp),(c)))
+#define BOFFSET(bp)\
+ (((bp)->state==Bractive)?\
+ (bp)->offset + (bp)->icount:\
+ (((bp)->state==Bwactive)?\
+ (bp)->offset + ((bp)->bsize + (bp)->ocount):\
+ -1))
+#define BLINELEN(bp)\
+ (bp)->rdline
+#define BFILDES(bp)\
+ (bp)->fid
+
+int Bbuffered(Biobuf*);
+Biobuf* Bfdopen(int, int);
+int Bfildes(Biobuf*);
+int Bflush(Biobuf*);
+int Bgetc(Biobuf*);
+int Bgetd(Biobuf*, double*);
+long Bgetrune(Biobuf*);
+int Binit(Biobuf*, int, int);
+int Binits(Biobuf*, int, int, unsigned char*, int);
+int Blinelen(Biobuf*);
+off_t Boffset(Biobuf*);
+Biobuf* Bopen(char*, int);
+int Bprint(Biobuf*, char*, ...);
+int Bputc(Biobuf*, int);
+int Bputrune(Biobuf*, long);
+void* Brdline(Biobuf*, int);
+char* Brdstr(Biobuf*, int, int);
+long Bread(Biobuf*, void*, long);
+off_t Bseek(Biobuf*, off_t, int);
+int Bterm(Biobuf*);
+int Bungetc(Biobuf*);
+int Bungetrune(Biobuf*);
+long Bwrite(Biobuf*, void*, long);
+int Bvprint(Biobuf*, char*, va_list);
+
+#if defined(__cplusplus)
+}
+#endif
+#endif
diff --git a/include/fmt.h b/include/fmt.h
new file mode 100644
index 000000000..480ccad58
--- /dev/null
+++ b/include/fmt.h
@@ -0,0 +1,116 @@
+#ifndef _FMT_H_
+#define _FMT_H_ 1
+#if defined(__cplusplus)
+extern "C" {
+#endif
+/*
+ * The authors of this software are Rob Pike and Ken Thompson.
+ * Copyright (c) 2002 by Lucent Technologies.
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose without fee is hereby granted, provided that this entire notice
+ * is included in all copies of any software which is or includes a copy
+ * or modification of this software and in all copies of the supporting
+ * documentation for such software.
+ * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY
+ * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
+ * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
+ */
+
+#include <stdarg.h>
+#include <utf.h>
+
+typedef struct Fmt Fmt;
+struct Fmt{
+ unsigned char runes; /* output buffer is runes or chars? */
+ void *start; /* of buffer */
+ void *to; /* current place in the buffer */
+ void *stop; /* end of the buffer; overwritten if flush fails */
+ int (*flush)(Fmt *); /* called when to == stop */
+ void *farg; /* to make flush a closure */
+ int nfmt; /* num chars formatted so far */
+ va_list args; /* args passed to dofmt */
+ int r; /* % format Rune */
+ int width;
+ int prec;
+ unsigned long flags;
+ char *decimal; /* decimal point; cannot be "" */
+
+ /* For %'d */
+ char *thousands; /* separator for thousands */
+
+ /*
+ * Each char is an integer indicating #digits before next separator. Values:
+ * \xFF: no more grouping (or \x7F; defined to be CHAR_MAX in POSIX)
+ * \x00: repeat previous indefinitely
+ * \x**: count that many
+ */
+ char *grouping; /* descriptor of separator placement */
+};
+
+enum{
+ FmtWidth = 1,
+ FmtLeft = FmtWidth << 1,
+ FmtPrec = FmtLeft << 1,
+ FmtSharp = FmtPrec << 1,
+ FmtSpace = FmtSharp << 1,
+ FmtSign = FmtSpace << 1,
+ FmtApost = FmtSign << 1,
+ FmtZero = FmtApost << 1,
+ FmtUnsigned = FmtZero << 1,
+ FmtShort = FmtUnsigned << 1,
+ FmtLong = FmtShort << 1,
+ FmtVLong = FmtLong << 1,
+ FmtComma = FmtVLong << 1,
+ FmtByte = FmtComma << 1,
+ FmtLDouble = FmtByte << 1,
+
+ FmtFlag = FmtLDouble << 1
+};
+
+extern int (*fmtdoquote)(int);
+
+/* Edit .+1,/^$/ | cfn $PLAN9/src/lib9/fmt/?*.c | grep -v static |grep -v __ */
+int dofmt(Fmt *f, char *fmt);
+int dorfmt(Fmt *f, const Rune *fmt);
+double fmtcharstod(int(*f)(void*), void *vp);
+int fmtfdflush(Fmt *f);
+int fmtfdinit(Fmt *f, int fd, char *buf, int size);
+int fmtinstall(int c, int (*f)(Fmt*));
+int fmtnullinit(Fmt*);
+void fmtlocaleinit(Fmt*, char*, char*, char*);
+int fmtprint(Fmt *f, char *fmt, ...);
+int fmtrune(Fmt *f, int r);
+int fmtrunestrcpy(Fmt *f, Rune *s);
+int fmtstrcpy(Fmt *f, char *s);
+char* fmtstrflush(Fmt *f);
+int fmtstrinit(Fmt *f);
+double fmtstrtod(const char *as, char **aas);
+int fmtvprint(Fmt *f, char *fmt, va_list args);
+int fprint(int fd, char *fmt, ...);
+int print(char *fmt, ...);
+void quotefmtinstall(void);
+int quoterunestrfmt(Fmt *f);
+int quotestrfmt(Fmt *f);
+Rune* runefmtstrflush(Fmt *f);
+int runefmtstrinit(Fmt *f);
+Rune* runeseprint(Rune *buf, Rune *e, char *fmt, ...);
+Rune* runesmprint(char *fmt, ...);
+int runesnprint(Rune *buf, int len, char *fmt, ...);
+int runesprint(Rune *buf, char *fmt, ...);
+Rune* runevseprint(Rune *buf, Rune *e, char *fmt, va_list args);
+Rune* runevsmprint(char *fmt, va_list args);
+int runevsnprint(Rune *buf, int len, char *fmt, va_list args);
+char* seprint(char *buf, char *e, char *fmt, ...);
+char* smprint(char *fmt, ...);
+int snprint(char *buf, int len, char *fmt, ...);
+int sprint(char *buf, char *fmt, ...);
+int vfprint(int fd, char *fmt, va_list args);
+char* vseprint(char *buf, char *e, char *fmt, va_list args);
+char* vsmprint(char *fmt, va_list args);
+int vsnprint(char *buf, int len, char *fmt, va_list args);
+
+#if defined(__cplusplus)
+}
+#endif
+#endif
diff --git a/include/libc.h b/include/libc.h
new file mode 100644
index 000000000..2eceaea9c
--- /dev/null
+++ b/include/libc.h
@@ -0,0 +1,364 @@
+/*
+Derived from Inferno include/kern.h and
+Plan 9 from User Space include/libc.h
+
+http://code.google.com/p/inferno-os/source/browse/include/kern.h
+http://code.swtch.com/plan9port/src/tip/include/libc.h
+
+ Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
+ Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved.
+ Portions Copyright © 2001-2007 Russ Cox. All rights reserved.
+ Portions Copyright © 2009 The Go Authors. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+/*
+ * Lib9 is miscellany from the Plan 9 C library that doesn't
+ * fit into libutf or into libfmt, but is still missing from traditional
+ * Unix C libraries.
+ */
+#ifndef _LIBC_H_
+#define _LIBC_H_ 1
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#include <utf.h>
+#include <fmt.h>
+
+/*
+ * Begin trimmed down usual libc.h
+ */
+
+#ifndef nil
+#define nil ((void*)0)
+#endif
+#define nelem(x) (sizeof(x)/sizeof((x)[0]))
+
+#ifndef offsetof
+#define offsetof(s, m) (ulong)(&(((s*)0)->m))
+#endif
+
+extern char* strecpy(char*, char*, char*);
+extern int tokenize(char*, char**, int);
+
+extern double p9cputime(void);
+#ifndef NOPLAN9DEFINES
+#define cputime p9cputime
+#endif
+/*
+ * one-of-a-kind
+ */
+enum
+{
+ PNPROC = 1,
+ PNGROUP = 2
+};
+int isInf(double, int);
+
+extern int p9atoi(char*);
+extern long p9atol(char*);
+extern vlong p9atoll(char*);
+extern double fmtcharstod(int(*)(void*), void*);
+extern char* cleanname(char*);
+extern int exitcode(char*);
+extern void exits(char*);
+extern double frexp(double, int*);
+extern char* p9getenv(char*);
+extern int p9putenv(char*, char*);
+extern int getfields(char*, char**, int, int, char*);
+extern int gettokens(char *, char **, int, char *);
+extern char* getuser(void);
+extern char* p9getwd(char*, int);
+extern void p9longjmp(p9jmp_buf, int);
+extern char* mktemp(char*);
+extern int opentemp(char*);
+extern void p9notejmp(void*, p9jmp_buf, int);
+extern void perror(const char*);
+extern int postnote(int, int, char *);
+extern double p9pow10(int);
+extern char* searchpath(char*);
+#define p9setjmp(b) sigsetjmp((void*)(b), 1)
+
+extern void sysfatal(char*, ...);
+
+#ifndef NOPLAN9DEFINES
+#define atoi p9atoi
+#define atol p9atol
+#define atoll p9atoll
+#define getenv p9getenv
+#define getwd p9getwd
+#define longjmp p9longjmp
+#undef setjmp
+#define setjmp p9setjmp
+#define putenv p9putenv
+#define notejmp p9notejmp
+#define jmp_buf p9jmp_buf
+#define pow10 p9pow10
+#define strtod fmtstrtod
+#define charstod fmtcharstod
+#endif
+
+/*
+ * system calls
+ *
+ */
+#define STATMAX 65535U /* max length of machine-independent stat structure */
+#define DIRMAX (sizeof(Dir)+STATMAX) /* max length of Dir structure */
+#define ERRMAX 128 /* max length of error string */
+
+#define MORDER 0x0003 /* mask for bits defining order of mounting */
+#define MREPL 0x0000 /* mount replaces object */
+#define MBEFORE 0x0001 /* mount goes before others in union directory */
+#define MAFTER 0x0002 /* mount goes after others in union directory */
+#define MCREATE 0x0004 /* permit creation in mounted directory */
+#define MCACHE 0x0010 /* cache some data */
+#define MMASK 0x0017 /* all bits on */
+
+#define OREAD 0 /* open for read */
+#define OWRITE 1 /* write */
+#define ORDWR 2 /* read and write */
+#define OEXEC 3 /* execute, == read but check execute permission */
+#define OTRUNC 16 /* or'ed in (except for exec), truncate file first */
+#define OCEXEC 32 /* or'ed in, close on exec */
+#define ORCLOSE 64 /* or'ed in, remove on close */
+#define ODIRECT 128 /* or'ed in, direct access */
+#define ONONBLOCK 256 /* or'ed in, non-blocking call */
+#define OEXCL 0x1000 /* or'ed in, exclusive use (create only) */
+#define OLOCK 0x2000 /* or'ed in, lock after opening */
+#define OAPPEND 0x4000 /* or'ed in, append only */
+
+#define AEXIST 0 /* accessible: exists */
+#define AEXEC 1 /* execute access */
+#define AWRITE 2 /* write access */
+#define AREAD 4 /* read access */
+
+/* Segattch */
+#define SG_RONLY 0040 /* read only */
+#define SG_CEXEC 0100 /* detach on exec */
+
+#define NCONT 0 /* continue after note */
+#define NDFLT 1 /* terminate after note */
+#define NSAVE 2 /* clear note but hold state */
+#define NRSTR 3 /* restore saved state */
+
+/* bits in Qid.type */
+#define QTDIR 0x80 /* type bit for directories */
+#define QTAPPEND 0x40 /* type bit for append only files */
+#define QTEXCL 0x20 /* type bit for exclusive use files */
+#define QTMOUNT 0x10 /* type bit for mounted channel */
+#define QTAUTH 0x08 /* type bit for authentication file */
+#define QTTMP 0x04 /* type bit for non-backed-up file */
+#define QTSYMLINK 0x02 /* type bit for symbolic link */
+#define QTFILE 0x00 /* type bits for plain file */
+
+/* bits in Dir.mode */
+#define DMDIR 0x80000000 /* mode bit for directories */
+#define DMAPPEND 0x40000000 /* mode bit for append only files */
+#define DMEXCL 0x20000000 /* mode bit for exclusive use files */
+#define DMMOUNT 0x10000000 /* mode bit for mounted channel */
+#define DMAUTH 0x08000000 /* mode bit for authentication file */
+#define DMTMP 0x04000000 /* mode bit for non-backed-up file */
+#define DMSYMLINK 0x02000000 /* mode bit for symbolic link (Unix, 9P2000.u) */
+#define DMDEVICE 0x00800000 /* mode bit for device file (Unix, 9P2000.u) */
+#define DMNAMEDPIPE 0x00200000 /* mode bit for named pipe (Unix, 9P2000.u) */
+#define DMSOCKET 0x00100000 /* mode bit for socket (Unix, 9P2000.u) */
+#define DMSETUID 0x00080000 /* mode bit for setuid (Unix, 9P2000.u) */
+#define DMSETGID 0x00040000 /* mode bit for setgid (Unix, 9P2000.u) */
+
+#define DMREAD 0x4 /* mode bit for read permission */
+#define DMWRITE 0x2 /* mode bit for write permission */
+#define DMEXEC 0x1 /* mode bit for execute permission */
+
+#ifdef RFMEM /* FreeBSD, OpenBSD */
+#undef RFFDG
+#undef RFNOTEG
+#undef RFPROC
+#undef RFMEM
+#undef RFNOWAIT
+#undef RFCFDG
+#undef RFNAMEG
+#undef RFENVG
+#undef RFCENVG
+#undef RFCFDG
+#undef RFCNAMEG
+#endif
+
+enum
+{
+ RFNAMEG = (1<<0),
+ RFENVG = (1<<1),
+ RFFDG = (1<<2),
+ RFNOTEG = (1<<3),
+ RFPROC = (1<<4),
+ RFMEM = (1<<5),
+ RFNOWAIT = (1<<6),
+ RFCNAMEG = (1<<10),
+ RFCENVG = (1<<11),
+ RFCFDG = (1<<12)
+/* RFREND = (1<<13), */
+/* RFNOMNT = (1<<14) */
+};
+
+typedef
+struct Qid
+{
+ uvlong path;
+ ulong vers;
+ uchar type;
+} Qid;
+
+typedef
+struct Dir {
+ /* system-modified data */
+ ushort type; /* server type */
+ uint dev; /* server subtype */
+ /* file data */
+ Qid qid; /* unique id from server */
+ ulong mode; /* permissions */
+ ulong atime; /* last read time */
+ ulong mtime; /* last write time */
+ vlong length; /* file length */
+ char *name; /* last element of path */
+ char *uid; /* owner name */
+ char *gid; /* group name */
+ char *muid; /* last modifier name */
+
+ /* 9P2000.u extensions */
+ uint uidnum; /* numeric uid */
+ uint gidnum; /* numeric gid */
+ uint muidnum; /* numeric muid */
+ char *ext; /* extended info */
+} Dir;
+
+typedef
+struct Waitmsg
+{
+ int pid; /* of loved one */
+ ulong time[3]; /* of loved one & descendants */
+ char *msg;
+} Waitmsg;
+
+extern void _exits(char*);
+
+extern void abort(void);
+extern long p9alarm(ulong);
+extern int await(char*, int);
+extern int awaitfor(int, char*, int);
+extern int awaitnohang(char*, int);
+extern int p9chdir(char*);
+extern int close(int);
+extern int p9create(char*, int, ulong);
+extern int p9dup(int, int);
+extern int errstr(char*, uint);
+extern int p9exec(char*, char*[]);
+extern int p9execl(char*, ...);
+extern int p9rfork(int);
+extern int noted(int);
+extern int notify(void(*)(void*, char*));
+extern int noteenable(char*);
+extern int notedisable(char*);
+extern int notifyon(char*);
+extern int notifyoff(char*);
+extern int p9open(char*, int);
+extern int fd2path(int, char*, int);
+extern int p9pipe(int*);
+extern long readn(int, void*, long);
+extern int remove(const char*);
+extern vlong p9seek(int, vlong, int);
+extern int p9sleep(long);
+extern Waitmsg* p9wait(void);
+extern Waitmsg* p9waitfor(int);
+extern Waitmsg* waitnohang(void);
+extern int p9waitpid(void);
+extern ulong rendezvous(ulong, ulong);
+
+#ifndef NOPLAN9DEFINES
+#define alarm p9alarm
+#define dup p9dup
+#define exec p9exec
+#define execl p9execl
+#define seek p9seek
+#define sleep p9sleep
+#define wait p9wait
+#define waitpid p9waitpid
+#define rfork p9rfork
+#define create p9create
+#undef open
+#define open p9open
+#define pipe p9pipe
+#define waitfor p9waitfor
+#endif
+
+extern Dir* dirstat(char*);
+extern Dir* dirfstat(int);
+extern int dirwstat(char*, Dir*);
+extern int dirfwstat(int, Dir*);
+extern void nulldir(Dir*);
+extern long dirreadall(int, Dir**);
+extern void rerrstr(char*, uint);
+extern char* sysname(void);
+extern void werrstr(char*, ...);
+extern char* getns(void);
+extern char* get9root(void);
+extern char* unsharp(char*);
+
+/* external names that we don't want to step on */
+#ifndef NOPLAN9DEFINES
+#define main p9main
+#endif
+
+/* compiler directives on plan 9 */
+#define SET(x) ((x)=0)
+#define USED(x) if(x){}else{}
+#ifdef __GNUC__
+# if __GNUC__ >= 3
+# undef USED
+# define USED(x) ((void)(x))
+# endif
+#endif
+
+/* command line */
+extern char *argv0;
+extern void __fixargv0(void);
+#define ARGBEGIN for((argv0?0:(argv0=(__fixargv0(),*argv))),argv++,argc--;\
+ argv[0] && argv[0][0]=='-' && argv[0][1];\
+ argc--, argv++) {\
+ char *_args, *_argt;\
+ Rune _argc;\
+ _args = &argv[0][1];\
+ if(_args[0]=='-' && _args[1]==0){\
+ argc--; argv++; break;\
+ }\
+ _argc = 0;\
+ while(*_args && (_args += chartorune(&_argc, _args)))\
+ switch(_argc)
+#define ARGEND SET(_argt);USED(_argt);USED(_argc);USED(_args);}USED(argv);USED(argc);
+#define ARGF() (_argt=_args, _args="",\
+ (*_argt? _argt: argv[1]? (argc--, *++argv): 0))
+#define EARGF(x) (_argt=_args, _args="",\
+ (*_argt? _argt: argv[1]? (argc--, *++argv): ((x), abort(), (char*)0)))
+
+#define ARGC() _argc
+
+#if defined(__cplusplus)
+}
+#endif
+#endif /* _LIB9_H_ */
diff --git a/include/u.h b/include/u.h
new file mode 100644
index 000000000..9b7bccb1a
--- /dev/null
+++ b/include/u.h
@@ -0,0 +1,208 @@
+/*
+Plan 9 from User Space include/u.h
+http://code.swtch.com/plan9port/src/tip/include/u.h
+
+Copyright 2001-2007 Russ Cox. All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef _U_H_
+#define _U_H_ 1
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#define __BSD_VISIBLE 1 /* FreeBSD 5.x */
+#if defined(__sun__)
+# define __EXTENSIONS__ 1 /* SunOS */
+# if defined(__SunOS5_6__) || defined(__SunOS5_7__) || defined(__SunOS5_8__)
+ /* NOT USING #define __MAKECONTEXT_V2_SOURCE 1 / * SunOS */
+# else
+# define __MAKECONTEXT_V2_SOURCE 1
+# endif
+#endif
+#define _BSD_SOURCE 1
+#define _NETBSD_SOURCE 1 /* NetBSD */
+#define _SVID_SOURCE 1
+#if !defined(__APPLE__) && !defined(__OpenBSD__)
+# define _XOPEN_SOURCE 1000
+# define _XOPEN_SOURCE_EXTENDED 1
+#endif
+#if defined(__FreeBSD__)
+# include <sys/cdefs.h>
+ /* for strtoll */
+# undef __ISO_C_VISIBLE
+# define __ISO_C_VISIBLE 1999
+# undef __LONG_LONG_SUPPORTED
+# define __LONG_LONG_SUPPORTED
+#endif
+#define _LARGEFILE64_SOURCE 1
+#define _FILE_OFFSET_BITS 64
+
+#include <inttypes.h>
+
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <setjmp.h>
+#include <stddef.h>
+#include <math.h>
+#include <ctype.h> /* for tolower */
+
+/*
+ * OS-specific crap
+ */
+#define _NEEDUCHAR 1
+#define _NEEDUSHORT 1
+#define _NEEDUINT 1
+#define _NEEDULONG 1
+
+typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
+
+#if defined(__linux__)
+# include <sys/types.h>
+# if defined(__Linux26__)
+# include <pthread.h>
+# define PLAN9PORT_USING_PTHREADS 1
+# endif
+# if defined(__USE_MISC)
+# undef _NEEDUSHORT
+# undef _NEEDUINT
+# undef _NEEDULONG
+# endif
+#elif defined(__sun__)
+# include <sys/types.h>
+# include <pthread.h>
+# define PLAN9PORT_USING_PTHREADS 1
+# undef _NEEDUSHORT
+# undef _NEEDUINT
+# undef _NEEDULONG
+# define nil 0 /* no cast to void* */
+#elif defined(__FreeBSD__)
+# include <sys/types.h>
+# include <osreldate.h>
+# if __FreeBSD_version >= 500000
+# define PLAN9PORT_USING_PTHREADS 1
+# include <pthread.h>
+# endif
+# if !defined(_POSIX_SOURCE)
+# undef _NEEDUSHORT
+# undef _NEEDUINT
+# endif
+#elif defined(__APPLE__)
+# include <sys/types.h>
+# include <pthread.h>
+# define PLAN9PORT_USING_PTHREADS 1
+# if __GNUC__ < 4
+# undef _NEEDUSHORT
+# undef _NEEDUINT
+# endif
+# undef _ANSI_SOURCE
+# undef _POSIX_C_SOURCE
+# undef _XOPEN_SOURCE
+# if !defined(NSIG)
+# define NSIG 32
+# endif
+# define _NEEDLL 1
+#elif defined(__NetBSD__)
+# include <sched.h>
+# include <sys/types.h>
+# undef _NEEDUSHORT
+# undef _NEEDUINT
+# undef _NEEDULONG
+#elif defined(__OpenBSD__)
+# include <sys/types.h>
+# undef _NEEDUSHORT
+# undef _NEEDUINT
+# undef _NEEDULONG
+#else
+ /* No idea what system this is -- try some defaults */
+# include <pthread.h>
+# define PLAN9PORT_USING_PTHREADS 1
+#endif
+
+#ifndef O_DIRECT
+#define O_DIRECT 0
+#endif
+
+typedef signed char schar;
+
+#ifdef _NEEDUCHAR
+ typedef unsigned char uchar;
+#endif
+#ifdef _NEEDUSHORT
+ typedef unsigned short ushort;
+#endif
+#ifdef _NEEDUINT
+ typedef unsigned int uint;
+#endif
+#ifdef _NEEDULONG
+ typedef unsigned long ulong;
+#endif
+typedef unsigned long long uvlong;
+typedef long long vlong;
+
+typedef uint64_t u64int;
+typedef int64_t s64int;
+typedef uint8_t u8int;
+typedef int8_t s8int;
+typedef uint16_t u16int;
+typedef int16_t s16int;
+typedef uintptr_t uintptr;
+typedef intptr_t intptr;
+typedef uint32_t u32int;
+typedef int32_t s32int;
+
+#undef _NEEDUCHAR
+#undef _NEEDUSHORT
+#undef _NEEDUINT
+#undef _NEEDULONG
+
+/*
+ * Funny-named symbols to tip off 9l to autolink.
+ */
+#define AUTOLIB(x) static int __p9l_autolib_ ## x = 1;
+#define AUTOFRAMEWORK(x) static int __p9l_autoframework_ ## x = 1;
+
+/*
+ * Gcc is too smart for its own good.
+ */
+#if defined(__GNUC__)
+# undef strcmp /* causes way too many warnings */
+# if __GNUC__ >= 4 || (__GNUC__==3 && !defined(__APPLE_CC__))
+# undef AUTOLIB
+# define AUTOLIB(x) int __p9l_autolib_ ## x __attribute__ ((weak));
+# undef AUTOFRAMEWORK
+# define AUTOFRAMEWORK(x) int __p9l_autoframework_ ## x __attribute__ ((weak));
+# else
+# undef AUTOLIB
+# define AUTOLIB(x) static int __p9l_autolib_ ## x __attribute__ ((unused));
+# undef AUTOFRAMEWORK
+# define AUTOFRAMEWORK(x) static int __p9l_autoframework_ ## x __attribute__ ((unused));
+# endif
+#endif
+
+#if defined(__cplusplus)
+}
+#endif
+#endif