wdir.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #include <bio.h>
  12. #include <String.h>
  13. #include <thread.h>
  14. #include "wiki.h"
  15. /* open, create relative to wiki dir */
  16. char *wikidir;
  17. static char*
  18. wname(char *s)
  19. {
  20. char *t;
  21. t = emalloc(strlen(wikidir)+1+strlen(s)+1);
  22. strcpy(t, wikidir);
  23. strcat(t, "/");
  24. strcat(t, s);
  25. return t;
  26. }
  27. int
  28. wopen(char *fn, int mode)
  29. {
  30. int rv;
  31. fn = wname(fn);
  32. rv = open(fn, mode);
  33. free(fn);
  34. return rv;
  35. }
  36. int
  37. wcreate(char *fn, int mode, int32_t perm)
  38. {
  39. int rv;
  40. fn = wname(fn);
  41. rv = create(fn, mode, perm);
  42. free(fn);
  43. return rv;
  44. }
  45. Biobuf*
  46. wBopen(char *fn, int mode)
  47. {
  48. Biobuf *rv;
  49. fn = wname(fn);
  50. rv = Bopen(fn, mode);
  51. free(fn);
  52. return rv;
  53. }
  54. int
  55. waccess(char *fn, int mode)
  56. {
  57. int rv;
  58. fn = wname(fn);
  59. rv = access(fn, mode);
  60. free(fn);
  61. return rv;
  62. }
  63. Dir*
  64. wdirstat(char *fn)
  65. {
  66. Dir *d;
  67. fn = wname(fn);
  68. d = dirstat(fn);
  69. free(fn);
  70. return d;
  71. }