file.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "mk.h"
  10. /* table-driven version in bootes dump of 12/31/96 */
  11. uint32_t
  12. mtime(char *name)
  13. {
  14. return mkmtime(name, 1);
  15. }
  16. uint32_t
  17. timeof(char *name, int force)
  18. {
  19. Symtab *sym;
  20. uint32_t t;
  21. if(utfrune(name, '('))
  22. return atimeof(force, name); /* archive */
  23. if(force)
  24. return mtime(name);
  25. sym = symlook(name, S_TIME, 0);
  26. if (sym)
  27. return sym->u.value; /* uggh */
  28. t = mkmtime(name, 0);
  29. if(t == 0)
  30. return 0;
  31. symlook(name, S_TIME, (void*)t); /* install time in cache */
  32. return t;
  33. }
  34. void
  35. touch(char *name)
  36. {
  37. Bprint(&bout, "touch(%s)\n", name);
  38. if(nflag)
  39. return;
  40. if(utfrune(name, '('))
  41. atouch(name); /* archive */
  42. else if(chgtime(name) < 0) {
  43. perror(name);
  44. Exit();
  45. }
  46. }
  47. void
  48. delete(char *name)
  49. {
  50. if(utfrune(name, '(') == 0) { /* file */
  51. if(remove(name) < 0)
  52. perror(name);
  53. } else
  54. fprint(2, "hoon off; mk can'tdelete archive members\n");
  55. }
  56. void
  57. timeinit(char *s)
  58. {
  59. uint32_t t;
  60. char *cp;
  61. Rune r;
  62. int c, n;
  63. t = time(0);
  64. while (*s) {
  65. cp = s;
  66. do{
  67. n = chartorune(&r, s);
  68. if (r == ' ' || r == ',' || r == '\n')
  69. break;
  70. s += n;
  71. } while(*s);
  72. c = *s;
  73. *s = 0;
  74. symlook(strdup(cp), S_TIME, (void *)t)->u.value = t;
  75. if (c)
  76. *s++ = c;
  77. while(*s){
  78. n = chartorune(&r, s);
  79. if(r != ' ' && r != ',' && r != '\n')
  80. break;
  81. s += n;
  82. }
  83. }
  84. }