libc.h 20 KB

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