|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- /*********************************************************************/
- /* */
- /* This Program Written By Paul Edwards. */
- /* Released to the public domain. */
- /* */
- /*********************************************************************/
- /*********************************************************************/
- /* */
- /* unixio - Unix I/O functions written in terms of standard C */
- /* functions. */
- /* */
- /*********************************************************************/
-
- #include <stdio.h>
-
- #ifdef fileno
- #undef fileno
- #endif
-
- #include "unixio.h"
-
- static FILE *files[FOPEN_MAX];
- /*char *environ[] = { NULL };*/
-
- int open(const char *fnm, int mode, ...)
- {
- int x;
- char *modestr;
-
- for (x = 3; x < FOPEN_MAX; x++)
- {
- if (files[x] == NULL)
- {
- break;
- }
- }
- if (x == FOPEN_MAX)
- {
- return (-1);
- }
- if (mode == O_RDONLY)
- {
- modestr = "r";
- }
- else if (mode == O_WRONLY)
- {
- modestr = "w";
- }
- else if (mode == O_RDWR)
- {
- modestr = "r+";
- }
- files[x] = fopen(fnm, modestr);
- if (files[x] == NULL)
- {
- return (-1);
- }
- return (x);
- }
-
- int read(int fno, void *buf, size_t bytes)
- {
- size_t rb;
-
- if (fno < 3)
- {
- rb = fread(buf, 1, bytes, stdin);
- }
- else
- {
- rb = fread(buf, 1, bytes, files[fno]);
- }
- return ((int)rb);
- }
-
- int write(int fno, const void *buf, size_t bytes)
- {
- size_t wb;
-
- if (fno == 1)
- {
- fwrite(buf, 1, bytes, stdout);
- }
- else if (fno == 2)
- {
- fwrite(buf, 1, bytes, stderr);
- }
- else if (fno > 2)
- {
- wb = fwrite(buf, 1, bytes, files[fno]);
- }
- return ((int)wb);
- }
-
- int close(int fno)
- {
- if (fno >= 3)
- {
- fclose(files[fno]);
- files[fno] = NULL;
- }
- return (0);
- }
-
- char *getcwd(char *buf, int len)
- {
- if (len != 0)
- {
- *buf = '\0';
- }
- return (buf);
- }
-
- void unlink(char *f)
- {
- remove(f);
- return;
- }
-
- int stat(char *f, struct stat *buf)
- {
- memset(buf, '\0', sizeof *buf);
- return (0);
- }
-
- int fileno(FILE *fp)
- {
- return (0);
- }
-
- int access(char *f, int n)
- {
- return (1);
- }
-
- int fstat(int fh, struct stat *buf)
- {
- memset(buf, '\0', sizeof *buf);
- return (0);
- }
-
- int pwait(int a, int *b, int c)
- {
- return (0);
- }
-
- int putenv(char *x)
- {
- return (0);
- }
-
- char *mktemp(char *s)
- {
- return (tmpnam(s));
- }
-
- int chdir(char *path)
- {
- return (0);
- }
-
- int rmdir(char *path)
- {
- return (0);
- }
-
- int mkdir(char *path, int permissions)
- {
- return (0);
- }
|