libc.h 19 KB

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