compat.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "l.h"
  10. /*
  11. * fake malloc
  12. */
  13. void*
  14. malloc(uint32_t n)
  15. {
  16. void *p;
  17. while(n & 7)
  18. n++;
  19. while(nhunk < n)
  20. gethunk();
  21. p = hunk;
  22. nhunk -= n;
  23. hunk += n;
  24. return p;
  25. }
  26. void
  27. free(void *p)
  28. {
  29. USED(p);
  30. }
  31. void*
  32. calloc(uint32_t m, uint32_t n)
  33. {
  34. void *p;
  35. n *= m;
  36. p = malloc(n);
  37. memset(p, 0, n);
  38. return p;
  39. }
  40. void*
  41. realloc(void*, uint32_t)
  42. {
  43. fprint(2, "realloc called\n");
  44. abort();
  45. return 0;
  46. }
  47. void*
  48. mysbrk(uint32_t size)
  49. {
  50. return sbrk(size);
  51. }
  52. void
  53. setmalloctag(void*, uint32_t)
  54. {
  55. }
  56. int
  57. fileexists(char *s)
  58. {
  59. uint8_t dirbuf[400];
  60. /* it's fine if stat result doesn't fit in dirbuf, since even then the file exists */
  61. return stat(s, dirbuf, sizeof(dirbuf)) >= 0;
  62. }