libc.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. #pragma lib "libc.a"
  2. #pragma src "/sys/src/libc"
  3. #define nelem(x) (sizeof(x)/sizeof((x)[0]))
  4. #define offsetof(s, m) (ulong)(&(((s*)0)->m))
  5. #define assert(x) if(x){}else _assert("x")
  6. /*
  7. * mem routines
  8. */
  9. extern void* memccpy(void*, void*, int, ulong);
  10. extern void* memset(void*, int, ulong);
  11. extern int memcmp(void*, void*, ulong);
  12. extern void* memcpy(void*, void*, ulong);
  13. extern void* memmove(void*, void*, ulong);
  14. extern void* memchr(void*, int, ulong);
  15. /*
  16. * string routines
  17. */
  18. extern char* strcat(char*, char*);
  19. extern char* strchr(char*, int);
  20. extern int strcmp(char*, char*);
  21. extern char* strcpy(char*, char*);
  22. extern char* strecpy(char*, char*, char*);
  23. extern char* strdup(char*);
  24. extern char* strncat(char*, char*, long);
  25. extern char* strncpy(char*, char*, long);
  26. extern int strncmp(char*, char*, long);
  27. extern char* strpbrk(char*, char*);
  28. extern char* strrchr(char*, int);
  29. extern char* strtok(char*, char*);
  30. extern long strlen(char*);
  31. extern long strspn(char*, char*);
  32. extern long strcspn(char*, char*);
  33. extern char* strstr(char*, char*);
  34. extern int cistrncmp(char*, char*, int);
  35. extern int cistrcmp(char*, char*);
  36. extern char* cistrstr(char*, char*);
  37. extern int tokenize(char*, char**, int);
  38. enum
  39. {
  40. UTFmax = 3, /* maximum bytes per rune */
  41. Runesync = 0x80, /* cannot represent part of a UTF sequence (<) */
  42. Runeself = 0x80, /* rune and UTF sequences are the same (<) */
  43. Runeerror = 0x80, /* decoding error in UTF */
  44. };
  45. /*
  46. * rune routines
  47. */
  48. extern int runetochar(char*, Rune*);
  49. extern int chartorune(Rune*, char*);
  50. extern int runelen(long);
  51. extern int runenlen(Rune*, int);
  52. extern int fullrune(char*, int);
  53. extern int utflen(char*);
  54. extern int utfnlen(char*, long);
  55. extern char* utfrune(char*, long);
  56. extern char* utfrrune(char*, long);
  57. extern char* utfutf(char*, char*);
  58. extern char* utfecpy(char*, char*, char*);
  59. extern Rune* runestrcat(Rune*, Rune*);
  60. extern Rune* runestrchr(Rune*, Rune);
  61. extern int runestrcmp(Rune*, Rune*);
  62. extern Rune* runestrcpy(Rune*, Rune*);
  63. extern Rune* runestrncpy(Rune*, Rune*, long);
  64. extern Rune* runestrecpy(Rune*, Rune*, Rune*);
  65. extern Rune* runestrdup(Rune*);
  66. extern Rune* runestrncat(Rune*, Rune*, long);
  67. extern int runestrncmp(Rune*, Rune*, long);
  68. extern Rune* runestrrchr(Rune*, Rune);
  69. extern long runestrlen(Rune*);
  70. extern Rune* runestrstr(Rune*, Rune*);
  71. extern Rune tolowerrune(Rune);
  72. extern Rune totitlerune(Rune);
  73. extern Rune toupperrune(Rune);
  74. extern int isalpharune(Rune);
  75. extern int islowerrune(Rune);
  76. extern int isspacerune(Rune);
  77. extern int istitlerune(Rune);
  78. extern int isupperrune(Rune);
  79. /*
  80. * malloc
  81. */
  82. extern void* malloc(ulong);
  83. extern void* mallocz(ulong, int);
  84. extern void free(void*);
  85. extern ulong msize(void*);
  86. extern void* calloc(ulong, ulong);
  87. extern void* realloc(void*, ulong);
  88. extern void setmalloctag(void*, ulong);
  89. extern void setrealloctag(void*, ulong);
  90. extern ulong getmalloctag(void*);
  91. extern ulong getrealloctag(void*);
  92. extern void* malloctopoolblock(void*);
  93. /*
  94. * print routines
  95. */
  96. typedef struct Fmt Fmt;
  97. struct Fmt{
  98. uchar runes; /* output buffer is runes or chars? */
  99. void *start; /* of buffer */
  100. void *to; /* current place in the buffer */
  101. void *stop; /* end of the buffer; overwritten if flush fails */
  102. int (*flush)(Fmt *); /* called when to == stop */
  103. void *farg; /* to make flush a closure */
  104. int nfmt; /* num chars formatted so far */
  105. va_list args; /* args passed to dofmt */
  106. int r; /* % format Rune */
  107. int width;
  108. int prec;
  109. ulong flags;
  110. };
  111. enum{
  112. FmtWidth = 1,
  113. FmtLeft = FmtWidth << 1,
  114. FmtPrec = FmtLeft << 1,
  115. FmtSharp = FmtPrec << 1,
  116. FmtSpace = FmtSharp << 1,
  117. FmtSign = FmtSpace << 1,
  118. FmtZero = FmtSign << 1,
  119. FmtUnsigned = FmtZero << 1,
  120. FmtShort = FmtUnsigned << 1,
  121. FmtLong = FmtShort << 1,
  122. FmtVLong = FmtLong << 1,
  123. FmtComma = FmtVLong << 1,
  124. FmtByte = FmtComma << 1,
  125. FmtFlag = FmtByte << 1
  126. };
  127. extern int print(char*, ...);
  128. extern char* seprint(char*, char*, char*, ...);
  129. extern char* vseprint(char*, char*, char*, va_list);
  130. extern int snprint(char*, int, char*, ...);
  131. extern int vsnprint(char*, int, char*, va_list);
  132. extern char* smprint(char*, ...);
  133. extern char* vsmprint(char*, va_list);
  134. extern int sprint(char*, char*, ...);
  135. extern int fprint(int, char*, ...);
  136. extern int vfprint(int, char*, va_list);
  137. extern int runesprint(Rune*, char*, ...);
  138. extern int runesnprint(Rune*, int, char*, ...);
  139. extern int runevsnprint(Rune*, int, char*, va_list);
  140. extern Rune* runeseprint(Rune*, Rune*, char*, ...);
  141. extern Rune* runevseprint(Rune*, Rune*, char*, va_list);
  142. extern Rune* runesmprint(char*, ...);
  143. extern Rune* runevsmprint(char*, va_list);
  144. extern int fmtfdinit(Fmt*, int, char*, int);
  145. extern int fmtfdflush(Fmt*);
  146. extern int fmtstrinit(Fmt*);
  147. extern char* fmtstrflush(Fmt*);
  148. extern int runefmtstrinit(Fmt*);
  149. extern Rune* runefmtstrflush(Fmt*);
  150. #pragma varargck argpos fmtprint 2
  151. #pragma varargck argpos fprint 2
  152. #pragma varargck argpos print 1
  153. #pragma varargck argpos runeseprint 3
  154. #pragma varargck argpos runesmprint 1
  155. #pragma varargck argpos runesnprint 3
  156. #pragma varargck argpos runesprint 2
  157. #pragma varargck argpos seprint 3
  158. #pragma varargck argpos smprint 1
  159. #pragma varargck argpos snprint 3
  160. #pragma varargck argpos sprint 2
  161. #pragma varargck type "lld" vlong
  162. #pragma varargck type "llx" vlong
  163. #pragma varargck type "lld" uvlong
  164. #pragma varargck type "llx" uvlong
  165. #pragma varargck type "ld" long
  166. #pragma varargck type "lx" long
  167. #pragma varargck type "ld" ulong
  168. #pragma varargck type "lx" ulong
  169. #pragma varargck type "d" int
  170. #pragma varargck type "x" int
  171. #pragma varargck type "c" int
  172. #pragma varargck type "C" int
  173. #pragma varargck type "d" uint
  174. #pragma varargck type "x" uint
  175. #pragma varargck type "c" uint
  176. #pragma varargck type "C" uint
  177. #pragma varargck type "f" double
  178. #pragma varargck type "e" double
  179. #pragma varargck type "g" double
  180. #pragma varargck type "s" char*
  181. #pragma varargck type "q" char*
  182. #pragma varargck type "S" Rune*
  183. #pragma varargck type "Q" Rune*
  184. #pragma varargck type "r" void
  185. #pragma varargck type "%" void
  186. #pragma varargck type "n" int*
  187. #pragma varargck type "p" void*
  188. #pragma varargck flag ','
  189. #pragma varargck type "<" void*
  190. #pragma varargck type "[" void*
  191. #pragma varargck type "H" void*
  192. extern int fmtinstall(int, int (*)(Fmt*));
  193. extern int dofmt(Fmt*, char*);
  194. extern int dorfmt(Fmt*, Rune*);
  195. extern int fmtprint(Fmt*, char*, ...);
  196. extern int fmtvprint(Fmt*, char*, va_list);
  197. extern int fmtrune(Fmt*, int);
  198. extern int fmtstrcpy(Fmt*, char*);
  199. extern int fmtrunestrcpy(Fmt*, Rune*);
  200. /*
  201. * error string for %r
  202. * supplied on per os basis, not part of fmt library
  203. */
  204. extern int errfmt(Fmt *f);
  205. /*
  206. * quoted strings
  207. */
  208. extern char *unquotestrdup(char*);
  209. extern Rune *unquoterunestrdup(Rune*);
  210. extern char *quotestrdup(char*);
  211. extern Rune *quoterunestrdup(Rune*);
  212. extern int quotestrfmt(Fmt*);
  213. extern int quoterunestrfmt(Fmt*);
  214. extern void quotefmtinstall(void);
  215. extern int (*doquote)(int);
  216. extern int needsrcquote(int);
  217. /*
  218. * random number
  219. */
  220. extern void srand(long);
  221. extern int rand(void);
  222. extern int nrand(int);
  223. extern long lrand(void);
  224. extern long lnrand(long);
  225. extern double frand(void);
  226. extern ulong truerand(void); /* uses /dev/random */
  227. extern ulong ntruerand(ulong); /* uses /dev/random */
  228. /*
  229. * math
  230. */
  231. extern ulong getfcr(void);
  232. extern void setfsr(ulong);
  233. extern ulong getfsr(void);
  234. extern void setfcr(ulong);
  235. extern double NaN(void);
  236. extern double Inf(int);
  237. extern int isNaN(double);
  238. extern int isInf(double, int);
  239. extern ulong umuldiv(ulong, ulong, ulong);
  240. extern long muldiv(long, long, long);
  241. extern double pow(double, double);
  242. extern double atan2(double, double);
  243. extern double fabs(double);
  244. extern double atan(double);
  245. extern double log(double);
  246. extern double log10(double);
  247. extern double exp(double);
  248. extern double floor(double);
  249. extern double ceil(double);
  250. extern double hypot(double, double);
  251. extern double sin(double);
  252. extern double cos(double);
  253. extern double tan(double);
  254. extern double asin(double);
  255. extern double acos(double);
  256. extern double sinh(double);
  257. extern double cosh(double);
  258. extern double tanh(double);
  259. extern double sqrt(double);
  260. extern double fmod(double, double);
  261. #define HUGE 3.4028234e38
  262. #define PIO2 1.570796326794896619231e0
  263. #define PI (PIO2+PIO2)
  264. /*
  265. * Time-of-day
  266. */
  267. typedef
  268. struct Tm
  269. {
  270. int sec;
  271. int min;
  272. int hour;
  273. int mday;
  274. int mon;
  275. int year;
  276. int wday;
  277. int yday;
  278. char zone[4];
  279. int tzoff;
  280. } Tm;
  281. extern Tm* gmtime(long);
  282. extern Tm* localtime(long);
  283. extern char* asctime(Tm*);
  284. extern char* ctime(long);
  285. extern double cputime(void);
  286. extern long times(long*);
  287. extern long tm2sec(Tm*);
  288. extern vlong nsec(void);
  289. /*
  290. * one-of-a-kind
  291. */
  292. enum
  293. {
  294. PNPROC = 1,
  295. PNGROUP = 2,
  296. };
  297. extern void _assert(char*);
  298. extern int abs(int);
  299. extern int atexit(void(*)(void));
  300. extern void atexitdont(void(*)(void));
  301. extern int atnotify(int(*)(void*, char*), int);
  302. extern double atof(char*);
  303. extern int atoi(char*);
  304. extern long atol(char*);
  305. extern vlong atoll(char*);
  306. extern double charstod(int(*)(void*), void*);
  307. extern char* cleanname(char*);
  308. extern int decrypt(void*, void*, int);
  309. extern int encrypt(void*, void*, int);
  310. extern int dec64(uchar*, int, char*, int);
  311. extern int enc64(char*, int, uchar*, int);
  312. extern int dec32(uchar*, int, char*, int);
  313. extern int enc32(char*, int, uchar*, int);
  314. extern int dec16(uchar*, int, char*, int);
  315. extern int enc16(char*, int, uchar*, int);
  316. extern int encodefmt(Fmt*);
  317. extern void exits(char*);
  318. extern double frexp(double, int*);
  319. extern ulong getcallerpc(void*);
  320. extern char* getenv(char*);
  321. extern int getfields(char*, char**, int, int, char*);
  322. extern int gettokens(char *, char **, int, char *);
  323. extern char* getuser(void);
  324. extern char* getwd(char*, int);
  325. extern int iounit(int);
  326. extern long labs(long);
  327. extern double ldexp(double, int);
  328. extern void longjmp(jmp_buf, int);
  329. extern char* mktemp(char*);
  330. extern double modf(double, double*);
  331. extern int netcrypt(void*, void*);
  332. extern void notejmp(void*, jmp_buf, int);
  333. extern void perror(char*);
  334. extern int postnote(int, int, char *);
  335. extern double pow10(int);
  336. extern int putenv(char*, char*);
  337. extern void qsort(void*, long, long, int (*)(void*, void*));
  338. extern int setjmp(jmp_buf);
  339. extern double strtod(char*, char**);
  340. extern long strtol(char*, char**, int);
  341. extern ulong strtoul(char*, char**, int);
  342. extern vlong strtoll(char*, char**, int);
  343. extern uvlong strtoull(char*, char**, int);
  344. extern void sysfatal(char*, ...);
  345. #pragma varargck argpos sysfatal 1
  346. extern void syslog(int, char*, char*, ...);
  347. #pragma varargck argpos syslog 3
  348. extern long time(long*);
  349. extern int tolower(int);
  350. extern int toupper(int);
  351. /*
  352. * synchronization
  353. */
  354. typedef
  355. struct Lock {
  356. int val;
  357. } Lock;
  358. extern int _tas(int*);
  359. extern void lock(Lock*);
  360. extern void unlock(Lock*);
  361. extern int canlock(Lock*);
  362. typedef struct QLp QLp;
  363. struct QLp
  364. {
  365. int inuse;
  366. QLp *next;
  367. char state;
  368. };
  369. typedef
  370. struct QLock
  371. {
  372. Lock lock;
  373. int locked;
  374. QLp *head;
  375. QLp *tail;
  376. } QLock;
  377. extern void qlock(QLock*);
  378. extern void qunlock(QLock*);
  379. extern int canqlock(QLock*);
  380. extern void _qlockinit(ulong (*)(ulong, ulong)); /* called only by the thread library */
  381. typedef
  382. struct RWLock
  383. {
  384. Lock lock;
  385. int readers; /* number of readers */
  386. int writer; /* number of writers */
  387. QLp *head; /* list of waiting processes */
  388. QLp *tail;
  389. } RWLock;
  390. extern void rlock(RWLock*);
  391. extern void runlock(RWLock*);
  392. extern int canrlock(RWLock*);
  393. extern void wlock(RWLock*);
  394. extern void wunlock(RWLock*);
  395. extern int canwlock(RWLock*);
  396. typedef
  397. struct Rendez
  398. {
  399. QLock *l;
  400. QLp *head;
  401. QLp *tail;
  402. } Rendez;
  403. extern void rsleep(Rendez*); /* unlocks r->l, sleeps, locks r->l again */
  404. extern int rwakeup(Rendez*);
  405. extern int rwakeupall(Rendez*);
  406. extern void** privalloc(void);
  407. extern void privfree(void**);
  408. /*
  409. * network dialing
  410. */
  411. #define NETPATHLEN 40
  412. extern int accept(int, char*);
  413. extern int announce(char*, char*);
  414. extern int dial(char*, char*, char*, int*);
  415. extern void setnetmtpt(char*, int, char*);
  416. extern int hangup(int);
  417. extern int listen(char*, char*);
  418. extern char* netmkaddr(char*, char*, char*);
  419. extern int reject(int, char*, char*);
  420. /*
  421. * encryption
  422. */
  423. extern int pushssl(int, char*, char*, char*, int*);
  424. extern int pushtls(int, char*, char*, int, char*, char*);
  425. /*
  426. * network services
  427. */
  428. typedef struct NetConnInfo NetConnInfo;
  429. struct NetConnInfo
  430. {
  431. char *dir; /* connection directory */
  432. char *root; /* network root */
  433. char *spec; /* binding spec */
  434. char *lsys; /* local system */
  435. char *lserv; /* local service */
  436. char *rsys; /* remote system */
  437. char *rserv; /* remote service */
  438. };
  439. extern NetConnInfo* getnetconninfo(char*, int);
  440. extern void freenetconninfo(NetConnInfo*);
  441. /*
  442. * system calls
  443. *
  444. */
  445. #define STATMAX 65535U /* max length of machine-independent stat structure */
  446. #define DIRMAX (sizeof(Dir)+STATMAX) /* max length of Dir structure */
  447. #define ERRMAX 128 /* max length of error string */
  448. #define MORDER 0x0003 /* mask for bits defining order of mounting */
  449. #define MREPL 0x0000 /* mount replaces object */
  450. #define MBEFORE 0x0001 /* mount goes before others in union directory */
  451. #define MAFTER 0x0002 /* mount goes after others in union directory */
  452. #define MCREATE 0x0004 /* permit creation in mounted directory */
  453. #define MCACHE 0x0010 /* cache some data */
  454. #define MMASK 0x0017 /* all bits on */
  455. #define OREAD 0 /* open for read */
  456. #define OWRITE 1 /* write */
  457. #define ORDWR 2 /* read and write */
  458. #define OEXEC 3 /* execute, == read but check execute permission */
  459. #define OTRUNC 16 /* or'ed in (except for exec), truncate file first */
  460. #define OCEXEC 32 /* or'ed in, close on exec */
  461. #define ORCLOSE 64 /* or'ed in, remove on close */
  462. #define OEXCL 0x1000 /* or'ed in, exclusive use (create only) */
  463. #define AEXIST 0 /* accessible: exists */
  464. #define AEXEC 1 /* execute access */
  465. #define AWRITE 2 /* write access */
  466. #define AREAD 4 /* read access */
  467. /* Segattch */
  468. #define SG_RONLY 0040 /* read only */
  469. #define SG_CEXEC 0100 /* detach on exec */
  470. #define NCONT 0 /* continue after note */
  471. #define NDFLT 1 /* terminate after note */
  472. #define NSAVE 2 /* clear note but hold state */
  473. #define NRSTR 3 /* restore saved state */
  474. /* bits in Qid.type */
  475. #define QTDIR 0x80 /* type bit for directories */
  476. #define QTAPPEND 0x40 /* type bit for append only files */
  477. #define QTEXCL 0x20 /* type bit for exclusive use files */
  478. #define QTMOUNT 0x10 /* type bit for mounted channel */
  479. #define QTAUTH 0x08 /* type bit for authentication file */
  480. #define QTFILE 0x00 /* plain file */
  481. /* bits in Dir.mode */
  482. #define DMDIR 0x80000000 /* mode bit for directories */
  483. #define DMAPPEND 0x40000000 /* mode bit for append only files */
  484. #define DMEXCL 0x20000000 /* mode bit for exclusive use files */
  485. #define DMMOUNT 0x10000000 /* mode bit for mounted channel */
  486. #define DMAUTH 0x08000000 /* mode bit for authentication file */
  487. #define DMREAD 0x4 /* mode bit for read permission */
  488. #define DMWRITE 0x2 /* mode bit for write permission */
  489. #define DMEXEC 0x1 /* mode bit for execute permission */
  490. /* rfork */
  491. enum
  492. {
  493. RFNAMEG = (1<<0),
  494. RFENVG = (1<<1),
  495. RFFDG = (1<<2),
  496. RFNOTEG = (1<<3),
  497. RFPROC = (1<<4),
  498. RFMEM = (1<<5),
  499. RFNOWAIT = (1<<6),
  500. RFCNAMEG = (1<<10),
  501. RFCENVG = (1<<11),
  502. RFCFDG = (1<<12),
  503. RFREND = (1<<13),
  504. RFNOMNT = (1<<14)
  505. };
  506. typedef
  507. struct Qid
  508. {
  509. uvlong path;
  510. ulong vers;
  511. uchar type;
  512. } Qid;
  513. typedef
  514. struct Dir {
  515. /* system-modified data */
  516. ushort type; /* server type */
  517. uint dev; /* server subtype */
  518. /* file data */
  519. Qid qid; /* unique id from server */
  520. ulong mode; /* permissions */
  521. ulong atime; /* last read time */
  522. ulong mtime; /* last write time */
  523. vlong length; /* file length */
  524. char *name; /* last element of path */
  525. char *uid; /* owner name */
  526. char *gid; /* group name */
  527. char *muid; /* last modifier name */
  528. } Dir;
  529. /* keep /sys/src/ape/lib/ap/plan9/sys9.h in sync with this -rsc */
  530. typedef
  531. struct Waitmsg
  532. {
  533. int pid; /* of loved one */
  534. ulong time[3]; /* of loved one & descendants */
  535. char *msg;
  536. } Waitmsg;
  537. typedef
  538. struct IOchunk
  539. {
  540. void *addr;
  541. ulong len;
  542. } IOchunk;
  543. extern void _exits(char*);
  544. extern void abort(void);
  545. extern int access(char*, int);
  546. extern long alarm(ulong);
  547. extern int await(char*, int);
  548. extern int bind(char*, char*, int);
  549. extern int brk(void*);
  550. extern int chdir(char*);
  551. extern int close(int);
  552. extern int create(char*, int, ulong);
  553. extern int dup(int, int);
  554. extern int errstr(char*, uint);
  555. extern int exec(char*, char*[]);
  556. extern int execl(char*, ...);
  557. extern int fork(void);
  558. extern int rfork(int);
  559. extern int fauth(int, char*);
  560. extern int fstat(int, uchar*, int);
  561. extern int fwstat(int, uchar*, int);
  562. extern int fversion(int, int, char*, int);
  563. extern int mount(int, int, char*, int, char*);
  564. extern int unmount(char*, char*);
  565. extern int noted(int);
  566. extern int notify(void(*)(void*, char*));
  567. extern int open(char*, int);
  568. extern int fd2path(int, char*, int);
  569. extern int pipe(int*);
  570. extern long pread(int, void*, long, vlong);
  571. extern long preadv(int, IOchunk*, int, vlong);
  572. extern long pwrite(int, void*, long, vlong);
  573. extern long pwritev(int, IOchunk*, int, vlong);
  574. extern long read(int, void*, long);
  575. extern long readn(int, void*, long);
  576. extern long readv(int, IOchunk*, int);
  577. extern int remove(char*);
  578. extern void* sbrk(ulong);
  579. extern long oseek(int, long, int);
  580. extern vlong seek(int, vlong, int);
  581. extern long segattach(int, char*, void*, ulong);
  582. extern int segbrk(void*, void*);
  583. extern int segdetach(void*);
  584. extern int segflush(void*, ulong);
  585. extern int segfree(void*, ulong);
  586. extern int sleep(long);
  587. extern int stat(char*, uchar*, int);
  588. extern Waitmsg* wait(void);
  589. extern int waitpid(void);
  590. extern long write(int, void*, long);
  591. extern long writev(int, IOchunk*, int);
  592. extern int wstat(char*, uchar*, int);
  593. extern ulong rendezvous(ulong, ulong);
  594. extern Dir* dirstat(char*);
  595. extern Dir* dirfstat(int);
  596. extern int dirwstat(char*, Dir*);
  597. extern int dirfwstat(int, Dir*);
  598. extern long dirread(int, Dir**);
  599. extern void nulldir(Dir*);
  600. extern long dirreadall(int, Dir**);
  601. extern int getpid(void);
  602. extern int getppid(void);
  603. extern void rerrstr(char*, uint);
  604. extern char* sysname(void);
  605. extern void werrstr(char*, ...);
  606. #pragma varargck argpos werrstr 1
  607. extern char *argv0;
  608. #define ARGBEGIN for((argv0||(argv0=*argv)),argv++,argc--;\
  609. argv[0] && argv[0][0]=='-' && argv[0][1];\
  610. argc--, argv++) {\
  611. char *_args, *_argt;\
  612. Rune _argc;\
  613. _args = &argv[0][1];\
  614. if(_args[0]=='-' && _args[1]==0){\
  615. argc--; argv++; break;\
  616. }\
  617. _argc = 0;\
  618. while(*_args && (_args += chartorune(&_argc, _args)))\
  619. switch(_argc)
  620. #define ARGEND SET(_argt);USED(_argt,_argc,_args);}USED(argv, argc);
  621. #define ARGF() (_argt=_args, _args="",\
  622. (*_argt? _argt: argv[1]? (argc--, *++argv): 0))
  623. #define EARGF(x) (_argt=_args, _args="",\
  624. (*_argt? _argt: argv[1]? (argc--, *++argv): ((x), abort(), (char*)0)))
  625. #define ARGC() _argc
  626. /* this is used by sbrk and brk, it's a really bad idea to redefine it */
  627. extern char end[];