libc.h (24860B)
1 /* 2 * Lib9 is miscellany from the Plan 9 C library that doesn't 3 * fit into libutf or into libfmt, but is still missing from traditional 4 * Unix C libraries. 5 */ 6 #ifndef _LIBC_H_ 7 #define _LIBC_H_ 1 8 #if defined(__cplusplus) 9 extern "C" { 10 #endif 11 12 #include <utf.h> 13 #include <fmt.h> 14 15 /* 16 * Begin usual libc.h 17 */ 18 19 #ifndef nil 20 #define nil ((void*)0) 21 #endif 22 #define nelem(x) (sizeof(x)/sizeof((x)[0])) 23 24 #ifndef offsetof 25 #define offsetof(s, m) (ulong)(&(((s*)0)->m)) 26 #endif 27 28 /* 29 * mem routines (provided by system <string.h>) 30 * 31 extern void* memccpy(void*, void*, int, ulong); 32 extern void* memset(void*, int, ulong); 33 extern int memcmp(void*, void*, ulong); 34 extern void* memcpy(void*, void*, ulong); 35 extern void* memmove(void*, void*, ulong); 36 extern void* memchr(void*, int, ulong); 37 */ 38 39 /* 40 * string routines (provided by system <string.h>) 41 * 42 extern char* strcat(char*, char*); 43 extern char* strchr(char*, int); 44 extern int strcmp(char*, char*); 45 extern char* strcpy(char*, char*); 46 */ 47 extern char* strecpy(char*, char*, char*); 48 extern char* p9strdup(char*); 49 /* 50 extern char* strncat(char*, char*, long); 51 extern char* strncpy(char*, char*, long); 52 extern int strncmp(char*, char*, long); 53 extern char* strpbrk(char*, char*); 54 extern char* strrchr(char*, int); 55 extern char* strtok(char*, char*); 56 extern long strlen(char*); 57 extern long strspn(char*, char*); 58 extern long strcspn(char*, char*); 59 extern char* strstr(char*, char*); 60 */ 61 extern int cistrncmp(char*, char*, int); 62 extern int cistrcmp(char*, char*); 63 extern char* cistrstr(char*, char*); 64 extern int tokenize(char*, char**, int); 65 66 /* 67 enum 68 { 69 UTFmax = 4, 70 Runesync = 0x80, 71 Runeself = 0x80, 72 Runeerror = 0xFFFD, 73 Runemax = 0x10FFFF, 74 }; 75 */ 76 77 /* 78 * rune routines (provided by <utf.h> 79 * 80 extern int runetochar(char*, Rune*); 81 extern int chartorune(Rune*, char*); 82 extern int runelen(long); 83 extern int runenlen(Rune*, int); 84 extern int fullrune(char*, int); 85 extern int utflen(char*); 86 extern int utfnlen(char*, long); 87 extern char* utfrune(char*, long); 88 extern char* utfrrune(char*, long); 89 extern char* utfutf(char*, char*); 90 extern char* utfecpy(char*, char*, char*); 91 92 extern Rune* runestrcat(Rune*, Rune*); 93 extern Rune* runestrchr(Rune*, Rune); 94 extern int runestrcmp(Rune*, Rune*); 95 extern Rune* runestrcpy(Rune*, Rune*); 96 extern Rune* runestrncpy(Rune*, Rune*, long); 97 extern Rune* runestrecpy(Rune*, Rune*, Rune*); 98 extern Rune* runestrdup(Rune*); 99 extern Rune* runestrncat(Rune*, Rune*, long); 100 extern int runestrncmp(Rune*, Rune*, long); 101 extern Rune* runestrrchr(Rune*, Rune); 102 extern long runestrlen(Rune*); 103 extern Rune* runestrstr(Rune*, Rune*); 104 105 extern Rune tolowerrune(Rune); 106 extern Rune totitlerune(Rune); 107 extern Rune toupperrune(Rune); 108 extern int isalpharune(Rune); 109 extern int islowerrune(Rune); 110 extern int isspacerune(Rune); 111 extern int istitlerune(Rune); 112 extern int isupperrune(Rune); 113 */ 114 115 /* 116 * malloc (provied by system <stdlib.h>) 117 * 118 extern void* malloc(ulong); 119 */ 120 extern void* p9malloc(ulong); 121 extern void* mallocz(ulong, int); 122 extern void p9free(void*); 123 extern void* p9calloc(ulong, ulong); 124 extern void* p9realloc(void*, ulong); 125 extern void setmalloctag(void*, ulong); 126 extern void setrealloctag(void*, ulong); 127 extern ulong getmalloctag(void*); 128 extern ulong getrealloctag(void*); 129 /* 130 extern void* malloctopoolblock(void*); 131 */ 132 #ifndef NOPLAN9DEFINES 133 #define malloc p9malloc 134 #define realloc p9realloc 135 #define calloc p9calloc 136 #define free p9free 137 #undef strdup 138 #define strdup p9strdup 139 #endif 140 141 /* 142 * print routines (provided by <fmt.h>) 143 * 144 typedef struct Fmt Fmt; 145 struct Fmt{ 146 uchar runes; 147 void *start; 148 void *to; 149 void *stop; 150 int (*flush)(Fmt *); 151 void *farg; 152 int nfmt; 153 va_list args; 154 int r; 155 int width; 156 int prec; 157 ulong flags; 158 }; 159 160 enum{ 161 FmtWidth = 1, 162 FmtLeft = FmtWidth << 1, 163 FmtPrec = FmtLeft << 1, 164 FmtSharp = FmtPrec << 1, 165 FmtSpace = FmtSharp << 1, 166 FmtSign = FmtSpace << 1, 167 FmtZero = FmtSign << 1, 168 FmtUnsigned = FmtZero << 1, 169 FmtShort = FmtUnsigned << 1, 170 FmtLong = FmtShort << 1, 171 FmtVLong = FmtLong << 1, 172 FmtComma = FmtVLong << 1, 173 FmtByte = FmtComma << 1, 174 175 FmtFlag = FmtByte << 1 176 }; 177 178 extern int print(char*, ...); 179 extern char* seprint(char*, char*, char*, ...); 180 extern char* vseprint(char*, char*, char*, va_list); 181 extern int snprint(char*, int, char*, ...); 182 extern int vsnprint(char*, int, char*, va_list); 183 extern char* smprint(char*, ...); 184 extern char* vsmprint(char*, va_list); 185 extern int sprint(char*, char*, ...); 186 extern int fprint(int, char*, ...); 187 extern int vfprint(int, char*, va_list); 188 189 extern int runesprint(Rune*, char*, ...); 190 extern int runesnprint(Rune*, int, char*, ...); 191 extern int runevsnprint(Rune*, int, char*, va_list); 192 extern Rune* runeseprint(Rune*, Rune*, char*, ...); 193 extern Rune* runevseprint(Rune*, Rune*, char*, va_list); 194 extern Rune* runesmprint(char*, ...); 195 extern Rune* runevsmprint(char*, va_list); 196 197 extern int fmtfdinit(Fmt*, int, char*, int); 198 extern int fmtfdflush(Fmt*); 199 extern int fmtstrinit(Fmt*); 200 extern char* fmtstrflush(Fmt*); 201 extern int runefmtstrinit(Fmt*); 202 extern Rune* runefmtstrflush(Fmt*); 203 204 extern int fmtinstall(int, int (*)(Fmt*)); 205 extern int dofmt(Fmt*, char*); 206 extern int dorfmt(Fmt*, Rune*); 207 extern int fmtprint(Fmt*, char*, ...); 208 extern int fmtvprint(Fmt*, char*, va_list); 209 extern int fmtrune(Fmt*, int); 210 extern int fmtstrcpy(Fmt*, char*); 211 extern int fmtrunestrcpy(Fmt*, Rune*); 212 */ 213 214 /* 215 * error string for %r 216 * supplied on per os basis, not part of fmt library 217 * 218 * (provided by lib9, but declared in fmt.h) 219 * 220 extern int errfmt(Fmt *f); 221 */ 222 223 /* 224 * quoted strings 225 */ 226 extern char *unquotestrdup(char*); 227 extern Rune *unquoterunestrdup(Rune*); 228 extern char *quotestrdup(char*); 229 extern Rune *quoterunestrdup(Rune*); 230 /* 231 * in fmt.h 232 * 233 extern void quotefmtinstall(void); 234 extern int quotestrfmt(Fmt*); 235 extern int quoterunestrfmt(Fmt*); 236 */ 237 #ifndef NOPLAN9DEFINES 238 #define doquote fmtdoquote 239 #endif 240 extern int needsrcquote(int); 241 242 /* 243 * random number 244 */ 245 extern void p9srand(long); 246 extern int p9rand(void); 247 248 extern int p9nrand(int); 249 extern long p9lrand(void); 250 extern long p9lnrand(long); 251 extern double p9frand(void); 252 extern ulong truerand(void); /* uses /dev/random */ 253 extern ulong ntruerand(ulong); /* uses /dev/random */ 254 255 #ifndef NOPLAN9DEFINES 256 #define srand p9srand 257 #define rand p9rand 258 #define nrand p9nrand 259 #define lrand p9lrand 260 #define lnrand p9lnrand 261 #define frand p9frand 262 #endif 263 264 /* 265 * math 266 */ 267 extern ulong getfcr(void); 268 extern void setfsr(ulong); 269 extern ulong getfsr(void); 270 extern void setfcr(ulong); 271 extern double NaN(void); 272 extern double Inf(int); 273 extern int isNaN(double); 274 extern int isInf(double, int); 275 extern ulong umuldiv(ulong, ulong, ulong); 276 extern long muldiv(long, long, long); 277 278 /* 279 * provided by math.h 280 * 281 extern double pow(double, double); 282 extern double atan2(double, double); 283 extern double fabs(double); 284 extern double atan(double); 285 extern double log(double); 286 extern double log10(double); 287 extern double exp(double); 288 extern double floor(double); 289 extern double ceil(double); 290 extern double hypot(double, double); 291 extern double sin(double); 292 extern double cos(double); 293 extern double tan(double); 294 extern double asin(double); 295 extern double acos(double); 296 extern double sinh(double); 297 extern double cosh(double); 298 extern double tanh(double); 299 extern double sqrt(double); 300 extern double fmod(double, double); 301 #define HUGE 3.4028234e38 302 #define PIO2 1.570796326794896619231e0 303 #define PI (PIO2+PIO2) 304 */ 305 #define PI M_PI 306 #define PIO2 M_PI_2 307 308 /* 309 * Time-of-day 310 */ 311 312 typedef 313 struct Tm 314 { 315 int sec; 316 int min; 317 int hour; 318 int mday; 319 int mon; 320 int year; 321 int wday; 322 int yday; 323 char zone[4]; 324 int tzoff; 325 } Tm; 326 327 extern Tm* p9gmtime(long); 328 extern Tm* p9localtime(long); 329 extern char* p9asctime(Tm*); 330 extern char* p9ctime(long); 331 extern double p9cputime(void); 332 extern long p9times(long*); 333 extern long p9tm2sec(Tm*); 334 extern vlong p9nsec(void); 335 336 #ifndef NOPLAN9DEFINES 337 /* Clear some declarations to avoid conflicts in edge situation. 338 * uClibc based systems have this issue. 339 */ 340 #undef gmtime 341 #undef localtime 342 #undef asctime 343 #undef ctime 344 #define gmtime p9gmtime 345 #define localtime p9localtime 346 #define asctime p9asctime 347 #define ctime p9ctime 348 #define cputime p9cputime 349 #define times p9times 350 #define tm2sec p9tm2sec 351 #define nsec p9nsec 352 #endif 353 354 /* 355 * one-of-a-kind 356 */ 357 enum 358 { 359 PNPROC = 1, 360 PNGROUP = 2 361 }; 362 363 /* extern int abs(int); <stdlib.h> */ 364 extern int p9atexit(void(*)(void)); 365 extern void p9atexitdont(void(*)(void)); 366 extern int atnotify(int(*)(void*, char*), int); 367 /* 368 * <stdlib.h> 369 extern double atof(char*); <stdlib.h> 370 */ 371 extern int p9atoi(char*); 372 extern long p9atol(char*); 373 extern vlong p9atoll(char*); 374 extern double fmtcharstod(int(*)(void*), void*); 375 extern char* cleanname(char*); 376 extern int p9decrypt(void*, void*, int); 377 extern int p9encrypt(void*, void*, int); 378 extern int netcrypt(void*, void*); 379 extern int dec64(uchar*, int, char*, int); 380 extern int enc64(char*, int, uchar*, int); 381 extern int dec32(uchar*, int, char*, int); 382 extern int enc32(char*, int, uchar*, int); 383 extern int dec16(uchar*, int, char*, int); 384 extern int enc16(char*, int, uchar*, int); 385 extern int encodefmt(Fmt*); 386 extern int dirmodefmt(Fmt*); 387 extern int exitcode(char*); 388 extern void exits(char*); 389 extern double frexp(double, int*); 390 extern ulong getcallerpc(void*); 391 extern char* p9getenv(char*); 392 extern int p9putenv(char*, char*); 393 extern int getfields(char*, char**, int, int, char*); 394 extern int gettokens(char *, char **, int, char *); 395 extern char* getuser(void); 396 extern char* p9getwd(char*, int); 397 extern int iounit(int); 398 /* extern long labs(long); <math.h> */ 399 /* extern double ldexp(double, int); <math.h> */ 400 extern void p9longjmp(p9jmp_buf, int); 401 extern char* mktemp(char*); 402 extern int opentemp(char*, int); 403 /* extern double modf(double, double*); <math.h> */ 404 extern void p9notejmp(void*, p9jmp_buf, int); 405 extern void perror(const char*); 406 extern int postnote(int, int, char *); 407 extern double p9pow10(int); 408 /* extern int putenv(char*, char*); <stdlib.h. */ 409 /* extern void qsort(void*, long, long, int (*)(void*, void*)); <stdlib.h> */ 410 extern char* searchpath(char*); 411 /* extern int p9setjmp(p9jmp_buf); */ 412 #define p9setjmp(b) sigsetjmp((void*)(b), 1) 413 /* 414 * <stdlib.h> 415 extern long strtol(char*, char**, int); 416 extern ulong strtoul(char*, char**, int); 417 extern vlong strtoll(char*, char**, int); 418 extern uvlong strtoull(char*, char**, int); 419 */ 420 extern void sysfatal(char*, ...); 421 extern void p9syslog(int, char*, char*, ...); 422 extern long p9time(long*); 423 /* extern int tolower(int); <ctype.h> */ 424 /* extern int toupper(int); <ctype.h> */ 425 extern void needstack(int); 426 extern char* readcons(char*, char*, int); 427 428 extern void (*_pin)(void); 429 extern void (*_unpin)(void); 430 431 #ifndef NOPLAN9DEFINES 432 #define atexit p9atexit 433 #define atexitdont p9atexitdont 434 #define atoi p9atoi 435 #define atol p9atol 436 #define atoll p9atoll 437 #define encrypt p9encrypt 438 #define decrypt p9decrypt 439 #define getenv p9getenv 440 #define getwd p9getwd 441 #undef longjmp 442 #define longjmp p9longjmp 443 #undef setjmp 444 #define setjmp p9setjmp 445 #define putenv p9putenv 446 #define notejmp p9notejmp 447 #define jmp_buf p9jmp_buf 448 #define time p9time 449 #define pow10 p9pow10 450 #define strtod fmtstrtod 451 #define charstod fmtcharstod 452 #define syslog p9syslog 453 #endif 454 455 /* 456 * just enough information so that libc can be 457 * properly locked without dragging in all of libthread 458 */ 459 typedef struct _Thread _Thread; 460 typedef struct _Threadlist _Threadlist; 461 struct _Threadlist 462 { 463 _Thread *head; 464 _Thread *tail; 465 }; 466 467 extern _Thread *(*threadnow)(void); 468 469 /* 470 * synchronization 471 */ 472 typedef struct Lock Lock; 473 struct Lock 474 { 475 #ifdef PLAN9PORT_USING_PTHREADS 476 int init; 477 pthread_mutex_t mutex; 478 #endif 479 int held; 480 }; 481 482 extern void lock(Lock*); 483 extern void unlock(Lock*); 484 extern int canlock(Lock*); 485 extern int (*_lock)(Lock*, int, ulong); 486 extern void (*_unlock)(Lock*, ulong); 487 488 typedef struct QLock QLock; 489 struct QLock 490 { 491 Lock l; 492 _Thread *owner; 493 _Threadlist waiting; 494 }; 495 496 extern void qlock(QLock*); 497 extern void qunlock(QLock*); 498 extern int canqlock(QLock*); 499 extern int (*_qlock)(QLock*, int, ulong); /* do not use */ 500 extern void (*_qunlock)(QLock*, ulong); 501 502 typedef struct Rendez Rendez; 503 struct Rendez 504 { 505 QLock *l; 506 _Threadlist waiting; 507 }; 508 509 extern void rsleep(Rendez*); /* unlocks r->l, sleeps, locks r->l again */ 510 extern int rwakeup(Rendez*); 511 extern int rwakeupall(Rendez*); 512 extern void (*_rsleep)(Rendez*, ulong); /* do not use */ 513 extern int (*_rwakeup)(Rendez*, int, ulong); 514 515 typedef struct RWLock RWLock; 516 struct RWLock 517 { 518 Lock l; 519 int readers; 520 _Thread *writer; 521 _Threadlist rwaiting; 522 _Threadlist wwaiting; 523 }; 524 525 extern void rlock(RWLock*); 526 extern void runlock(RWLock*); 527 extern int canrlock(RWLock*); 528 extern void wlock(RWLock*); 529 extern void wunlock(RWLock*); 530 extern int canwlock(RWLock*); 531 extern int (*_rlock)(RWLock*, int, ulong); /* do not use */ 532 extern int (*_wlock)(RWLock*, int, ulong); 533 extern void (*_runlock)(RWLock*, ulong); 534 extern void (*_wunlock)(RWLock*, ulong); 535 536 /* 537 * per-process private data 538 */ 539 extern void** privalloc(void); 540 extern void privfree(void**); 541 542 /* 543 * network dialing 544 */ 545 #define NETPATHLEN 40 546 extern int p9accept(int, char*); 547 extern int p9announce(char*, char*); 548 extern int p9dial(char*, char*, char*, int*); 549 extern int p9dialparse(char *ds, char **net, char **unixa, u32int *ip, int *port); 550 extern void p9setnetmtpt(char*, int, char*); 551 extern int p9listen(char*, char*); 552 extern char* p9netmkaddr(char*, char*, char*); 553 extern int p9reject(int, char*, char*); 554 555 #ifndef NOPLAN9DEFINES 556 #define accept p9accept 557 #define announce p9announce 558 #define dial p9dial 559 #define setnetmtpt p9setnetmtpt 560 #define listen p9listen 561 #define netmkaddr p9netmkaddr 562 #define reject p9reject 563 #endif 564 565 /* 566 * encryption 567 */ 568 extern int pushssl(int, char*, char*, char*, int*); 569 extern int pushtls(int, char*, char*, int, char*, char*); 570 571 /* 572 * network services 573 */ 574 typedef struct NetConnInfo NetConnInfo; 575 struct NetConnInfo 576 { 577 char *dir; /* connection directory */ 578 char *root; /* network root */ 579 char *spec; /* binding spec */ 580 char *lsys; /* local system */ 581 char *lserv; /* local service */ 582 char *rsys; /* remote system */ 583 char *rserv; /* remote service */ 584 char *laddr; 585 char *raddr; 586 }; 587 extern NetConnInfo* getnetconninfo(char*, int); 588 extern void freenetconninfo(NetConnInfo*); 589 590 /* 591 * system calls 592 * 593 */ 594 #define STATMAX 65535U /* max length of machine-independent stat structure */ 595 #define DIRMAX (sizeof(Dir)+STATMAX) /* max length of Dir structure */ 596 #define ERRMAX 128 /* max length of error string */ 597 598 #define MORDER 0x0003 /* mask for bits defining order of mounting */ 599 #define MREPL 0x0000 /* mount replaces object */ 600 #define MBEFORE 0x0001 /* mount goes before others in union directory */ 601 #define MAFTER 0x0002 /* mount goes after others in union directory */ 602 #define MCREATE 0x0004 /* permit creation in mounted directory */ 603 #define MCACHE 0x0010 /* cache some data */ 604 #define MMASK 0x0017 /* all bits on */ 605 606 #define OREAD 0 /* open for read */ 607 #define OWRITE 1 /* write */ 608 #define ORDWR 2 /* read and write */ 609 #define OEXEC 3 /* execute, == read but check execute permission */ 610 #define OTRUNC 16 /* or'ed in (except for exec), truncate file first */ 611 #define OCEXEC 32 /* or'ed in, close on exec */ 612 #define ORCLOSE 64 /* or'ed in, remove on close */ 613 #define ODIRECT 128 /* or'ed in, direct access */ 614 #define ONONBLOCK 256 /* or'ed in, non-blocking call */ 615 #define OEXCL 0x1000 /* or'ed in, exclusive use (create only) */ 616 #define OLOCK 0x2000 /* or'ed in, lock after opening */ 617 #define OAPPEND 0x4000 /* or'ed in, append only */ 618 619 #define AEXIST 0 /* accessible: exists */ 620 #define AEXEC 1 /* execute access */ 621 #define AWRITE 2 /* write access */ 622 #define AREAD 4 /* read access */ 623 624 /* Segattch */ 625 #define SG_RONLY 0040 /* read only */ 626 #define SG_CEXEC 0100 /* detach on exec */ 627 628 #define NCONT 0 /* continue after note */ 629 #define NDFLT 1 /* terminate after note */ 630 #define NSAVE 2 /* clear note but hold state */ 631 #define NRSTR 3 /* restore saved state */ 632 633 /* bits in Qid.type */ 634 #define QTDIR 0x80 /* type bit for directories */ 635 #define QTAPPEND 0x40 /* type bit for append only files */ 636 #define QTEXCL 0x20 /* type bit for exclusive use files */ 637 #define QTMOUNT 0x10 /* type bit for mounted channel */ 638 #define QTAUTH 0x08 /* type bit for authentication file */ 639 #define QTTMP 0x04 /* type bit for non-backed-up file */ 640 #define QTSYMLINK 0x02 /* type bit for symbolic link */ 641 #define QTFILE 0x00 /* type bits for plain file */ 642 643 /* bits in Dir.mode */ 644 #define DMDIR 0x80000000 /* mode bit for directories */ 645 #define DMAPPEND 0x40000000 /* mode bit for append only files */ 646 #define DMEXCL 0x20000000 /* mode bit for exclusive use files */ 647 #define DMMOUNT 0x10000000 /* mode bit for mounted channel */ 648 #define DMAUTH 0x08000000 /* mode bit for authentication file */ 649 #define DMTMP 0x04000000 /* mode bit for non-backed-up file */ 650 #define DMSYMLINK 0x02000000 /* mode bit for symbolic link (Unix, 9P2000.u) */ 651 #define DMDEVICE 0x00800000 /* mode bit for device file (Unix, 9P2000.u) */ 652 #define DMNAMEDPIPE 0x00200000 /* mode bit for named pipe (Unix, 9P2000.u) */ 653 #define DMSOCKET 0x00100000 /* mode bit for socket (Unix, 9P2000.u) */ 654 #define DMSETUID 0x00080000 /* mode bit for setuid (Unix, 9P2000.u) */ 655 #define DMSETGID 0x00040000 /* mode bit for setgid (Unix, 9P2000.u) */ 656 657 #define DMREAD 0x4 /* mode bit for read permission */ 658 #define DMWRITE 0x2 /* mode bit for write permission */ 659 #define DMEXEC 0x1 /* mode bit for execute permission */ 660 661 #ifdef RFMEM /* FreeBSD, OpenBSD */ 662 #undef RFFDG 663 #undef RFNOTEG 664 #undef RFPROC 665 #undef RFMEM 666 #undef RFNOWAIT 667 #undef RFCFDG 668 #undef RFNAMEG 669 #undef RFENVG 670 #undef RFCENVG 671 #undef RFCFDG 672 #undef RFCNAMEG 673 #endif 674 675 enum 676 { 677 RFNAMEG = (1<<0), 678 RFENVG = (1<<1), 679 RFFDG = (1<<2), 680 RFNOTEG = (1<<3), 681 RFPROC = (1<<4), 682 RFMEM = (1<<5), 683 RFNOWAIT = (1<<6), 684 RFCNAMEG = (1<<10), 685 RFCENVG = (1<<11), 686 RFCFDG = (1<<12) 687 /* RFREND = (1<<13), */ 688 /* RFNOMNT = (1<<14) */ 689 }; 690 691 typedef 692 struct Qid 693 { 694 uvlong path; 695 ulong vers; 696 uchar type; 697 } Qid; 698 699 typedef 700 struct Dir { 701 /* system-modified data */ 702 ushort type; /* server type */ 703 uint dev; /* server subtype */ 704 /* file data */ 705 Qid qid; /* unique id from server */ 706 ulong mode; /* permissions */ 707 ulong atime; /* last read time */ 708 ulong mtime; /* last write time */ 709 vlong length; /* file length */ 710 char *name; /* last element of path */ 711 char *uid; /* owner name */ 712 char *gid; /* group name */ 713 char *muid; /* last modifier name */ 714 715 /* 9P2000.u extensions */ 716 uint uidnum; /* numeric uid */ 717 uint gidnum; /* numeric gid */ 718 uint muidnum; /* numeric muid */ 719 char *ext; /* extended info */ 720 } Dir; 721 722 /* keep /sys/src/ape/lib/ap/plan9/sys9.h in sync with this -rsc */ 723 typedef 724 struct Waitmsg 725 { 726 int pid; /* of loved one */ 727 ulong time[3]; /* of loved one & descendants */ 728 char *msg; 729 } Waitmsg; 730 731 typedef 732 struct IOchunk 733 { 734 void *addr; 735 ulong len; 736 } IOchunk; 737 738 extern void _exits(char*); 739 740 extern void abort(void); 741 /* extern int access(char*, int); */ 742 extern long p9alarm(ulong); 743 extern int await(char*, int); 744 extern int awaitfor(int, char*, int); 745 extern int awaitnohang(char*, int); 746 /* extern int bind(char*, char*, int); give up */ 747 /* extern int brk(void*); <unistd.h> */ 748 extern int p9chdir(char*); 749 extern int close(int); 750 extern int p9create(char*, int, ulong); 751 extern int p9dup(int, int); 752 extern int errstr(char*, uint); 753 extern int p9exec(char*, char*[]); 754 extern int p9execl(char*, ...); 755 /* extern int p9fork(void); */ 756 extern int p9rfork(int); 757 /* not implemented 758 extern int fauth(int, char*); 759 extern int fstat(int, uchar*, int); 760 extern int fwstat(int, uchar*, int); 761 extern int fversion(int, int, char*, int); 762 extern int mount(int, int, char*, int, char*); 763 extern int unmount(char*, char*); 764 */ 765 extern int noted(int); 766 extern int notify(void(*)(void*, char*)); 767 extern int noteenable(char*); 768 extern int notedisable(char*); 769 extern int notifyon(char*); 770 extern int notifyoff(char*); 771 extern int p9open(char*, int); 772 extern int fd2path(int, char*, int); 773 extern int p9pipe(int*); 774 /* 775 * use defs from <unistd.h> 776 extern long pread(int, void*, long, vlong); 777 extern long preadv(int, IOchunk*, int, vlong); 778 extern long pwrite(int, void*, long, vlong); 779 extern long pwritev(int, IOchunk*, int, vlong); 780 extern long read(int, void*, long); 781 */ 782 extern long readn(int, void*, long); 783 /* extern long readv(int, IOchunk*, int); <unistd.h> */ 784 extern int remove(const char*); 785 /* extern long oseek(int, long, int); */ 786 extern vlong p9seek(int, vlong, int); 787 /* give up 788 extern long segattach(int, char*, void*, ulong); 789 extern int segbrk(void*, void*); 790 extern int segdetach(void*); 791 extern int segflush(void*, ulong); 792 extern int segfree(void*, ulong); 793 */ 794 extern int p9sleep(long); 795 /* extern int stat(char*, uchar*, int); give up */ 796 extern Waitmsg* p9wait(void); 797 extern Waitmsg* p9waitfor(int); 798 extern Waitmsg* waitnohang(void); 799 extern int p9waitpid(void); 800 /* <unistd.h> 801 extern long write(int, void*, long); 802 extern long writev(int, IOchunk*, int); 803 */ 804 extern long p9write(int, void*, long); 805 /* extern int wstat(char*, uchar*, int); give up */ 806 extern ulong rendezvous(ulong, ulong); 807 808 #ifndef NOPLAN9DEFINES 809 #define alarm p9alarm 810 #define dup p9dup 811 #define exec p9exec 812 #define execl p9execl 813 #define seek p9seek 814 #define sleep p9sleep 815 #define wait p9wait 816 #define waitpid p9waitpid 817 /* #define fork p9fork */ 818 #define rfork p9rfork 819 /* #define access p9access */ 820 #define create p9create 821 #undef open 822 #define open p9open 823 #define pipe p9pipe 824 #define waitfor p9waitfor 825 #define write p9write 826 #endif 827 828 extern Dir* dirstat(char*); 829 extern Dir* dirfstat(int); 830 extern int dirwstat(char*, Dir*); 831 extern int dirfwstat(int, Dir*); 832 extern long dirread(int, Dir**); 833 extern void nulldir(Dir*); 834 extern long dirreadall(int, Dir**); 835 /* extern int getpid(void); <unistd.h> */ 836 /* extern int getppid(void); */ 837 extern void rerrstr(char*, uint); 838 extern char* sysname(void); 839 extern void werrstr(char*, ...); 840 extern char* getns(void); 841 extern char* get9root(void); 842 extern char* unsharp(char*); 843 extern int sendfd(int, int); 844 extern int recvfd(int); 845 extern int post9pservice(int, char*, char*); 846 extern int chattyfuse; 847 848 /* external names that we don't want to step on */ 849 #ifndef NOPLAN9DEFINES 850 #define main p9main 851 #endif 852 853 #ifdef VARARGCK 854 #pragma varargck type "lld" vlong 855 #pragma varargck type "llx" vlong 856 #pragma varargck type "lld" uvlong 857 #pragma varargck type "llx" uvlong 858 #pragma varargck type "ld" long 859 #pragma varargck type "lx" long 860 #pragma varargck type "ld" ulong 861 #pragma varargck type "lx" ulong 862 #pragma varargck type "d" int 863 #pragma varargck type "x" int 864 #pragma varargck type "c" int 865 #pragma varargck type "C" int 866 #pragma varargck type "d" uint 867 #pragma varargck type "x" uint 868 #pragma varargck type "c" uint 869 #pragma varargck type "C" uint 870 #pragma varargck type "f" double 871 #pragma varargck type "e" double 872 #pragma varargck type "g" double 873 #pragma varargck type "lf" long double 874 #pragma varargck type "le" long double 875 #pragma varargck type "lg" long double 876 #pragma varargck type "s" char* 877 #pragma varargck type "q" char* 878 #pragma varargck type "S" Rune* 879 #pragma varargck type "Q" Rune* 880 #pragma varargck type "r" void 881 #pragma varargck type "%" void 882 #pragma varargck type "n" int* 883 #pragma varargck type "p" void* 884 #pragma varargck type "<" void* 885 #pragma varargck type "[" void* 886 #pragma varargck type "H" void* 887 #pragma varargck type "lH" void* 888 889 #pragma varargck flag ' ' 890 #pragma varargck flag '#' 891 #pragma varargck flag '+' 892 #pragma varargck flag ',' 893 #pragma varargck flag '-' 894 #pragma varargck flag 'u' 895 896 #pragma varargck argpos fmtprint 2 897 #pragma varargck argpos fprint 2 898 #pragma varargck argpos print 1 899 #pragma varargck argpos runeseprint 3 900 #pragma varargck argpos runesmprint 1 901 #pragma varargck argpos runesnprint 3 902 #pragma varargck argpos runesprint 2 903 #pragma varargck argpos seprint 3 904 #pragma varargck argpos smprint 1 905 #pragma varargck argpos snprint 3 906 #pragma varargck argpos sprint 2 907 #pragma varargck argpos sysfatal 1 908 #pragma varargck argpos p9syslog 3 909 #pragma varargck argpos werrstr 1 910 #endif 911 912 /* compiler directives on plan 9 */ 913 #define SET(x) ((x)=0) 914 #define USED(x) if(x){}else{} 915 #ifdef __GNUC__ 916 # if __GNUC__ >= 3 917 # undef USED 918 # define USED(x) ((void)(x)) 919 # endif 920 #endif 921 922 /* command line */ 923 extern char *argv0; 924 extern void __fixargv0(void); 925 #define ARGBEGIN for((argv0?0:(argv0=(__fixargv0(),*argv))),argv++,argc--;\ 926 argv[0] && argv[0][0]=='-' && argv[0][1];\ 927 argc--, argv++) {\ 928 char *_args, *_argt;\ 929 Rune _argc;\ 930 _args = &argv[0][1];\ 931 if(_args[0]=='-' && _args[1]==0){\ 932 argc--; argv++; break;\ 933 }\ 934 _argc = 0;\ 935 while(*_args && (_args += chartorune(&_argc, _args)))\ 936 switch(_argc) 937 #define ARGEND SET(_argt);USED(_argt);USED(_argc);USED(_args);}USED(argv);USED(argc); 938 #define ARGF() (_argt=_args, _args="",\ 939 (*_argt? _argt: argv[1]? (argc--, *++argv): 0)) 940 #define EARGF(x) (_argt=_args, _args="",\ 941 (*_argt? _argt: argv[1]? (argc--, *++argv): ((x), abort(), (char*)0))) 942 943 #define ARGC() _argc 944 945 #if defined(__cplusplus) 946 } 947 #endif 948 #endif /* _LIB9_H_ */