/* uvec2ps.c - uvec-backed abstraction for PStreams */
static char *rcsid
= "$Header: /f/osi/psap/RCS/uvec2ps.c,v 7.1 91/02/22 09:37:18 mrose Interim $";
* $Header: /f/osi/psap/RCS/uvec2ps.c,v 7.1 91/02/22 09:37:18 mrose Interim $
* Revision 7.1 91/02/22 09:37:18 mrose
* Revision 7.0 89/11/23 22:13:58 mrose
* 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
#define NPSUV 10 /* really should be NSPUV - 2 */
#define PSDU_MAGIC 64 /* threshold for scattering */
static int uvec_write (ps
, data
, n
, in_line
)
register struct udvec
*uv
;
if (in_line
&& n
< PSDU_MAGIC
)
if (in_line
&& ps
-> ps_cur
-> uv_base
)
if (ps
-> ps_cur
>= ps
-> ps_end
) {
SLOG (psap_log
, LLOG_DEBUG
, NULLCP
,
("%d elements not enough for pe2uvec", ps
-> ps_elems
));
if ((uv
= (struct udvec
*) realloc ((char *) ps
-> ps_head
,
(unsigned) (ps
-> ps_elems
return ps_seterr (ps
, PS_ERR_NMEM
, NOTOK
);
ps
-> ps_cur
= uv
+ (ps
-> ps_cur
- ps
-> ps_head
);
ps
-> ps_end
= (ps
-> ps_head
= uv
) + ps
-> ps_elems
- 1;
SLOG (psap_log
, LLOG_EXCEPTIONS
, NULLCP
,
("first write in pe2uvec is inline"));
return ps_seterr (ps
, PS_ERR_EOF
, NOTOK
);
uv
-> uv_base
= (char *) data
, uv
-> uv_len
= n
;
(++ps
-> ps_cur
) -> uv_base
= NULL
;
SLOG (psap_log
, LLOG_EXCEPTIONS
, NULLCP
,
("insufficient slop in pe2uvec, at least %d octets short",
return ps_seterr (ps
, PS_ERR_EOF
, NOTOK
);
if (uv
-> uv_base
== NULL
) {
uv
-> uv_base
= ps
-> ps_extra
, uv
-> uv_len
= 0;
uv
-> uv_inline
= ps
-> ps_cc
> 0 ? 1 : 0;
bcopy ((char *) data
, ps
-> ps_extra
, n
);
ps
-> ps_extra
+= n
, ps
-> ps_slop
-= n
;
static int uvec_flush (ps
)
if (ps
-> ps_cur
-> uv_base
)
ps
-> ps_cur
-> uv_base
= NULL
;
SLOG (psap_log
, LLOG_EXCEPTIONS
, NULLCP
,
("%d octets of slop remaining on pe2uvec flush", ps
-> ps_slop
));
static int uvec_close (ps
)
register struct udvec
*uv
;
for (uv
= ps
-> ps_head
; uv
-> uv_base
; uv
++)
free ((char *) ps
-> ps_head
);
if (ps
-> ps_extra
&& ps
-> ps_cc
== 0)
ps
-> ps_writeP
= uvec_write
;
ps
-> ps_flushP
= uvec_flush
;
ps
-> ps_closeP
= uvec_close
;
register struct udvec
*uv
;
if ((uv
= (struct udvec
*) calloc ((unsigned) ps
-> ps_elems
, sizeof *uv
))
return ps_seterr (ps
, PS_ERR_NMEM
, NOTOK
);
ps
-> ps_end
= (ps
-> ps_head
= ps
-> ps_cur
= uv
) + ps
-> ps_elems
- 1;
if ((ps
-> ps_slop
= len
) <= 0)
SLOG (psap_log
, LLOG_EXCEPTIONS
, NULLCP
,
("bad initial slop in pe2uvec, %d octets", len
));
if ((ps
-> ps_extra
= malloc ((unsigned) len
)) == NULL
)
return ps_seterr (ps
, PS_ERR_NMEM
, NOTOK
);
register PElementLen len
;
if (pe
-> pe_len
>= PSDU_MAGIC
)
for (p
= pe
-> pe_cons
; p
; p
= p
-> pe_next
)