Loading

plan9port GNU Hurd

  1. diff --git a/bin/9c b/bin/9c
  2. index 3ffb716c..abf2eb31 100755
  3. --- a/bin/9c
  4. +++ b/bin/9c
  5. @@ -79,6 +79,7 @@ useclang()
  6.  
  7.  tag="${SYSNAME:-`uname`}-${OBJTYPE:-`uname -m`}-${CC9:-cc}"
  8.  case "$tag" in
  9. +*GNU*)  usegcc ;;
  10.  *FreeBSD*gcc*) usegcc ;;
  11.  *FreeBSD*clang*)   useclang ;;
  12.  *DragonFly*|*BSD*) usegcc ;;
  13. diff --git a/bin/9l b/bin/9l
  14. index 6195815f..4230c0f7 100755
  15. --- a/bin/9l
  16. +++ b/bin/9l
  17. @@ -45,6 +45,11 @@ case "$tag" in
  18.         ;;
  19.     esac
  20.     ;;
  21. +*GNU*)
  22. +   ld=${CC9:-gcc}
  23. +   userpath=true
  24. +   extralibs="$extralibs -lpthread"
  25. +   ;;
  26.  *Darwin*x86_64*)
  27.     ld="${CC9:-gcc} -m64"
  28.     ;;
  29. diff --git a/include/libc.h b/include/libc.h
  30. index 45b22b69..f12fef34 100644
  31. --- a/include/libc.h
  32. +++ b/include/libc.h
  33. @@ -599,18 +599,23 @@ extern    void        freenetconninfo(NetConnInfo*);
  34.  #define    MCACHE  0x0010  /* cache some data */
  35.  #define    MMASK   0x0017  /* all bits on */
  36.  
  37. -#define    OREAD   0   /* open for read */
  38. -#define    OWRITE  1   /* write */
  39. -#define    ORDWR   2   /* read and write */
  40. -#define    OEXEC   3   /* execute, == read but check execute permission */
  41. -#define    OTRUNC  16  /* or'ed in (except for exec), truncate file first */
  42. -#define    OCEXEC  32  /* or'ed in, close on exec */
  43. -#define    ORCLOSE 64  /* or'ed in, remove on close */
  44. -#define    ODIRECT 128 /* or'ed in, direct access */
  45. -#define    ONONBLOCK 256   /* or'ed in, non-blocking call */
  46. -#define    OEXCL   0x1000  /* or'ed in, exclusive use (create only) */
  47. -#define    OLOCK   0x2000  /* or'ed in, lock after opening */
  48. -#define    OAPPEND 0x4000  /* or'ed in, append only */
  49. +#include <fcntl.h>
  50. +#include <string.h>
  51. +#include <unistd.h>
  52. +#include <stdlib.h>
  53. +
  54. +#define    OREAD   O_RDONLY    /* open for read */
  55. +#define    OWRITE  O_WRONLY    /* write */
  56. +#define    ORDWR   O_RDWR      /* read and write */
  57. +#define    OEXEC   0   /* execute, == read but check execute permission */
  58. +#define    OTRUNC  O_TRUNC /* or'ed in (except for exec), truncate file first */
  59. +#define    OCEXEC  O_CLOEXEC   /* or'ed in, close on exec */
  60. +#define    ORCLOSE 0   /* or'ed in, remove on close */
  61. +#define    ODIRECT O_DIRECT    /* or'ed in, direct access */
  62. +#define    ONONBLOCK O_NONBLOCK    /* or'ed in, non-blocking call */
  63. +#define    OEXCL   O_EXCL  /* or'ed in, exclusive use (create only) */
  64. +#define    OLOCK   0   /* or'ed in, lock after opening */
  65. +#define    OAPPEND O_APPEND /* or'ed in, append only */
  66.  
  67.  #define    AEXIST  0   /* accessible: exists */
  68.  #define    AEXEC   1   /* execute access */
  69. diff --git a/src/cmd/9term/GNU.c b/src/cmd/9term/GNU.c
  70. new file mode 100644
  71. index 00000000..d3cdeb7c
  72. --- /dev/null
  73. +++ b/src/cmd/9term/GNU.c
  74. @@ -0,0 +1,21 @@
  75. +#define getpts not_using_this_getpts
  76. +#include "bsdpty.c"
  77. +#undef getpts
  78. +#include <signal.h>
  79. +#include <pty.h>
  80. +
  81. +int
  82. +getpts(int fd[], char *slave)
  83. +{
  84. +   void (*f)(int);
  85. +
  86. +   f = signal(SIGCHLD, SIG_DFL);
  87. +   if(openpty(&fd[1], &fd[0], NULL, NULL, NULL) >= 0){
  88. +       fchmod(fd[1], 0620);
  89. +       strcpy(slave, ttyname(fd[0]));
  90. +       signal(SIGCHLD, f);
  91. +       return 0;
  92. +   }
  93. +   sysfatal("no ptys");
  94. +   return 0;
  95. +}
  96. diff --git a/src/cmd/9term/mkfile b/src/cmd/9term/mkfile
  97. index 4546d666..6ef5025e 100644
  98. --- a/src/cmd/9term/mkfile
  99. +++ b/src/cmd/9term/mkfile
  100. @@ -8,9 +8,11 @@ OFILES=\
  101.  
  102.  HFILES=dat.h fns.h term.h
  103.  
  104. +LDFLAGS=$LDFLAGS -lutil
  105. +
  106.  <$PLAN9/src/mkmany
  107.  
  108. -Darwin.$O Linux.$O FreeBSD.$O DragonFly.$O: bsdpty.c
  109. +GNU.$0 Darwin.$O Linux.$O FreeBSD.$O DragonFly.$O: bsdpty.c
  110.  
  111.  $O.9term: data.$O scrl.$O time.$O util.$O wind.$O
  112.  
  113. diff --git a/src/cmd/astro/satel.c b/src/cmd/astro/satel.c
  114. index e610afa1..0ea96765 100644
  115. --- a/src/cmd/astro/satel.c
  116. +++ b/src/cmd/astro/satel.c
  117. @@ -36,7 +36,7 @@ satels(void)
  118.  loop:
  119.     if(*satp == 0)
  120.         return;
  121. -   f = open(*satp, 0);
  122. +   f = open(*satp, OREAD);
  123.     if(f < 0) {
  124.         fprint(2, "cannot open %s\n", *satp);
  125.         satp += 2;
  126. diff --git a/src/cmd/auxstats/GNU.c b/src/cmd/auxstats/GNU.c
  127. new file mode 100644
  128. index 00000000..804ee1b4
  129. --- /dev/null
  130. +++ b/src/cmd/auxstats/GNU.c
  131. @@ -0,0 +1,267 @@
  132. +#include <u.h>
  133. +#include <libc.h>
  134. +#include <bio.h>
  135. +#include "dat.h"
  136. +
  137. +void xapm(int);
  138. +void xloadavg(int);
  139. +void xmeminfo(int);
  140. +void xnet(int);
  141. +void xstat(int);
  142. +void xvmstat(int);
  143. +void xwireless(int);
  144. +
  145. +void (*statfn[])(int) =
  146. +{
  147. +   xapm,
  148. +   xloadavg,
  149. +   xmeminfo,
  150. +   xnet,
  151. +   xstat,
  152. +   xvmstat,
  153. +   xwireless,
  154. +   0
  155. +};
  156. +
  157. +void
  158. +xapm(int first)
  159. +{
  160. +   static int fd = -1, fdb = -1;
  161. +   int i, last = -1, curr = -1;
  162. +
  163. +   if(first){
  164. +       fd = open("/proc/acpi/battery/BAT0/info", OREAD);
  165. +       fdb = open("/proc/acpi/battery/BAT0/state", OREAD);
  166. +       return;
  167. +   }
  168. +   if(fd == -1 || fdb == -1)
  169. +       return;
  170. +
  171. +   readfile(fd);
  172. +   for(i=0; i<nline; i++){
  173. +       tokens(i);
  174. +       if(ntok < 3)
  175. +           continue;
  176. +       if(strcmp(tok[0], "last") == 0 && strcmp(tok[1], "full") == 0)
  177. +           last = atoi(tok[3]);
  178. +   }
  179. +   readfile(fdb);
  180. +   for(i = 0; i < nline; i++) {
  181. +       tokens(i);
  182. +       if(ntok < 3)
  183. +           continue;
  184. +       if(strcmp(tok[0], "remaining") == 0 && strcmp(tok[1], "capacity:") == 0)
  185. +           curr = atoi(tok[2]);
  186. +   }
  187. +
  188. +   if(curr != -1 && last != -1)
  189. +       Bprint(&bout, "battery =%d 100\n", (int)(((float)curr/(float)last)*100.0));
  190. +
  191. +}
  192. +
  193. +void
  194. +xloadavg(int first)
  195. +{
  196. +   static int fd = -1;
  197. +
  198. +   if(first){
  199. +       fd = open("/proc/loadavg", OREAD);
  200. +       return;
  201. +   }
  202. +
  203. +   readfile(fd);
  204. +   tokens(0);
  205. +   if(ntok >= 1)
  206. +       Bprint(&bout, "load =%d 1000\n", (int)(atof(tok[0])*1000));
  207. +}
  208. +
  209. +void
  210. +xmeminfo(int first)
  211. +{
  212. +   int i;
  213. +   vlong tot, used;
  214. +   vlong mtot, mfree;
  215. +   vlong stot, sfree;
  216. +   static int fd = -1;
  217. +
  218. +   if(first){
  219. +       fd = open("/proc/meminfo", OREAD);
  220. +       return;
  221. +   }
  222. +
  223. +   readfile(fd);
  224. +   mtot = 0;
  225. +   stot = 0;
  226. +   mfree = 0;
  227. +   sfree = 0;
  228. +   for(i=0; i<nline; i++){
  229. +       tokens(i);
  230. +       if(ntok < 3)
  231. +           continue;
  232. +       tot = atoll(tok[1]);
  233. +       used = atoll(tok[2]);
  234. +       if(strcmp(tok[0], "Mem:") == 0)
  235. +           Bprint(&bout, "mem =%lld %lld\n", used/1024, tot/1024);
  236. +       else if(strcmp(tok[0], "Swap:") == 0)
  237. +           Bprint(&bout, "swap =%lld %lld\n", used/1024, tot/1024);
  238. +       else if(strcmp(tok[0], "MemTotal:") == 0)
  239. +           mtot = atoll(tok[1]);   /* kb */
  240. +       else if(strcmp(tok[0], "MemFree:") == 0)
  241. +           mfree += atoll(tok[1]);
  242. +       else if(strcmp(tok[0], "Buffers:") == 0)
  243. +           mfree += atoll(tok[1]);
  244. +       else if(strcmp(tok[0], "Cached:") == 0){
  245. +           mfree += atoll(tok[1]);
  246. +           if(mtot < mfree)
  247. +               continue;
  248. +           Bprint(&bout, "mem =%lld %lld\n", mtot-mfree, mtot);
  249. +       }else if(strcmp(tok[0], "SwapTotal:") == 0)
  250. +           stot = atoll(tok[1]);   /* kb */
  251. +       else if(strcmp(tok[0], "SwapFree:") == 0){
  252. +           sfree = atoll(tok[1]);
  253. +           if(stot < sfree)
  254. +               continue;
  255. +           Bprint(&bout, "swap =%lld %lld\n", stot-sfree, stot);
  256. +       }
  257. +   }
  258. +}
  259. +
  260. +void
  261. +xnet(int first)
  262. +{
  263. +   int i, n;
  264. +   vlong totb, totp, tote, totin, totou, totinb, totoub, b, p, e, in, ou, inb, oub;
  265. +   char *q;
  266. +   static int fd = -1;
  267. +
  268. +   if(first){
  269. +       fd = open("/proc/net/dev", OREAD);
  270. +       return;
  271. +   }
  272. +
  273. +   readfile(fd);
  274. +   n = 0;
  275. +   totb = 0;
  276. +   tote = 0;
  277. +   totp = 0;
  278. +   totin = 0;
  279. +   totou = 0;
  280. +   totinb = 0;
  281. +   totoub = 0;
  282. +   for(i=0; i<nline; i++){
  283. +       if((q = strchr(line[i], ':')) != nil)
  284. +           *q = ' ';
  285. +       tokens(i);
  286. +       if(ntok < 8+8)
  287. +           continue;
  288. +       if(strncmp(tok[0], "eth", 3) != 0 && strncmp(tok[0], "wlan", 4) != 0)
  289. +           continue;
  290. +       inb = atoll(tok[1]);
  291. +       oub = atoll(tok[9]);
  292. +       in = atoll(tok[2]);
  293. +       ou = atoll(tok[10]);
  294. +       b = inb+oub;
  295. +       p = in+ou;
  296. +       e = atoll(tok[3])+atoll(tok[11]);
  297. +       totb += b;
  298. +       totp += p;
  299. +       tote += e;
  300. +       totin += in;
  301. +       totou += ou;
  302. +       totinb += inb;
  303. +       totoub += oub;
  304. +       n++;
  305. +   }
  306. +   Bprint(&bout, "etherb %lld %d\n", totb, n*1000000);
  307. +   Bprint(&bout, "ether %lld %d\n", totp, n*1000);
  308. +   Bprint(&bout, "ethererr %lld %d\n", tote, n*1000);
  309. +   Bprint(&bout, "etherin %lld %d\n", totin, n*1000);
  310. +   Bprint(&bout, "etherout %lld %d\n", totou, n*1000);
  311. +   Bprint(&bout, "etherinb %lld %d\n", totinb, n*1000);
  312. +   Bprint(&bout, "etheroutb %lld %d\n", totoub, n*1000);
  313. +}
  314. +
  315. +void
  316. +xstat(int first)
  317. +{
  318. +   static int fd = -1;
  319. +   int i;
  320. +
  321. +   if(first){
  322. +       fd = open("/proc/stat", OREAD);
  323. +       return;
  324. +   }
  325. +
  326. +   readfile(fd);
  327. +   for(i=0; i<nline; i++){
  328. +       tokens(i);
  329. +       if(ntok < 2)
  330. +           continue;
  331. +       if(strcmp(tok[0], "cpu") == 0 && ntok >= 5){
  332. +           Bprint(&bout, "user %lld 100\n", atoll(tok[1]));
  333. +           Bprint(&bout, "sys %lld 100\n", atoll(tok[3]));
  334. +           Bprint(&bout, "cpu %lld 100\n", atoll(tok[1])+atoll(tok[3]));
  335. +           Bprint(&bout, "idle %lld 100\n", atoll(tok[4]));
  336. +       }
  337. +   /*
  338. +       if(strcmp(tok[0], "page") == 0 && ntok >= 3){
  339. +           Bprint(&bout, "pagein %lld 500\n", atoll(tok[1]));
  340. +           Bprint(&bout, "pageout %lld 500\n", atoll(tok[2]));
  341. +           Bprint(&bout, "page %lld 1000\n", atoll(tok[1])+atoll(tok[2]));
  342. +       }
  343. +       if(strcmp(tok[0], "swap") == 0 && ntok >= 3){
  344. +           Bprint(&bout, "swapin %lld 500\n", atoll(tok[1]));
  345. +           Bprint(&bout, "swapout %lld 500\n", atoll(tok[2]));
  346. +           Bprint(&bout, "swap %lld 1000\n", atoll(tok[1])+atoll(tok[2]));
  347. +       }
  348. +   */
  349. +       if(strcmp(tok[0], "intr") == 0)
  350. +           Bprint(&bout, "intr %lld 1000\n", atoll(tok[1]));
  351. +       if(strcmp(tok[0], "ctxt") == 0)
  352. +           Bprint(&bout, "context %lld 10000\n", atoll(tok[1]));
  353. +       if(strcmp(tok[0], "processes") == 0)
  354. +           Bprint(&bout, "fork %lld 1000\n", atoll(tok[1]));
  355. +   }
  356. +}
  357. +
  358. +void
  359. +xvmstat(int first)
  360. +{
  361. +   static int fd = -1;
  362. +   int i;
  363. +
  364. +   if(first){
  365. +       fd = open("/proc/vmstat", OREAD);
  366. +       return;
  367. +   }
  368. +
  369. +   readfile(fd);
  370. +   for(i=0; i<nline; i++){
  371. +       tokens(i);
  372. +       if(ntok < 2)
  373. +           continue;
  374. +       if(strcmp(tok[0], "pgfault") == 0)
  375. +           Bprint(&bout, "fault %lld 100000\n", atoll(tok[1]));
  376. +   }
  377. +}
  378. +
  379. +void
  380. +xwireless(int first)
  381. +{
  382. +   static int fd = -1;
  383. +   int i;
  384. +
  385. +   if(first){
  386. +       fd = open("/proc/net/wireless", OREAD);
  387. +       return;
  388. +   }
  389. +
  390. +   readfile(fd);
  391. +   for(i=0; i<nline; i++){
  392. +       tokens(i);
  393. +       if(ntok < 3)
  394. +           continue;
  395. +       if(strcmp(tok[0], "wlan0:") == 0)
  396. +           Bprint(&bout, "802.11 =%lld 100\n", atoll(tok[2]));
  397. +   }
  398. +}
  399. diff --git a/src/cmd/db/print.c b/src/cmd/db/print.c
  400. index 3f1a5805..1c428ba4 100644
  401. --- a/src/cmd/db/print.c
  402. +++ b/src/cmd/db/print.c
  403. @@ -276,11 +276,11 @@ redirin(int stack, char *file)
  404.         return;
  405.     }
  406.     iclose(stack, 0);
  407. -   if ((infile = open(file, 0)) < 0) {
  408. +   if ((infile = open(file, OREAD)) < 0) {
  409.         strcpy(pfile, Ipath);
  410.         strcat(pfile, "/");
  411.         strcat(pfile, file);
  412. -       if ((infile = open(pfile, 0)) < 0) {
  413. +       if ((infile = open(pfile, OREAD)) < 0) {
  414.             infile = STDIN;
  415.             error("cannot open");
  416.         }
  417. diff --git a/src/cmd/dd.c b/src/cmd/dd.c
  418. index 01966b15..c8dc0328 100644
  419. --- a/src/cmd/dd.c
  420. +++ b/src/cmd/dd.c
  421. @@ -188,7 +188,7 @@ main(int argc, char *argv[])
  422.     if(conv == null && cflag&(LCASE|UCASE))
  423.         conv = cnull;
  424.     if(ifile)
  425. -       ibf = open(ifile, 0);
  426. +       ibf = open(ifile, OREAD);
  427.     else
  428.         ibf = dup(0, -1);
  429.     if(ibf < 0) {
  430. @@ -197,9 +197,9 @@ main(int argc, char *argv[])
  431.     }
  432.     if(ofile){
  433.         if(dotrunc)
  434. -           obf = create(ofile, 1, 0664);
  435. +           obf = create(ofile, OWRITE, 0664);
  436.         else
  437. -           obf = open(ofile, 1);
  438. +           obf = open(ofile, OWRITE);
  439.         if(obf < 0) {
  440.             fprint(2, "dd: create %s: %r\n", ofile);
  441.             exits("create");
  442. diff --git a/src/cmd/freq.c b/src/cmd/freq.c
  443. index daba277f..a5066b7d 100644
  444. --- a/src/cmd/freq.c
  445. +++ b/src/cmd/freq.c
  446. @@ -50,7 +50,7 @@ main(int argc, char *argv[])
  447.         exits(0);
  448.     }
  449.     for(i=0; i<argc; i++) {
  450. -       f = open(argv[i], 0);
  451. +       f = open(argv[i], OREAD);
  452.         if(f < 0) {
  453.             fprint(2, "cannot open %s\n", argv[i]);
  454.             continue;
  455. diff --git a/src/cmd/mk/main.c b/src/cmd/mk/main.c
  456. index 28e50c01..70c4e8ba 100644
  457. --- a/src/cmd/mk/main.c
  458. +++ b/src/cmd/mk/main.c
  459. @@ -164,12 +164,13 @@ main(int argc, char **argv)
  460.     symlook("MKARGS", S_VAR, (void *) stow(buf->start));
  461.     freebuf(buf);
  462.  
  463. +   fprint(2, "OREAD == %d\n", OREAD);
  464.     if(f == files){
  465.         if(access(MKFILE, 4) == 0)
  466. -           parse(MKFILE, open(MKFILE, 0), 0);
  467. +           parse(MKFILE, open(MKFILE, OREAD), 0);
  468.     } else
  469.         for(ff = files; ff < f; ff++)
  470. -           parse(*ff, open(*ff, 0), 0);
  471. +           parse(*ff, open(*ff, OREAD), 0);
  472.     if(DEBUG(D_PARSE)){
  473.         dumpw("default targets", target1);
  474.         dumpr("rules", rules);
  475. diff --git a/src/cmd/postscript/download/download.c b/src/cmd/postscript/download/download.c
  476. index 31aa1b3b..ffd3c7ea 100644
  477. --- a/src/cmd/postscript/download/download.c
  478. +++ b/src/cmd/postscript/download/download.c
  479. @@ -265,7 +265,7 @@ readmap(void)
  480.     sprintf(path, "%s/%s%s", hostfontdir, mapname, suffix);
  481.      } else path = mapname;
  482.  
  483. -    if ( (fd = open(path, 0)) != -1 ) {
  484. +    if ( (fd = open(path, OREAD)) != -1 ) {
  485.     if ( fstat(fd, &sbuf) == -1 )
  486.         error(FATAL, "can't fstat %s", path);
  487.     if ( (stringspace = (char *)malloc(sbuf.st_size + 2)) == NULL )
  488. diff --git a/src/cmd/proof/font.c b/src/cmd/proof/font.c
  489. index d930f34c..47c8eb0b 100644
  490. --- a/src/cmd/proof/font.c
  491. +++ b/src/cmd/proof/font.c
  492. @@ -146,7 +146,7 @@ loadfont(int n, int s)
  493.             for (deep = drawlog2[screen->depth]; deep >= 0; deep--){
  494.                 sprint(file, "%s/%s%d.%d", libfont, try[t], i, deep);
  495.                 dprint(2, "trying %s for %d\n", file, i);
  496. -               if ((fd = open(file, 0)) >= 0){
  497. +               if ((fd = open(file, OREAD)) >= 0){
  498.                     f = readsubfont(display, file, fd, 0);
  499.                     if (f == 0) {
  500.                         fprint(2, "can't rdsubfontfile %s: %r\n", file);
  501. diff --git a/src/cmd/proof/main.c b/src/cmd/proof/main.c
  502. index 5e0c804c..a116946c 100644
  503. --- a/src/cmd/proof/main.c
  504. +++ b/src/cmd/proof/main.c
  505. @@ -82,7 +82,7 @@ main(int argc, char *argv[])
  506.  
  507.     if (argc > 0) {
  508.         close(0);
  509. -       if (open(argv[0], 0) != 0) {
  510. +       if (open(argv[0], OREAD) != 0) {
  511.             sysfatal("can't open %s: %r\n", argv[0]);
  512.             exits("open failure");
  513.         }
  514. diff --git a/src/cmd/rc/exec.c b/src/cmd/rc/exec.c
  515. index 03c96d49..165a722c 100644
  516. --- a/src/cmd/rc/exec.c
  517. +++ b/src/cmd/rc/exec.c
  518. @@ -254,7 +254,7 @@ Xappend(void)
  519.         break;
  520.     }
  521.     file = runq->argv->words->word;
  522. -   if((f = open(file, 1))<0 && (f = Creat(file))<0){
  523. +   if((f = open(file, OWRITE))<0 && (f = Creat(file))<0){
  524.         pfmt(err, "%s: ", file);
  525.         Xerror("can't open");
  526.         return;
  527. @@ -371,7 +371,7 @@ Xread(void)
  528.         break;
  529.     }
  530.     file = runq->argv->words->word;
  531. -   if((f = open(file, 0))<0){
  532. +   if((f = open(file, OREAD))<0){
  533.         pfmt(err, "%s: ", file);
  534.         Xerror("can't open");
  535.         return;
  536. diff --git a/src/cmd/rc/havefork.c b/src/cmd/rc/havefork.c
  537. index dc0ca2e8..04e11796 100644
  538. --- a/src/cmd/rc/havefork.c
  539. +++ b/src/cmd/rc/havefork.c
  540. @@ -15,7 +15,7 @@ int havefork = 1;
  541.  void
  542.  Xasync(void)
  543.  {
  544. -   int null = open("/dev/null", 0);
  545. +   int null = open("/dev/null", OREAD);
  546.     int tty;
  547.     int pid;
  548.     char npid[10];
  549. diff --git a/src/cmd/rc/io.c b/src/cmd/rc/io.c
  550. index bb8af4ab..34b56417 100644
  551. --- a/src/cmd/rc/io.c
  552. +++ b/src/cmd/rc/io.c
  553. @@ -222,7 +222,7 @@ opencore(char *s, int len)
  554.  {
  555.     io *f = new(struct io);
  556.     char *buf = emalloc(len);
  557. -   f->fd= -1 /*open("/dev/null", 0)*/;
  558. +   f->fd= -1 /*open("/dev/null", OREAD)*/;
  559.     f->bufp = f->strp = buf;
  560.     f->ebuf = buf+len;
  561.     Memcpy(buf, s, len);
  562. diff --git a/src/cmd/rc/plan9ish.c b/src/cmd/rc/plan9ish.c
  563. index da9d8679..643cf158 100644
  564. --- a/src/cmd/rc/plan9ish.c
  565. +++ b/src/cmd/rc/plan9ish.c
  566. @@ -398,7 +398,7 @@ int Opendir(char *name)
  567.  {
  568.     Dir *db;
  569.     int f;
  570. -   f=open(name, 0);
  571. +   f=open(name, OREAD);
  572.     if(f==-1)
  573.         return f;
  574.     db = dirfstat(f);
  575. diff --git a/src/cmd/rc/simple.c b/src/cmd/rc/simple.c
  576. index d587227a..100df6af 100644
  577. --- a/src/cmd/rc/simple.c
  578. +++ b/src/cmd/rc/simple.c
  579. @@ -358,7 +358,7 @@ execdot(void)
  580.         if(file[0])
  581.             strcat(file, "/");
  582.         strcat(file, zero);
  583. -       if((fd = open(file, 0))>=0) break;
  584. +       if((fd = open(file, OREAD))>=0) break;
  585.         if(strcmp(file, "/dev/stdin")==0){  /* for sun & ucb */
  586.             fd = Dup1(0);
  587.             if(fd>=0)
  588. diff --git a/src/cmd/sam/_libc.h b/src/cmd/sam/_libc.h
  589. index 65618918..7b715bfa 100644
  590. --- a/src/cmd/sam/_libc.h
  591. +++ b/src/cmd/sam/_libc.h
  592. @@ -20,7 +20,7 @@
  593.  #define getwd getcwd
  594.  #define USED(a)
  595.  #define SET(a)
  596. -
  597. +/*
  598.  enum {
  599.     OREAD = 0,
  600.     OWRITE = 1,
  601. @@ -28,7 +28,7 @@ enum {
  602.     OCEXEC = 4,
  603.     ORCLOSE = 8
  604.  };
  605. -
  606. +*/
  607.  enum {
  608.     ERRMAX = 255
  609.  };
  610. diff --git a/src/cmd/sam/plan9.c b/src/cmd/sam/plan9.c
  611. index 0a3fe070..29360760 100644
  612. --- a/src/cmd/sam/plan9.c
  613. +++ b/src/cmd/sam/plan9.c
  614. @@ -56,7 +56,7 @@ getuser(void)
  615.     int fd;
  616.  
  617.     if(user[0] == 0){
  618. -       fd = open("/dev/user", 0);
  619. +       fd = open("/dev/user", OREAD);
  620.         if(fd<0 || read(fd, user, sizeof user-1)<=0)
  621.             strcpy(user, "none");
  622.         close(fd);
  623. diff --git a/src/cmd/sam/shell.c b/src/cmd/sam/shell.c
  624. index c6efdd57..1015cf4f 100644
  625. --- a/src/cmd/sam/shell.c
  626. +++ b/src/cmd/sam/shell.c
  627. @@ -55,7 +55,7 @@ plan9(File *f, int type, String *s, int nest)
  628.                 dup(2, 1);
  629.             else if(type=='!'){
  630.                 dup(2, 1);
  631. -               fd = open("/dev/null", 0);
  632. +               fd = open("/dev/null", OREAD);
  633.                 dup(fd, 0);
  634.                 close(fd);
  635.             }
  636. @@ -102,7 +102,7 @@ plan9(File *f, int type, String *s, int nest)
  637.         }
  638.         if(type=='<'){
  639.             close(0);   /* so it won't read from terminal */
  640. -           open("/dev/null", 0);
  641. +           open("/dev/null", OREAD);
  642.         }
  643.         execl(SHPATH, SH, "-c", Strtoc(&plan9cmd), (char *)0);
  644.         exits("exec");
  645. @@ -149,7 +149,7 @@ checkerrs(void)
  646.     long l;
  647.  
  648.     if(statfile(errfile, 0, 0, 0, &l, 0) > 0 && l != 0){
  649. -       if((f=open(errfile, 0)) != -1){
  650. +       if((f=open(errfile, OREAD)) != -1){
  651.             if((n=read(f, buf, sizeof buf-1)) > 0){
  652.                 for(nl=0,p=buf; nl<25 && p<&buf[n]; p++)
  653.                     if(*p=='\n')
  654. diff --git a/src/cmd/scat/scat.c b/src/cmd/scat/scat.c
  655. index 35b7e7aa..a25758fa 100644
  656. --- a/src/cmd/scat/scat.c
  657. +++ b/src/cmd/scat/scat.c
  658. @@ -122,7 +122,7 @@ eopen(char *s)
  659.     int f;
  660.  
  661.     sprint(buf, "%s/%s.scat", dir, s);
  662. -   f = open(buf, 0);
  663. +   f = open(buf, OREAD);
  664.     if(f<0){
  665.         fprint(2, "scat: can't open %s\n", buf);
  666.         exits("open");
  667. diff --git a/src/cmd/spell/sprog.c b/src/cmd/spell/sprog.c
  668. index 6eaa026f..6ea3304f 100644
  669. --- a/src/cmd/spell/sprog.c
  670. +++ b/src/cmd/spell/sprog.c
  671. @@ -1301,7 +1301,7 @@ readdict(char *file)
  672.     long l;
  673.  
  674.     lasts = 0;
  675. -   f = open(file, 0);
  676. +   f = open(file, OREAD);
  677.     if(f == -1) {
  678.         fprint(2, "cannot open %s\n", file);
  679.         exits("open");
  680. diff --git a/src/cmd/tcs/tcs.c b/src/cmd/tcs/tcs.c
  681. index 6722bb6b..c5b512cd 100644
  682. --- a/src/cmd/tcs/tcs.c
  683. +++ b/src/cmd/tcs/tcs.c
  684. @@ -92,7 +92,7 @@ main(int argc, char **argv)
  685.         while(*argv){
  686.             file = *argv;
  687.  #ifndef PLAN9
  688. -           if((fd = open(*argv, 0)) < 0){
  689. +           if((fd = open(*argv, OREAD)) < 0){
  690.                 EPR "%s: %s: %s\n", argv0, *argv, strerror(errno));
  691.  #else /* PLAN9 */
  692.             if((fd = open(*argv, OREAD)) < 0){
  693. diff --git a/src/cmd/uniq.c b/src/cmd/uniq.c
  694. index 88fb9286..ea3e7c72 100644
  695. --- a/src/cmd/uniq.c
  696. +++ b/src/cmd/uniq.c
  697. @@ -48,7 +48,7 @@ main(int argc, char *argv[])
  698.             argv++;
  699.             continue;
  700.         }
  701. -       f = open(argv[1], 0);
  702. +       f = open(argv[1], OREAD);
  703.         if(f < 0) {
  704.             fprint(2, "cannot open %s\n", argv[1]);
  705.             exits("open");
  706. diff --git a/src/cmd/vbackup/mount-GNU.c b/src/cmd/vbackup/mount-GNU.c
  707. new file mode 100644
  708. index 00000000..3dde4fdf
  709. --- /dev/null
  710. +++ b/src/cmd/vbackup/mount-GNU.c
  711. @@ -0,0 +1 @@
  712. +#include "mount-none.c"
  713. diff --git a/src/lib9/dirread.c b/src/lib9/dirread.c
  714. index 40fbe3c7..79cda6f3 100644
  715. --- a/src/lib9/dirread.c
  716. +++ b/src/lib9/dirread.c
  717. @@ -18,6 +18,25 @@ mygetdents(int fd, struct dirent *buf, int n)
  718.     nn = getdirentries(fd, (void*)buf, n, &off);
  719.     return nn;
  720.  }
  721. +#elif defined (__GNU__)
  722. +static int
  723. +mygetdents(int fd, struct dirent *buf, int n)
  724. +{
  725. +   int i;
  726. +   int fd2 = dup(fd);
  727. +   DIR *d = fdopendir(fd2);
  728. +
  729. +   for (i = 0; i < n; i++) {
  730. +       struct dirent *ent = readdir(d);
  731. +       if (ent == NULL) {
  732. +           break;
  733. +       }
  734. +       memcpy(buf++, ent, sizeof(struct dirent));
  735. +   }
  736. +
  737. +   closedir(d);
  738. +   return i;
  739. +}
  740.  #elif defined(__APPLE__)
  741.  static int
  742.  mygetdents(int fd, struct dirent *buf, int n)
  743. diff --git a/src/libip/GNU.c b/src/libip/GNU.c
  744. new file mode 100644
  745. index 00000000..48c87c62
  746. --- /dev/null
  747. +++ b/src/libip/GNU.c
  748. @@ -0,0 +1 @@
  749. +#include "none.c"
  750. diff --git a/src/libip/mkfile b/src/libip/mkfile
  751. index 88b0fd99..fc479df6 100644
  752. --- a/src/libip/mkfile
  753. +++ b/src/libip/mkfile
  754. @@ -21,6 +21,7 @@ HFILES=\
  755.  <$PLAN9/src/mksyslib
  756.  
  757.  Darwin.$O FreeBSD.$O DragonFly.$O: BSD.c
  758. +GNU.$0: GNU.c
  759.  
  760.  testreadipifc: testreadipifc.o $LIBDIR/$LIB
  761.     $LD -o testreadipifc testreadipifc.o
  762. diff --git a/src/libmach/GNU.c b/src/libmach/GNU.c
  763. new file mode 100644
  764. index 00000000..3626e7c6
  765. --- /dev/null
  766. +++ b/src/libmach/GNU.c
  767. @@ -0,0 +1 @@
  768. +#include "nosys.c"
  769. diff --git a/src/libmach/mkfile b/src/libmach/mkfile
  770. index 7659b708..075b2580 100644
  771. --- a/src/libmach/mkfile
  772. +++ b/src/libmach/mkfile
  773. @@ -81,4 +81,4 @@ SunOS.$O: nosys.c
  774.  Darwin.$O: nosys.c
  775.  OpenBSD.$O: nosys.c
  776.  NetBSD.$O: nosys.c
  777. -
  778. +GNU.$0: nosys.c