Annotation of 43BSDReno/contrib/isode-beta/psap/ps_alloc.c, revision 1.1

1.1     ! root        1: /* ps_alloc.c - allocate a presentation stream */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/psap/RCS/ps_alloc.c,v 7.0 89/11/23 22:13:19 mrose Rel $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/psap/RCS/ps_alloc.c,v 7.0 89/11/23 22:13:19 mrose Rel $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       ps_alloc.c,v $
        !            12:  * Revision 7.0  89/11/23  22:13:19  mrose
        !            13:  * Release 6.0
        !            14:  * 
        !            15:  */
        !            16: 
        !            17: /*
        !            18:  *                               NOTICE
        !            19:  *
        !            20:  *    Acquisition, use, and distribution of this module and related
        !            21:  *    materials are subject to the restrictions of a license agreement.
        !            22:  *    Consult the Preface in the User's Manual for the full terms of
        !            23:  *    this agreement.
        !            24:  *
        !            25:  */
        !            26: 
        !            27: 
        !            28: /* LINTLIBRARY */
        !            29: 
        !            30: #include <stdio.h>
        !            31: #include "psap.h"
        !            32: 
        !            33: 
        !            34: /* A Presentatation Stream (or PStream) is the second generation of
        !            35:    "generic" I/O stream-based handling.  (For the first attempt,
        !            36:    take a look at the prototype implementation of the TTI Trusted Mail
        !            37:    Agent.)  The idea is to present a common, simple I/O paradigm (i.e.,
        !            38:    the UNIX v7 philosophy) to protocol-translation entities regardless of
        !            39:    the underlying medium (files, pipes, sockets, or strings).
        !            40: 
        !            41:    New streams are created by a call to ps_alloc().  It allocates memory
        !            42:    and calls an open routine.  This routine fills in the dispatch vectors
        !            43:    for read/write and (optionally) close.  It can also fill in any other
        !            44:    part of the stream's structure it likes.
        !            45: 
        !            46:    Once created, I/O is done using the macros ps_read/ps_write.  These
        !            47:    return either NOTOK or OK; depending on how things went. The read/write
        !            48:    routines are invoked as:
        !            49: 
        !            50:        int     iofunc (ps, data, n, in_line)
        !            51:        PS      ps;
        !            52:        PElementData data;
        !            53:        PElementLen  n;
        !            54:        int     in_line;
        !            55: 
        !            56:    They should read/write upto len bytes, starting at data, and return the
        !            57:    number of bytes processed, or NOTOK on error.  The routine ps_io() will
        !            58:    make successive calls to fill/flush the data.  If the read/write routine
        !            59:    returns NOTOK, it should set ps_errno as well.
        !            60: 
        !            61:    Streams are removed by a call to ps_free ().  It calls the close
        !            62:    routine, if any, which should de-commission any parts of the stream's
        !            63:    structure that are in use.  ps_free() will then free the allocated
        !            64:    memory.
        !            65:  */
        !            66: 
        !            67: /*  */
        !            68: 
        !            69: PS     ps_alloc (io)
        !            70: register IFP   io;
        !            71: {
        !            72:     register PS            ps;
        !            73: 
        !            74:     if ((ps = (PS) calloc (1, sizeof *ps)) == NULLPS)
        !            75:        return NULLPS;
        !            76: 
        !            77:     if ((*io) (ps) == NOTOK) {
        !            78:        ps_free (ps);
        !            79:        return NULLPS;
        !            80:     }
        !            81: 
        !            82:     return ps;
        !            83: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.