ChipMaster's bwBASIC This also includes history going back to v2.10. *WARN* some binary files might have been corrupted by CRLF.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

171 lines
2.9 KiB

  1. /*********************************************************************/
  2. /* */
  3. /* This Program Written By Paul Edwards. */
  4. /* Released to the public domain. */
  5. /* */
  6. /*********************************************************************/
  7. /*********************************************************************/
  8. /* */
  9. /* unixio - Unix I/O functions written in terms of standard C */
  10. /* functions. */
  11. /* */
  12. /*********************************************************************/
  13. #include <stdio.h>
  14. #ifdef fileno
  15. #undef fileno
  16. #endif
  17. #include "unixio.h"
  18. static FILE *files[FOPEN_MAX];
  19. /*char *environ[] = { NULL };*/
  20. int open(const char *fnm, int mode, ...)
  21. {
  22. int x;
  23. char *modestr;
  24. for (x = 3; x < FOPEN_MAX; x++)
  25. {
  26. if (files[x] == NULL)
  27. {
  28. break;
  29. }
  30. }
  31. if (x == FOPEN_MAX)
  32. {
  33. return (-1);
  34. }
  35. if (mode == O_RDONLY)
  36. {
  37. modestr = "r";
  38. }
  39. else if (mode == O_WRONLY)
  40. {
  41. modestr = "w";
  42. }
  43. else if (mode == O_RDWR)
  44. {
  45. modestr = "r+";
  46. }
  47. files[x] = fopen(fnm, modestr);
  48. if (files[x] == NULL)
  49. {
  50. return (-1);
  51. }
  52. return (x);
  53. }
  54. int read(int fno, void *buf, size_t bytes)
  55. {
  56. size_t rb;
  57. if (fno < 3)
  58. {
  59. rb = fread(buf, 1, bytes, stdin);
  60. }
  61. else
  62. {
  63. rb = fread(buf, 1, bytes, files[fno]);
  64. }
  65. return ((int)rb);
  66. }
  67. int write(int fno, const void *buf, size_t bytes)
  68. {
  69. size_t wb = 0;
  70. if (fno == 1)
  71. {
  72. wb = fwrite(buf, 1, bytes, stdout);
  73. }
  74. else if (fno == 2)
  75. {
  76. wb = fwrite(buf, 1, bytes, stderr);
  77. }
  78. else if (fno > 2)
  79. {
  80. wb = fwrite(buf, 1, bytes, files[fno]);
  81. }
  82. return ((int)wb);
  83. }
  84. int close(int fno)
  85. {
  86. if (fno >= 3)
  87. {
  88. fclose(files[fno]);
  89. files[fno] = NULL;
  90. }
  91. return (0);
  92. }
  93. char *getcwd(char *buf, int len)
  94. {
  95. if (len != 0)
  96. {
  97. *buf = '\0';
  98. }
  99. return (buf);
  100. }
  101. void unlink(char *f)
  102. {
  103. remove(f);
  104. return;
  105. }
  106. int stat(char *f, struct stat *buf)
  107. {
  108. memset(buf, '\0', sizeof *buf);
  109. return (0);
  110. }
  111. int fileno(FILE *fp)
  112. {
  113. return (0);
  114. }
  115. int access(char *f, int n)
  116. {
  117. return (1);
  118. }
  119. int fstat(int fh, struct stat *buf)
  120. {
  121. memset(buf, '\0', sizeof *buf);
  122. return (0);
  123. }
  124. int pwait(int a, int *b, int c)
  125. {
  126. return (0);
  127. }
  128. int putenv(char *x)
  129. {
  130. return (0);
  131. }
  132. char *mktemp(char *s)
  133. {
  134. return (tmpnam(s));
  135. }
  136. int chdir(char *path)
  137. {
  138. return (0);
  139. }
  140. int rmdir(char *path)
  141. {
  142. return (0);
  143. }
  144. int mkdir(char *path, int permissions)
  145. {
  146. return (0);
  147. }