summaryrefslogtreecommitdiff
path: root/com32/lib/sys/open.c
diff options
context:
space:
mode:
Diffstat (limited to 'com32/lib/sys/open.c')
-rw-r--r--com32/lib/sys/open.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/com32/lib/sys/open.c b/com32/lib/sys/open.c
index 3f84e5f7..27c22cec 100644
--- a/com32/lib/sys/open.c
+++ b/com32/lib/sys/open.c
@@ -1,7 +1,7 @@
#ident "$Id$"
/* ----------------------------------------------------------------------- *
*
- * Copyright 2003 H. Peter Anvin - All Rights Reserved
+ * Copyright 2003-2004 H. Peter Anvin - All Rights Reserved
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
@@ -29,27 +29,40 @@
#include <errno.h>
#include <com32.h>
#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
#include "file.h"
-int open(const char *pathname, int flags, mode_t mode)
+/*
+ * open.c
+ *
+ * Open an ordinary file
+ */
+
+extern ssize_t __file_read(struct file_info *, void *, size_t);
+extern int __file_close(struct file_info *);
+
+static const struct dev_info file_dev = {
+ .dev_magic = __DEV_MAGIC,
+ .flags = __DEV_FILE,
+ .fileflags = O_RDONLY,
+ .read = __file_read,
+ .write = NULL, /* File writes are not supported */
+ .close = __file_close,
+};
+
+int open(const char *pathname, int flags, ...)
{
com32sys_t regs;
int fd;
struct file_info *fp;
-
- if ( flags ) {
- errno = EINVAL;
- return -1;
- }
- for ( fd = 0, fp = __file_info ; fd < NFILES ; fd++, fp++ )
- if ( fp->blocklg2 == 0 )
- break;
+ fd = opendev(&file_dev, flags);
- if ( fd >= NFILES ) {
- errno = EMFILE;
+ if ( fd < 0 )
return -1;
- }
+
+ fp = &__file_info[fd];
strlcpy(__com32.cs_bounce, pathname, __com32.cs_bounce_size);
@@ -67,13 +80,13 @@ int open(const char *pathname, int flags, mode_t mode)
{
uint16_t blklg2;
asm("bsrw %1,%0" : "=r" (blklg2) : "rm" (regs.ecx.w[0]));
- fp->blocklg2 = blklg2;
+ fp->p.f.blocklg2 = blklg2;
}
- fp->length = regs.eax.l;
- fp->filedes = regs.esi.w[0];
- fp->offset = 0;
- fp->nbytes = 0;
- fp->datap = fp->buf;
+ fp->p.f.length = regs.eax.l;
+ fp->p.f.filedes = regs.esi.w[0];
+ fp->p.f.offset = 0;
+ fp->p.f.nbytes = 0;
+ fp->p.f.datap = fp->p.f.buf;
return fd;
}