compat.c 704 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "l.h"
  2. /*
  3. * fake malloc
  4. */
  5. void*
  6. malloc(ulong n)
  7. {
  8. void *p;
  9. while(n & 7)
  10. n++;
  11. while(nhunk < n)
  12. gethunk();
  13. p = hunk;
  14. nhunk -= n;
  15. hunk += n;
  16. return p;
  17. }
  18. void
  19. free(void *p)
  20. {
  21. USED(p);
  22. }
  23. void*
  24. calloc(ulong m, ulong n)
  25. {
  26. void *p;
  27. n *= m;
  28. p = malloc(n);
  29. memset(p, 0, n);
  30. return p;
  31. }
  32. void*
  33. realloc(void *p, ulong n)
  34. {
  35. fprint(2, "realloc(0x%p %ld) called\n", p, n);
  36. abort();
  37. return 0;
  38. }
  39. void*
  40. mysbrk(ulong size)
  41. {
  42. return sbrk(size);
  43. }
  44. void
  45. setmalloctag(void *v, ulong pc)
  46. {
  47. USED(v, pc);
  48. }
  49. int
  50. fileexists(char *s)
  51. {
  52. uchar dirbuf[400];
  53. /* it's fine if stat result doesn't fit in dirbuf, since even then the file exists */
  54. return stat(s, dirbuf, sizeof(dirbuf)) >= 0;
  55. }