1
0

mkwnew.c 862 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <u.h>
  2. #include <libc.h>
  3. void
  4. main(int argc, char *argv[])
  5. {
  6. int i, fd, pid, n;
  7. char wdir[256];
  8. int dflag;
  9. dflag = 0;
  10. ARGBEGIN{
  11. case 'd':
  12. dflag = 1;
  13. break;
  14. default:
  15. fprint(2, "usage: wnew [-d] [label]\n");
  16. }ARGEND
  17. pid = getpid();
  18. wdir[0] = '\0';
  19. if(!dflag)
  20. getwd(wdir, sizeof wdir);
  21. if(argc>0)
  22. for(i=0; i<argc; i++)
  23. snprint(wdir, sizeof wdir, "%s%c%s", wdir, i==0? '/' : '-', argv[i]);
  24. else
  25. snprint(wdir, sizeof wdir, "%s/-win", wdir);
  26. if((fd = open("/dev/wnew", ORDWR)) < 0)
  27. sysfatal("wnew: can't open /dev/wnew: %r");
  28. if(fprint(fd, "%d %s", pid, wdir+dflag) < 0)
  29. sysfatal("wnew: can't create window: %r");
  30. if(seek(fd, 0, 0) != 0)
  31. sysfatal("wnew: can't seek: %r");
  32. if((n=read(fd, wdir, sizeof wdir-1)) < 0)
  33. sysfatal("wnew: can't read window id: %r");
  34. wdir[n] = '\0';
  35. print("%s\n", wdir);
  36. exits(nil);
  37. }