1
0

unistd.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef __UNISTD_H
  2. #define __UNISTD_H
  3. #define SEEK_SET 0
  4. #define SEEK_CUR 1
  5. #define SEEK_END 2
  6. off_t lseek(int fildes, off_t offset, int whence);
  7. #include "asmc.h"
  8. #include "sys/stat.h"
  9. #include "errno.h"
  10. // STUB
  11. int access(const char *path, int amode) {
  12. __unimplemented();
  13. errno = ENOTIMPL;
  14. return -1;
  15. }
  16. // STUB
  17. int isatty(int fildes) {
  18. __unimplemented();
  19. errno = ENOTIMPL;
  20. return 0;
  21. }
  22. ssize_t read(int fildes, void *buf, size_t nbyte) {
  23. if (fildes == 1 || fildes == 2) {
  24. return 0;
  25. }
  26. if (nbyte == 0) {
  27. return 0;
  28. }
  29. int c;
  30. if (fildes == 0) {
  31. c = __handles->input_getc();
  32. // Loop back character to console
  33. __handles->write(c);
  34. } else {
  35. c = __handles->vfs_read(fildes);
  36. }
  37. if (c < 0) {
  38. return 0;
  39. } else {
  40. _force_assert(0 <= c && c < 256);
  41. *(char*)buf = (char) c;
  42. return 1;
  43. }
  44. }
  45. // STUB
  46. char *getcwd(char *buf, size_t size) {
  47. __unimplemented();
  48. errno = ENOTIMPL;
  49. return NULL;
  50. }
  51. // Just ignore unlink
  52. int unlink(const char *path) {
  53. return 0;
  54. }
  55. off_t lseek(int fildes, off_t offset, int whence) {
  56. //printf("seeking at %d from %d\n", offset, whence);
  57. return __handles->vfs_seek(whence, offset, fildes);
  58. }
  59. int close(int fildes) {
  60. __handles->vfs_close(fildes);
  61. return 0;
  62. }
  63. // STUB
  64. int ftruncate(int fildes, off_t length) {
  65. __unimplemented();
  66. errno = ENOTIMPL;
  67. return -1;
  68. }
  69. #endif