awd.c 661 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <u.h>
  2. #include <libc.h>
  3. /*
  4. * like fprint but be sure to deliver as a single write.
  5. * (fprint uses a small write buffer.)
  6. */
  7. void
  8. xfprint(int fd, char *fmt, ...)
  9. {
  10. char *s;
  11. va_list arg;
  12. va_start(arg, fmt);
  13. s = vsmprint(fmt, arg);
  14. va_end(arg);
  15. if(s == nil)
  16. sysfatal("smprint: %r");
  17. write(fd, s, strlen(s));
  18. free(s);
  19. }
  20. void
  21. main(int argc, char **argv)
  22. {
  23. int fd;
  24. char dir[512];
  25. fd = open("/dev/acme/ctl", OWRITE);
  26. if(fd < 0)
  27. exits(0);
  28. getwd(dir, 512);
  29. if(dir[0]!=0 && dir[strlen(dir)-1]=='/')
  30. dir[strlen(dir)-1] = 0;
  31. xfprint(fd, "name %s/-%s\n", dir, argc > 1 ? argv[1] : "rc");
  32. xfprint(fd, "dumpdir %s\n", dir);
  33. exits(0);
  34. }