home *** CD-ROM | disk | FTP | other *** search
- /*
- * c-tree server for netbios
- * open, sopen, read, write, lseek, close for netbios servers
- *
- * !!DOES NOT SUPPORT fstat()!!
- *
- * This program is the CONFIDENTIAL and PROPRIETARY property
- * of FairCom(R) Corporation. Any unauthorized use, reproduction or
- * transfer of this program is strictly prohibited.
- *
- * Copyright (c) 1987, 1988, 1989 FairCom Corporation
- * (Subject to limited distribution and
- * restricted disclosure only.)
- * *** ALL RIGHTS RESERVED ***
- *
- * 4006 West Broadway
- * Columbia, MO 65203
- *
- *
- * c-tree(R) Version 4.3
- * Release C
- * February 7, 1989 17:30
- *
- */
-
- #include <stdio.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <sys\types.h>
- #include <sys\stat.h>
- #include <share.h>
- #include <dos.h> /* cpu regs structure */
-
- extern int errno;
-
- /*** variables for passing CPU regs to/from intdos ***/
- static union REGS r;
- static struct SREGS sr;
-
-
- /*
- * sopen
- */
-
- /* binary mode is assumed for sopen and open */
- /* pmode ignored */
-
- int sopen(path, oflag, shflag, pmode)
- char *path;
- int oflag, shflag, pmode;
- {
- long lseek();
- int cmd, access, handle;
- char far *lp;
- lp = (char far *) path;
- if (oflag & O_RDONLY)
- access = 0;
- else if (oflag & O_WRONLY)
- access = 1;
- else
- access = 2;
- switch (shflag)
- {
- case SH_DENYRW: access |= 0x10; break;
- case SH_DENYWR: access |= 0x20; break;
- case SH_DENYRD: access |= 0x30; break;
- case SH_DENYNO: access |= 0x40; break;
- default: access |= 0;
- }
- if (oflag & O_CREAT)
- {
- if (oflag & O_EXCL)
- cmd = 0x5b00; /* create new */
- else
- cmd = 0x3c00;
- }
- else /* not create */
- {
- cmd = 0x3d00 | access;
- }
- r.x.ax = cmd;
- r.x.cx = 0;
- r.x.dx = FP_OFF(lp);
- sr.ds = FP_SEG(lp);
- intdosx(&r, &r, &sr);
- if (r.x.cflag)
- {
- if (r.x.ax == 0x50)
- errno = EEXIST;
- else if (r.x.ax == 4)
- errno = EMFILE;
- else if (r.x.ax == 0x20)
- errno = EACCES;
- else
- errno = ENOENT;
- return -1;
- }
- else
- {
- handle = r.x.ax;
- if (0x3d00 == (cmd & 0xff00))
- {
- if (oflag & O_TRUNC)
- write(handle, (char *)&cmd, 0); /* truncates file */
- else if (oflag & O_APPEND)
- lseek(handle, 0L, 2);
- }
- return handle;
- }
- }
-
- /*
- * open
- */
-
- int open(path, oflag, pmode)
- char *path;
- int oflag, pmode;
- {
- return sopen(path, oflag, 0, pmode);
- }
-
- /*
- * read
- */
-
- int read(handle, buffer, count)
- int handle;
- char *buffer;
- int count;
- {
- char far *lp;
- lp = (char far *) buffer;
- r.x.ax = 0x3f00;
- r.x.bx = handle;
- r.x.cx = count;
- r.x.dx = FP_OFF(lp);
- sr.ds = FP_SEG(lp);
- intdosx(&r, &r, &sr);
- if (r.x.cflag)
- {
- errno = EBADF;
- return -1;
- }
- else
- return r.x.ax; /* num bytes actually read */
- }
-
- /*
- * write
- */
-
- int write(handle, buffer, count)
- int handle;
- char *buffer;
- int count;
- {
- char far *lp;
- lp = (char far *) buffer;
- r.x.ax = 0x4000;
- r.x.bx = handle;
- r.x.cx = count;
- r.x.dx = FP_OFF(lp);
- sr.ds = FP_SEG(lp);
- intdosx(&r, &r, &sr);
- if (r.x.cflag)
- {
- errno = EBADF;
- return -1;
- }
- else
- {
- if (r.x.ax != count)
- {
- errno = ENOSPC;
- return -1;
- }
- else
- return r.x.ax; /* num bytes actually read */
- }
- }
-
- /*
- * lseek
- */
-
- long lseek(handle, offset, origin)
- int handle;
- long offset;
- int origin;
- {
- r.x.ax = 0x4200 | origin;
- r.x.bx = handle;
- /*
- r.x.dx = (int) origin;
- r.x.cx = (int) (origin >> 16);
- */
- r.x.dx = (int) offset;
- r.x.cx = (int) (offset >> 16);
- intdos(&r, &r);
- if (r.x.cflag)
- {
- errno = (r.x.ax == 6) ? EBADF : EINVAL;
- return -1l;
- }
- else
- return (((long) r.x.dx) << 16) + ((long) (unsigned) r.x.ax);
- }
-
-
- /*
- * close
- */
-
- int close(handle)
- int handle;
- {
- r.x.ax = 0x3e00;
- r.x.bx = handle;
- intdos(&r, &r);
- if (r.x.cflag)
- {
- errno = EBADF;
- return -1;
- }
- else
- return 0;
- }
-
- /* end of ctrfio.c */
-