|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T f
Length: 4202 (0x106a)
Types: TextFile
Names: »fdx2ps.c«
└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
└─⟦eba4602b1⟧ »./isode-5.0.tar.Z«
└─⟦d3ac74d73⟧
└─⟦this⟧ »isode-5.0/psap/fdx2ps.c«
/* fdx2ps.c - full-duplex abstraction for PStreams */
#ifndef lint
static char *rcsid = "$Header: /f/osi/psap/RCS/fdx2ps.c,v 6.0 89/03/18 23:38:14 mrose Rel $";
#endif
/*
* $Header: /f/osi/psap/RCS/fdx2ps.c,v 6.0 89/03/18 23:38:14 mrose Rel $
*
*
* $Log: fdx2ps.c,v $
* Revision 6.0 89/03/18 23:38:14 mrose
* Release 5.0
*
*/
/*
* NOTICE
*
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
* this agreement.
*
*/
/* LINTLIBRARY */
#include <stdio.h>
#include "psap.h"
/* \f
DATA */
struct ps_fdx {
int ps_fd;
struct ps_inout {
char *pio_base;
int pio_bufsiz;
char *pio_ptr;
int pio_cnt;
} ps_input,
ps_output;
};
/* \f
*/
/* ARGSUSED */
static int fdx_read (ps, data, n, in_line)
register PS ps;
PElementData data;
PElementLen n;
int in_line;
{
int cc;
register struct ps_fdx *pt = (struct ps_fdx *) ps -> ps_addr;
register struct ps_inout *pi = &pt -> ps_input;
if ((cc = pi -> pio_cnt) <= 0) {
if (n > pi -> pio_bufsiz) {
if ((cc = read (pt -> ps_fd, (char *) data, n)) == NOTOK)
return ps_seterr (ps, PS_ERR_IO, NOTOK);
return cc;
}
if ((cc = read (pt -> ps_fd, pi -> pio_base, pi -> pio_bufsiz))
== NOTOK)
return ps_seterr (ps, PS_ERR_IO, NOTOK);
pi -> pio_ptr = pi -> pio_base, pi -> pio_cnt = cc;
}
if (cc > n)
cc = n;
bcopy (pi -> pio_ptr, (char *) data, cc);
pi -> pio_ptr += cc, pi -> pio_cnt -= cc;
return cc;
}
/* ARGSUSED */
static int fdx_write (ps, data, n, in_line)
register PS ps;
PElementData data;
PElementLen n;
int in_line;
{
int cc;
register struct ps_fdx *pt = (struct ps_fdx *) ps -> ps_addr;
register struct ps_inout *po = &pt -> ps_output;
#ifdef oldef
if (n > po -> pio_bufsiz) {
if (fdx_flush (ps) == NOTOK
|| (cc = write (pt -> ps_fd, (char *) data, n)) != n)
#else
if (n > po -> pio_bufsiz && po -> pio_ptr <= po -> pio_base) {
if ((cc = write (pt -> ps_fd, (char *) data, n)) != n)
#endif
return ps_seterr (ps, PS_ERR_IO, NOTOK);
return cc;
}
if (n > po -> pio_cnt)
n = po -> pio_cnt;
bcopy ((char *) data, po -> pio_ptr, n);
po -> pio_ptr += n, po -> pio_cnt -= n;
if (po -> pio_cnt <= 0 && fdx_flush (ps) == NOTOK)
return ps_seterr (ps, PS_ERR_IO, NOTOK);
return n;
}
static int fdx_flush (ps)
register PS ps;
{
int cc;
register struct ps_fdx *pt = (struct ps_fdx *) ps -> ps_addr;
register struct ps_inout *po = &pt -> ps_output;
if ((cc = po -> pio_ptr - po -> pio_base) <= 0)
return OK;
if (write (pt -> ps_fd, po -> pio_base, cc) != cc)
return ps_seterr (ps, PS_ERR_IO, NOTOK);
po -> pio_ptr = po -> pio_base, po -> pio_cnt = po -> pio_bufsiz;
return OK;
}
static int fdx_close (ps)
register PS ps;
{
register struct ps_fdx *pt = (struct ps_fdx *) ps -> ps_addr;
if (pt == NULL)
return OK;
if (pt -> ps_input.pio_base)
free (pt -> ps_input.pio_base);
if (pt -> ps_output.pio_base)
free (pt -> ps_output.pio_base);
free ((char *) pt);
return OK;
}
/* \f
*/
int fdx_open (ps)
register PS ps;
{
ps -> ps_readP = fdx_read;
ps -> ps_writeP = fdx_write;
ps -> ps_flushP = fdx_flush;
ps -> ps_closeP = fdx_close;
return OK;
}
int fdx_setup (ps, fd)
register PS ps;
int fd;
{
int pz;
register struct ps_fdx *pt;
if ((pt = (struct ps_fdx *) calloc (1, sizeof *pt)) == NULL)
return ps_seterr (ps, PS_ERR_NMEM, NOTOK);
ps -> ps_addr = (caddr_t) pt;
pt -> ps_fd = fd;
#ifdef BSD42
if ((pz = getpagesize ()) <= 0)
#endif
pz = BUFSIZ;
if ((pt -> ps_input.pio_base = malloc ((unsigned) pz)) == NULL
|| (pt -> ps_output.pio_base = malloc ((unsigned) pz)) == NULL)
return ps_seterr (ps, PS_ERR_NMEM, NOTOK);
pt -> ps_input.pio_bufsiz = pz, pt -> ps_output.pio_cnt = 0;
pt -> ps_input.pio_ptr = pt -> ps_input.pio_base;
pt -> ps_output.pio_bufsiz = pt -> ps_output.pio_cnt = pz;
pt -> ps_output.pio_ptr = pt -> ps_output.pio_base;
return OK;
}