dirmodeconv.c 970 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <plan9.h>
  10. #include <fcall.h>
  11. static char *modes[] =
  12. {
  13. "---",
  14. "--x",
  15. "-w-",
  16. "-wx",
  17. "r--",
  18. "r-x",
  19. "rw-",
  20. "rwx",
  21. };
  22. static void
  23. rwx(int32_t m, char *s)
  24. {
  25. strncpy(s, modes[m], 3);
  26. }
  27. int
  28. dirmodeconv(va_list *arg, Fconv *f)
  29. {
  30. static char buf[16];
  31. uint32_t m;
  32. m = va_arg(*arg, uint32_t);
  33. if(m & DMDIR)
  34. buf[0]='d';
  35. else if(m & DMAPPEND)
  36. buf[0]='a';
  37. else
  38. buf[0]='-';
  39. if(m & DMEXCL)
  40. buf[1]='l';
  41. else
  42. buf[1]='-';
  43. rwx((m>>6)&7, buf+2);
  44. rwx((m>>3)&7, buf+5);
  45. rwx((m>>0)&7, buf+8);
  46. buf[11] = 0;
  47. strconv(buf, f);
  48. return 0;
  49. }