compat.c 665 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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*, ulong)
  34. {
  35. fprint(2, "realloc called\n");
  36. abort();
  37. return 0;
  38. }
  39. void*
  40. mysbrk(ulong size)
  41. {
  42. return sbrk(size);
  43. }
  44. void
  45. setmalloctag(void*, ulong)
  46. {
  47. }
  48. int
  49. fileexists(char *s)
  50. {
  51. uchar dirbuf[400];
  52. /* it's fine if stat result doesn't fit in dirbuf, since even then the file exists */
  53. return stat(s, dirbuf, sizeof(dirbuf)) >= 0;
  54. }