bind.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. void usage(void);
  12. void
  13. main(int argc, char *argv[])
  14. {
  15. uint32_t flag = 0;
  16. int qflag = 0;
  17. ARGBEGIN{
  18. case 'a':
  19. flag |= MAFTER;
  20. break;
  21. case 'b':
  22. flag |= MBEFORE;
  23. break;
  24. case 'c':
  25. flag |= MCREATE;
  26. break;
  27. case 'q':
  28. qflag = 1;
  29. break;
  30. default:
  31. usage();
  32. }ARGEND
  33. if(argc != 2 || ((flag&MAFTER)&&(flag&MBEFORE)))
  34. usage();
  35. if(bind(argv[0], argv[1], flag) < 0){
  36. if(qflag)
  37. exits(0);
  38. /* try to give a less confusing error than the default */
  39. if(access(argv[0], 0) < 0)
  40. fprint(2, "bind: %s: %r\n", argv[0]);
  41. else if(access(argv[1], 0) < 0)
  42. fprint(2, "bind: %s: %r\n", argv[1]);
  43. else
  44. fprint(2, "bind %s %s: %r\n", argv[0], argv[1]);
  45. exits("bind");
  46. }
  47. exits(0);
  48. }
  49. void
  50. usage(void)
  51. {
  52. fprint(2, "usage: bind [-q] [-b|-a|-c|-bc|-ac] new old\n");
  53. exits("usage");
  54. }