--- libaitio/src/bufio.c 2014/02/08 22:06:17 1.9 +++ libaitio/src/bufio.c 2016/08/11 12:25:51 1.9.8.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: bufio.c,v 1.9 2014/02/08 22:06:17 misho Exp $ +* $Id: bufio.c,v 1.9.8.1 2016/08/11 12:25:51 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2014 +Copyright 2004 - 2016 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -53,6 +53,7 @@ unmap_cf(struct tagBufIO *buf) munmap(buf->buf_base, buf->buf_size); } +#ifndef __linux__ static int cf_(struct tagBufIO *buf) { @@ -240,6 +241,7 @@ wf_inf(struct tagBufIO *buf, const char *dat, int siz) buf->buf_offset += siz; return siz; } +#endif /* @@ -268,6 +270,7 @@ io_fmemopen(void ** __restrict base, off_t basesize) memset(buf, 0, sizeof(struct tagBufIO)); if (!*base) { +#ifndef __linux__ *base = e_malloc(basesize); if (!*base) { LOGERR; @@ -276,13 +279,18 @@ io_fmemopen(void ** __restrict base, off_t basesize) } else memset(*base, 0, basesize); + buf->buf_base = *base; + buf->buf_size = basesize; +#endif buf->buf_mode = BUFIO_MODE_INFINIT; - } else + } else { + buf->buf_base = *base; + buf->buf_size = basesize; + buf->buf_mode = BUFIO_MODE_LIMIT; + } - buf->buf_base = *base; - buf->buf_size = basesize; - +#ifndef __linux__ #ifdef __NetBSD__ if (buf->buf_mode == BUFIO_MODE_INFINIT) f = funopen(buf, (int (*)(void *, char *, int)) rf_lim, @@ -306,15 +314,27 @@ io_fmemopen(void ** __restrict base, off_t basesize) (fpos_t (*)(void *, fpos_t, int)) sf_lim, (int (*)(void *)) cf_); #endif +#else + if (buf->buf_mode == BUFIO_MODE_INFINIT) + f = open_memstream((char**) &buf->buf_base, (size_t*) &buf->buf_size); + else + f = fmemopen(buf->buf_base, buf->buf_size, "r+"); +#endif if (!f) { LOGERR; +#ifndef __linux__ if (buf->buf_mode == BUFIO_MODE_INFINIT) { e_free(*base); *base = NULL; } +#endif e_free(buf); return NULL; } +#ifdef __linux__ + if (buf->buf_mode == BUFIO_MODE_INFINIT) + *base = buf->buf_base; +#endif return f; } @@ -386,6 +406,7 @@ io_fmapopen(const char *csFile, int mode, int perm, in buf->buf_size = basesize; buf->buf_unmap = unmap_cf; +#ifndef __linux__ #ifdef __NetBSD__ f = funopen(buf, (int (*)(void *, char *, int)) rf_lim, (int (*)(void *, char const *, int)) wf_lim, @@ -396,6 +417,9 @@ io_fmapopen(const char *csFile, int mode, int perm, in (int (*)(void *, char const *, int)) wf_lim, (fpos_t (*)(void *, fpos_t, int)) sf_lim, (int (*)(void *)) cf_); +#endif +#else + f = fmemopen(buf->buf_base, buf->buf_size, "r+"); #endif if (!f) { LOGERR;