diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2001-11-12 21:04:41 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2001-11-12 21:04:41 +0000 |
commit | 8be9b48be685645e2f5b977de10492108581352c (patch) | |
tree | 7b060090d130dd0e5375497dd6ab4946b3a0b238 /newlib/libc/sys/mmixware/open.c | |
parent | 5e051b1bf7e468251890457a62093c509168f304 (diff) | |
download | cygnal-8be9b48be685645e2f5b977de10492108581352c.tar.gz cygnal-8be9b48be685645e2f5b977de10492108581352c.tar.bz2 cygnal-8be9b48be685645e2f5b977de10492108581352c.zip |
2001-11-12 Hans-Peter Nilsson <hp@bitrange.com>
* libc/include/machine/ieeefp.h: Add support for mmix target.
* libc/include/machine/setjmp.h: Ditto.
* configure.host: Ditto.
* libc/sys/mmixware/Makefile.am, libc/sys/mmixware/_exit.c,
libc/sys/mmixware/access.c, libc/sys/mmixware/aclocal.m4,
libc/sys/mmixware/chmod.c, libc/sys/mmixware/chown.c,
libc/sys/mmixware/close.c, libc/sys/mmixware/configure.in,
libc/sys/mmixware/creat.c, libc/sys/mmixware/crt0.c,
libc/sys/mmixware/execv.c, libc/sys/mmixware/execve.c,
libc/sys/mmixware/fork.c, libc/sys/mmixware/fstat.c,
libc/sys/mmixware/getpid.c, libc/sys/mmixware/gettime.c,
libc/sys/mmixware/isatty.c, libc/sys/mmixware/kill.c,
libc/sys/mmixware/lseek.c, libc/sys/mmixware/open.c,
libc/sys/mmixware/pipe.c, libc/sys/mmixware/read.c,
libc/sys/mmixware/sbrk.c, libc/sys/mmixware/setjmp.S,
libc/sys/mmixware/stat.c, libc/sys/mmixware/sys/syscall.h,
libc/sys/mmixware/time.c, libc/sys/mmixware/times.c,
libc/sys/mmixware/unlink.c, libc/sys/mmixware/utime.c,
libc/sys/mmixware/wait.c, libc/sys/mmixware/write.c: New files.
* libc/sys/mmixware/configure, libc/sys/mmixware/Makefile.in,
libc/sys/mmixware/aclocal.m4: Generate.
Diffstat (limited to 'newlib/libc/sys/mmixware/open.c')
-rw-r--r-- | newlib/libc/sys/mmixware/open.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/newlib/libc/sys/mmixware/open.c b/newlib/libc/sys/mmixware/open.c new file mode 100644 index 000000000..ec0d222d5 --- /dev/null +++ b/newlib/libc/sys/mmixware/open.c @@ -0,0 +1,106 @@ +/* open for MMIXware. + + Copyright (C) 2001 Hans-Peter Nilsson. + + Permission to use, copy, modify, and distribute this software is freely + granted, provided that this notice is preserved with no changes. + THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE. */ + +#include <fcntl.h> +#include <_ansi.h> +#include <sys/types.h> +#include <sys/stat.h> +#include "sys/syscall.h" +#include <errno.h> + +/* Let's keep the filehandle array here, since this is a primary + initializer of it. */ +unsigned char _MMIX_allocated_filehandle[32] = + { + 1, + 1, + 1, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 + }; + +int +_open (const char *path, + int flags, ...) +{ + long fileno; + unsigned char mode; + long fffile = 0; + long ret; + + for (fileno = 0; + fileno < (sizeof (_MMIX_allocated_filehandle) / + sizeof (_MMIX_allocated_filehandle[0])); + fileno++) + if (_MMIX_allocated_filehandle[fileno] == 0) + break; + + if (fileno == (sizeof (_MMIX_allocated_filehandle) / + sizeof (_MMIX_allocated_filehandle[0]))) + { + errno = EMFILE; + return -1; + } + + /* We map this to a fopen call. The flags parameter is stymied because + we don't support more other than these flags. */ + if (flags & ~(O_RDONLY | O_WRONLY | O_RDWR | O_CREAT | O_APPEND | O_TRUNC)) + { + UNIMPLEMENTED (("path: %s, flags: %d", path, flags)); + errno = ENOSYS; + return -1; + } + + if ((flags & O_ACCMODE) == O_RDONLY) + mode = BinaryRead; + else if ((flags & (O_WRONLY | O_APPEND)) == (O_WRONLY | O_APPEND)) + { + mode = BinaryReadWrite; + fffile = 1; + } + else if ((flags & (O_RDWR | O_APPEND)) == (O_RDWR | O_APPEND)) + { + mode = BinaryReadWrite; + fffile = 1; + } + else if ((flags & (O_WRONLY | O_CREAT)) == (O_WRONLY | O_CREAT) + || (flags & (O_WRONLY | O_TRUNC)) == (O_WRONLY | O_TRUNC)) + mode = BinaryWrite; + else if ((flags & (O_RDWR | O_CREAT)) == (O_RDWR | O_CREAT)) + mode = BinaryReadWrite; + else if (flags & O_RDWR) + mode = BinaryReadWrite; + else + { + errno = EINVAL; + return -1; + } + + ret = TRAP3f (SYS_Fopen, fileno, path, mode); + if (ret < 0) + { + /* It's totally unknown what the error was. We'll just take our + chances and assume ENOENT. */ + errno = ENOENT; + return -1; + } + + _MMIX_allocated_filehandle[fileno] = 1; + + if (fffile) + { + TRAP2f (SYS_Fseek, fileno, -1); + } + + return fileno; +} |