roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Module      :   mem_file.c
roentgen b75cab
-   Description :   A general purpose library for manipulating a memory area
roentgen b75cab
-                   as if it were a file.
roentgen b75cab
-                   mfs_ stands for memory file system.
roentgen b75cab
-   Author      :   Mike Johnson - Banctec AB 03/07/96
roentgen b75cab
-                   
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
/* 
roentgen b75cab
roentgen b75cab
Copyright (c) 1996 Mike Johnson
roentgen b75cab
Copyright (c) 1996 BancTec AB
roentgen b75cab
roentgen b75cab
Permission to use, copy, modify, distribute, and sell this software
roentgen b75cab
for any purpose is hereby granted without fee, provided
roentgen b75cab
that (i) the above copyright notices and this permission notice appear in
roentgen b75cab
all copies of the software and related documentation, and (ii) the names of
roentgen b75cab
Mike Johnson and BancTec may not be used in any advertising or
roentgen b75cab
publicity relating to the software.
roentgen b75cab
roentgen b75cab
THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
roentgen b75cab
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
roentgen b75cab
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
roentgen b75cab
roentgen b75cab
IN NO EVENT SHALL MIKE JOHNSON OR BANCTEC BE LIABLE FOR
roentgen b75cab
ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
roentgen b75cab
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
roentgen b75cab
WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
roentgen b75cab
LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
roentgen b75cab
OF THIS SOFTWARE.
roentgen b75cab
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Includes
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
#include    <stdio.h></stdio.h>
roentgen b75cab
#include    <stdlib.h></stdlib.h>
roentgen b75cab
#include    <string.h></string.h>
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Definitions
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
#define MAX_BUFFS   20
roentgen b75cab
#define FALSE       0
roentgen b75cab
#define TRUE        1
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Globals
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
static char *buf[MAX_BUFFS];        /* Memory for each open buf */
roentgen b75cab
static long  buf_off[MAX_BUFFS];    /* File pointer for each buf */
roentgen b75cab
static long  buf_size[MAX_BUFFS];   /* Count of bytes allocated for each buf */
roentgen b75cab
static long  fds[MAX_BUFFS];        /* File descriptor status */
roentgen b75cab
static int   buf_mode[MAX_BUFFS];   /* Mode of buffer (r, w, a) */
roentgen b75cab
roentgen b75cab
static int library_init_done = FALSE;
roentgen b75cab
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Function prototypes
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
int mfs_open (void *ptr, int size, char *mode);
roentgen b75cab
int mfs_lseek (int fd, int offset, int whence);
roentgen b75cab
int mfs_read (int fd, void *buf, int size);
roentgen b75cab
int mfs_write (int fd, void *buf, int size);
roentgen b75cab
int mfs_size (int fd);
roentgen b75cab
int mfs_map (int fd, char **addr, size_t *len);
roentgen b75cab
int mfs_unmap (int fd);
roentgen b75cab
int mfs_close (int fd);
roentgen b75cab
static int extend_mem_file (int fd, int size);
roentgen b75cab
static void mem_init ();
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Function code
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Function    :   mfs_open ()
roentgen b75cab
-
roentgen b75cab
-   Arguments   :   Pointer to allocated buffer, initial size of buffer, 
roentgen b75cab
-                   mode spec (r, w, a)
roentgen b75cab
-
roentgen b75cab
-   Returns     :   File descriptor or -1 if error.
roentgen b75cab
-
roentgen b75cab
-   Description :   Register this area of memory (which has been allocated
roentgen b75cab
-                   and has a file read into it) under the mem_file library.
roentgen b75cab
-                   A file descriptor is returned which can the be passed
roentgen b75cab
-                   back to TIFFClientOpen and used as if it was a disk
roentgen b75cab
-                   based fd.
roentgen b75cab
-                   If the call is for mode 'w' then pass (void *)NULL as
roentgen b75cab
-                   the buffer and zero size and the library will 
roentgen b75cab
-                   allocate memory for you.
roentgen b75cab
-                   If the mode is append then pass (void *)NULL and size
roentgen b75cab
-                   zero or with a valid address.
roentgen b75cab
-                   
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
int mfs_open (void *buffer, int size, char *mode)
roentgen b75cab
{
roentgen b75cab
    int ret, i;
roentgen b75cab
    void *tmp;
roentgen b75cab
roentgen b75cab
    if (library_init_done == FALSE)
roentgen b75cab
    {
roentgen b75cab
        mem_init ();
roentgen b75cab
        library_init_done = TRUE;
roentgen b75cab
    }
roentgen b75cab
roentgen b75cab
    ret = -1;
roentgen b75cab
roentgen b75cab
    /* Find a free fd */
roentgen b75cab
roentgen b75cab
    for (i = 0; i < MAX_BUFFS; i++)
roentgen b75cab
    {
roentgen b75cab
        if (fds[i] == -1)
roentgen b75cab
        {
roentgen b75cab
            ret = i;
roentgen b75cab
            break;
roentgen b75cab
        }
roentgen b75cab
    }
roentgen b75cab
roentgen b75cab
    if (i == MAX_BUFFS)     /* No more free descriptors */
roentgen b75cab
    {
roentgen b75cab
        ret = -1;
roentgen b75cab
        errno = EMFILE;
roentgen b75cab
    }
roentgen b75cab
roentgen b75cab
    if (ret >= 0 && *mode == 'r')
roentgen b75cab
    {
roentgen b75cab
        if (buffer == (void *)NULL)
roentgen b75cab
        {
roentgen b75cab
            ret = -1;
roentgen b75cab
            errno = EINVAL;
roentgen b75cab
        }
roentgen b75cab
        else
roentgen b75cab
        {
roentgen b75cab
            buf[ret] = (char *)buffer;
roentgen b75cab
            buf_size[ret] = size;
roentgen b75cab
            buf_off[ret] = 0;
roentgen b75cab
        }
roentgen b75cab
    }
roentgen b75cab
    else if (ret >= 0 && *mode == 'w')
roentgen b75cab
    {
roentgen b75cab
roentgen b75cab
        if (buffer != (void *)NULL)
roentgen b75cab
        {
roentgen b75cab
            ret = -1;
roentgen b75cab
            errno = EINVAL;
roentgen b75cab
        }
roentgen b75cab
roentgen b75cab
        else
roentgen b75cab
        {
roentgen b75cab
            tmp = malloc (0);   /* Get a pointer */
roentgen b75cab
            if (tmp == (void *)NULL)
roentgen b75cab
            {
roentgen b75cab
                ret = -1;
roentgen b75cab
                errno = EDQUOT;
roentgen b75cab
            }
roentgen b75cab
            else
roentgen b75cab
            {
roentgen b75cab
                buf[ret] = (char *)tmp;
roentgen b75cab
                buf_size[ret] = 0;
roentgen b75cab
                buf_off[ret] = 0;
roentgen b75cab
            }
roentgen b75cab
        }
roentgen b75cab
    }
roentgen b75cab
    else if (ret >= 0 && *mode == 'a')
roentgen b75cab
    {
roentgen b75cab
        if (buffer == (void *) NULL)    /* Create space for client */
roentgen b75cab
        {
roentgen b75cab
            tmp = malloc (0);   /* Get a pointer */
roentgen b75cab
            if (tmp == (void *)NULL)
roentgen b75cab
            {
roentgen b75cab
                ret = -1;
roentgen b75cab
                errno = EDQUOT;
roentgen b75cab
            }
roentgen b75cab
            else
roentgen b75cab
            {
roentgen b75cab
                buf[ret] = (char *)tmp;
roentgen b75cab
                buf_size[ret] = 0;
roentgen b75cab
                buf_off[ret] = 0;
roentgen b75cab
            }
roentgen b75cab
        }
roentgen b75cab
        else                            /* Client has file read in already */
roentgen b75cab
        {
roentgen b75cab
            buf[ret] = (char *)buffer;
roentgen b75cab
            buf_size[ret] = size;
roentgen b75cab
            buf_off[ret] = 0;
roentgen b75cab
        }
roentgen b75cab
    }
roentgen b75cab
    else        /* Some other invalid combination of parameters */
roentgen b75cab
    {
roentgen b75cab
        ret = -1;
roentgen b75cab
        errno = EINVAL;
roentgen b75cab
    }
roentgen b75cab
roentgen b75cab
    if (ret != -1)
roentgen b75cab
    {
roentgen b75cab
        fds[ret] = 0;
roentgen b75cab
        buf_mode[ret] = *mode;
roentgen b75cab
    }
roentgen b75cab
roentgen b75cab
    return (ret);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Function    :   mfs_lseek ()
roentgen b75cab
-
roentgen b75cab
-   Arguments   :   File descriptor, offset, whence
roentgen b75cab
-
roentgen b75cab
-   Returns     :   as per man lseek (2)
roentgen b75cab
-
roentgen b75cab
-   Description :   Does the same as lseek (2) except on a memory based file.
roentgen b75cab
-                   Note: the memory area will be extended if the caller
roentgen b75cab
-                   attempts to seek past the current end of file (memory).
roentgen b75cab
-                   
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
int mfs_lseek (int fd, int offset, int whence)
roentgen b75cab
{
roentgen b75cab
    int ret;
roentgen b75cab
    long test_off;
roentgen b75cab
roentgen b75cab
    if (fds[fd] == -1)  /* Not open */
roentgen b75cab
    {
roentgen b75cab
        ret = -1;
roentgen b75cab
        errno = EBADF;
roentgen b75cab
    }
roentgen b75cab
    else if (offset < 0 && whence == SEEK_SET)
roentgen b75cab
    {
roentgen b75cab
        ret = -1;
roentgen b75cab
        errno = EINVAL;
roentgen b75cab
    }
roentgen b75cab
    else
roentgen b75cab
    {
roentgen b75cab
        switch (whence)
roentgen b75cab
        {
roentgen b75cab
            case SEEK_SET:
roentgen b75cab
                if (offset > buf_size[fd])
roentgen b75cab
                    extend_mem_file (fd, offset);
roentgen b75cab
                buf_off[fd] = offset;
roentgen b75cab
                ret = offset;
roentgen b75cab
                break;
roentgen b75cab
roentgen b75cab
            case SEEK_CUR:
roentgen b75cab
                test_off = buf_off[fd] + offset;
roentgen b75cab
roentgen b75cab
                if (test_off < 0)
roentgen b75cab
                {
roentgen b75cab
                    ret = -1;
roentgen b75cab
                    errno = EINVAL;
roentgen b75cab
                }
roentgen b75cab
                else
roentgen b75cab
                {
roentgen b75cab
                    if (test_off > buf_size[fd])
roentgen b75cab
                        extend_mem_file (fd, test_off);
roentgen b75cab
                    buf_off[fd] = test_off;
roentgen b75cab
                    ret = test_off;
roentgen b75cab
                }
roentgen b75cab
                break;
roentgen b75cab
roentgen b75cab
            case SEEK_END:
roentgen b75cab
                test_off = buf_size[fd] + offset;
roentgen b75cab
roentgen b75cab
                if (test_off < 0)
roentgen b75cab
                {
roentgen b75cab
                    ret = -1;
roentgen b75cab
                    errno = EINVAL;
roentgen b75cab
                }
roentgen b75cab
                else
roentgen b75cab
                {
roentgen b75cab
                    if (test_off > buf_size[fd])
roentgen b75cab
                        extend_mem_file (fd, test_off);
roentgen b75cab
                    buf_off[fd] = test_off;
roentgen b75cab
                    ret = test_off;
roentgen b75cab
                }
roentgen b75cab
                break;
roentgen b75cab
roentgen b75cab
            default:
roentgen b75cab
                errno = EINVAL;
roentgen b75cab
                ret = -1;
roentgen b75cab
                break;
roentgen b75cab
        }
roentgen b75cab
    }
roentgen b75cab
roentgen b75cab
    return (ret);
roentgen b75cab
}   
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Function    :   mfs_read ()
roentgen b75cab
-
roentgen b75cab
-   Arguments   :   File descriptor, buffer, size
roentgen b75cab
-
roentgen b75cab
-   Returns     :   as per man read (2)
roentgen b75cab
-
roentgen b75cab
-   Description :   Does the same as read (2) except on a memory based file.
roentgen b75cab
-                   Note: An attempt to read past the end of memory currently
roentgen b75cab
-                   allocated to the file will return 0 (End Of File)
roentgen b75cab
-                   
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
int mfs_read (int fd, void *clnt_buf, int size)
roentgen b75cab
{
roentgen b75cab
    int ret;
roentgen b75cab
roentgen b75cab
    if (fds[fd] == -1 || buf_mode[fd] != 'r')
roentgen b75cab
    {
roentgen b75cab
        /* File is either not open, or not opened for read */
roentgen b75cab
roentgen b75cab
        ret = -1;
roentgen b75cab
        errno = EBADF;
roentgen b75cab
    }
roentgen b75cab
    else if (buf_off[fd] + size > buf_size[fd])
roentgen b75cab
    {
roentgen b75cab
        ret = 0;        /* EOF */
roentgen b75cab
    }
roentgen b75cab
    else
roentgen b75cab
    {
roentgen b75cab
        memcpy (clnt_buf, (void *) (buf[fd] + buf_off[fd]), size);
roentgen b75cab
        buf_off[fd] = buf_off[fd] + size;
roentgen b75cab
        ret = size;
roentgen b75cab
    }
roentgen b75cab
roentgen b75cab
    return (ret);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Function    :   mfs_write ()
roentgen b75cab
-
roentgen b75cab
-   Arguments   :   File descriptor, buffer, size
roentgen b75cab
-
roentgen b75cab
-   Returns     :   as per man write (2)
roentgen b75cab
-
roentgen b75cab
-   Description :   Does the same as write (2) except on a memory based file.
roentgen b75cab
-                   Note: the memory area will be extended if the caller
roentgen b75cab
-                   attempts to write past the current end of file (memory).
roentgen b75cab
-                   
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
int mfs_write (int fd, void *clnt_buf, int size)
roentgen b75cab
{
roentgen b75cab
    int ret;
roentgen b75cab
roentgen b75cab
    if (fds[fd] == -1 || buf_mode[fd] == 'r')
roentgen b75cab
    {
roentgen b75cab
        /* Either the file is not open or it is opened for reading only */
roentgen b75cab
roentgen b75cab
        ret = -1;
roentgen b75cab
        errno = EBADF;
roentgen b75cab
    }
roentgen b75cab
    else if (buf_mode[fd] == 'w')
roentgen b75cab
    {
roentgen b75cab
        /* Write */
roentgen b75cab
roentgen b75cab
        if (buf_off[fd] + size > buf_size[fd])
roentgen b75cab
        {       
roentgen b75cab
            extend_mem_file (fd, buf_off[fd] + size);
roentgen b75cab
            buf_size[fd] = (buf_off[fd] + size);
roentgen b75cab
        }
roentgen b75cab
roentgen b75cab
        memcpy ((buf[fd] + buf_off[fd]), clnt_buf, size);
roentgen b75cab
        buf_off[fd] = buf_off[fd] + size;
roentgen b75cab
roentgen b75cab
        ret = size;
roentgen b75cab
    }
roentgen b75cab
    else
roentgen b75cab
    {
roentgen b75cab
        /* Append */
roentgen b75cab
roentgen b75cab
        if (buf_off[fd] != buf_size[fd])
roentgen b75cab
            buf_off[fd] = buf_size[fd];
roentgen b75cab
roentgen b75cab
        extend_mem_file (fd, buf_off[fd] + size);
roentgen b75cab
        buf_size[fd] += size;
roentgen b75cab
roentgen b75cab
        memcpy ((buf[fd] + buf_off[fd]), clnt_buf, size);
roentgen b75cab
        buf_off[fd] = buf_off[fd] + size;
roentgen b75cab
roentgen b75cab
        ret = size;
roentgen b75cab
    }
roentgen b75cab
roentgen b75cab
    return (ret);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Function    :   mfs_size ()
roentgen b75cab
-
roentgen b75cab
-   Arguments   :   File descriptor
roentgen b75cab
-
roentgen b75cab
-   Returns     :   integer file size
roentgen b75cab
-
roentgen b75cab
-   Description :   This function returns the current size of the file in bytes.
roentgen b75cab
-                   
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
int mfs_size (int fd)
roentgen b75cab
{
roentgen b75cab
    int ret;
roentgen b75cab
roentgen b75cab
    if (fds[fd] == -1)  /* Not open */
roentgen b75cab
    {
roentgen b75cab
        ret = -1;
roentgen b75cab
        errno = EBADF;
roentgen b75cab
    }
roentgen b75cab
    else
roentgen b75cab
        ret = buf_size[fd];
roentgen b75cab
roentgen b75cab
    return (ret);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Function    :   mfs_map ()
roentgen b75cab
-
roentgen b75cab
-   Arguments   :   File descriptor, ptr to address, ptr to length
roentgen b75cab
-
roentgen b75cab
-   Returns     :   Map status (succeeded or otherwise)
roentgen b75cab
-
roentgen b75cab
-   Description :   This function tells the client where the file is mapped
roentgen b75cab
-                   in memory and what size the mapped area is. It is provided
roentgen b75cab
-                   to satisfy the MapProc function in libtiff. It pretends
roentgen b75cab
-                   that the file has been mmap (2)ped.
roentgen b75cab
-                   
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
int mfs_map (int fd, char **addr, size_t *len)
roentgen b75cab
{
roentgen b75cab
    int ret; 
roentgen b75cab
roentgen b75cab
    if (fds[fd] == -1)  /* Not open */
roentgen b75cab
    {
roentgen b75cab
        ret = -1;
roentgen b75cab
        errno = EBADF;
roentgen b75cab
    }
roentgen b75cab
    else
roentgen b75cab
    {
roentgen b75cab
        *addr = buf[fd];
roentgen b75cab
        *len = buf_size[fd];
roentgen b75cab
        ret = 0;
roentgen b75cab
    }
roentgen b75cab
roentgen b75cab
    return (ret);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Function    :   mfs_unmap ()
roentgen b75cab
-
roentgen b75cab
-   Arguments   :   File descriptor
roentgen b75cab
-
roentgen b75cab
-   Returns     :   UnMap status (succeeded or otherwise)
roentgen b75cab
-
roentgen b75cab
-   Description :   This function does nothing as the file is always
roentgen b75cab
-                   in memory.
roentgen b75cab
-                   
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
int mfs_unmap (int fd)
roentgen b75cab
{
roentgen b75cab
    return (0);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Function    :   mfs_close ()
roentgen b75cab
-
roentgen b75cab
-   Arguments   :   File descriptor
roentgen b75cab
-
roentgen b75cab
-   Returns     :   close status (succeeded or otherwise)
roentgen b75cab
-
roentgen b75cab
-   Description :   Close the open memory file. (Make fd available again.)
roentgen b75cab
-                   
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
int mfs_close (int fd)
roentgen b75cab
{
roentgen b75cab
    int ret; 
roentgen b75cab
roentgen b75cab
    if (fds[fd] == -1)  /* Not open */
roentgen b75cab
    {
roentgen b75cab
        ret = -1;
roentgen b75cab
        errno = EBADF;
roentgen b75cab
    }
roentgen b75cab
    else
roentgen b75cab
    {
roentgen b75cab
        fds[fd] = -1;
roentgen b75cab
        ret = 0;
roentgen b75cab
    }
roentgen b75cab
roentgen b75cab
    return (ret);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Function    :   extend_mem_file ()
roentgen b75cab
-
roentgen b75cab
-   Arguments   :   File descriptor, length to extend to.
roentgen b75cab
-
roentgen b75cab
-   Returns     :   0 - All OK, -1 - realloc () failed.
roentgen b75cab
-
roentgen b75cab
-   Description :   Increase the amount of memory allocated to a file.
roentgen b75cab
-                   
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
static int extend_mem_file (int fd, int size)
roentgen b75cab
{
roentgen b75cab
    void *new_mem;
roentgen b75cab
    int ret;
roentgen b75cab
roentgen b75cab
    if ((new_mem = realloc (buf[fd], size)) == (void *) NULL)
roentgen b75cab
        ret = -1;
roentgen b75cab
    else
roentgen b75cab
    {
roentgen b75cab
        buf[fd] = (char *) new_mem;
roentgen b75cab
        ret = 0;
roentgen b75cab
    }
roentgen b75cab
roentgen b75cab
    return (ret);
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
-   Function    :   mem_init ()
roentgen b75cab
-
roentgen b75cab
-   Arguments   :   None
roentgen b75cab
-
roentgen b75cab
-   Returns     :   void
roentgen b75cab
-
roentgen b75cab
-   Description :   Initialise the library.
roentgen b75cab
-                   
roentgen b75cab
--------------------------------------------------------------------------------
roentgen b75cab
*/
roentgen b75cab
roentgen b75cab
static void mem_init ()
roentgen b75cab
{
roentgen b75cab
    int i;
roentgen b75cab
roentgen b75cab
    for (i = 0; i < MAX_BUFFS; i++)
roentgen b75cab
    {
roentgen b75cab
        fds[i] = -1;
roentgen b75cab
        buf[i] = (char *)NULL;
roentgen b75cab
        buf_size[i] = 0;
roentgen b75cab
        buf_off[i] = 0;
roentgen b75cab
    }
roentgen b75cab
}
roentgen b75cab
roentgen b75cab
/*
roentgen b75cab
 * Local Variables:
roentgen b75cab
 * mode: c
roentgen b75cab
 * c-basic-offset: 8
roentgen b75cab
 * fill-column: 78
roentgen b75cab
 * End:
roentgen b75cab
 */