Diff for /libaitio/src/bufio.c between versions 1.6 and 1.9.8.1

version 1.6, 2012/07/03 08:51:05 version 1.9.8.1, 2016/08/11 12:25:51
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012Copyright 2004 - 2016
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 53  unmap_cf(struct tagBufIO *buf) Line 53  unmap_cf(struct tagBufIO *buf)
                 munmap(buf->buf_base, buf->buf_size);                  munmap(buf->buf_base, buf->buf_size);
 }  }
   
   #ifndef __linux__
 static int  static int
 cf_(struct tagBufIO *buf)  cf_(struct tagBufIO *buf)
 {  {
Line 62  cf_(struct tagBufIO *buf) Line 63  cf_(struct tagBufIO *buf)
         }          }
   
         if (buf->buf_mode == BUFIO_MODE_INFINIT)          if (buf->buf_mode == BUFIO_MODE_INFINIT)
                io_free(buf->buf_base);                e_free(buf->buf_base);
         else if (buf->buf_unmap)          else if (buf->buf_unmap)
                 buf->buf_unmap(buf);                  buf->buf_unmap(buf);
   
        io_free(buf);        e_free(buf);
         return 0;          return 0;
 }  }
   
Line 157  sf_inf(struct tagBufIO *buf, fpos_t pos, int w) Line 158  sf_inf(struct tagBufIO *buf, fpos_t pos, int w)
                         if (pos < 0)                          if (pos < 0)
                                 goto err;                                  goto err;
                         if (buf->buf_size < pos) {                          if (buf->buf_size < pos) {
                                b = io_realloc(buf->buf_base, pos);                                b = e_realloc(buf->buf_base, pos);
                                 if (!b) {                                  if (!b) {
                                         LOGERR;                                          LOGERR;
                                         return -1;                                          return -1;
Line 173  sf_inf(struct tagBufIO *buf, fpos_t pos, int w) Line 174  sf_inf(struct tagBufIO *buf, fpos_t pos, int w)
                         if ((buf->buf_offset + pos) < 0)                          if ((buf->buf_offset + pos) < 0)
                                 goto err;                                  goto err;
                         if (buf->buf_size < (buf->buf_offset + pos)) {                          if (buf->buf_size < (buf->buf_offset + pos)) {
                                b = io_realloc(buf->buf_base, buf->buf_offset + pos);                                b = e_realloc(buf->buf_base, buf->buf_offset + pos);
                                 if (!b) {                                  if (!b) {
                                         LOGERR;                                          LOGERR;
                                         return -1;                                          return -1;
Line 190  sf_inf(struct tagBufIO *buf, fpos_t pos, int w) Line 191  sf_inf(struct tagBufIO *buf, fpos_t pos, int w)
                         if ((buf->buf_size + pos) < 0)                          if ((buf->buf_size + pos) < 0)
                                 goto err;                                  goto err;
                         if (buf->buf_size < (buf->buf_size + pos)) {                          if (buf->buf_size < (buf->buf_size + pos)) {
                                b = io_realloc(buf->buf_base, buf->buf_size + pos);                                b = e_realloc(buf->buf_base, buf->buf_size + pos);
                                 if (!b) {                                  if (!b) {
                                         LOGERR;                                          LOGERR;
                                         return -1;                                          return -1;
Line 224  wf_inf(struct tagBufIO *buf, const char *dat, int siz) Line 225  wf_inf(struct tagBufIO *buf, const char *dat, int siz)
         }          }
   
         if (buf->buf_offset + siz > buf->buf_size) {          if (buf->buf_offset + siz > buf->buf_size) {
                b = io_realloc(buf->buf_base, buf->buf_offset + siz);                b = e_realloc(buf->buf_base, buf->buf_offset + siz);
                 if (!b) {                  if (!b) {
                         LOGERR;                          LOGERR;
                         return -1;                          return -1;
Line 240  wf_inf(struct tagBufIO *buf, const char *dat, int siz) Line 241  wf_inf(struct tagBufIO *buf, const char *dat, int siz)
         buf->buf_offset += siz;          buf->buf_offset += siz;
         return siz;          return siz;
 }  }
   #endif
   
   
 /*  /*
Line 260  io_fmemopen(void ** __restrict base, off_t basesize) Line 262  io_fmemopen(void ** __restrict base, off_t basesize)
                 return NULL;                  return NULL;
         }          }
   
        buf = io_malloc(sizeof(struct tagBufIO));        buf = e_malloc(sizeof(struct tagBufIO));
         if (!buf) {          if (!buf) {
                 LOGERR;                  LOGERR;
                 return NULL;                  return NULL;
Line 268  io_fmemopen(void ** __restrict base, off_t basesize) Line 270  io_fmemopen(void ** __restrict base, off_t basesize)
                 memset(buf, 0, sizeof(struct tagBufIO));                  memset(buf, 0, sizeof(struct tagBufIO));
   
         if (!*base) {          if (!*base) {
                *base = io_malloc(basesize);#ifndef __linux__
                 *base = e_malloc(basesize);
                 if (!*base) {                  if (!*base) {
                         LOGERR;                          LOGERR;
                        io_free(buf);                        e_free(buf);
                         return NULL;                          return NULL;
                 } else                  } else
                         memset(*base, 0, basesize);                          memset(*base, 0, basesize);
   
                   buf->buf_base = *base;
                   buf->buf_size = basesize;
   #endif
                 buf->buf_mode = BUFIO_MODE_INFINIT;                  buf->buf_mode = BUFIO_MODE_INFINIT;
        } else        } else {
                 buf->buf_base = *base;
                 buf->buf_size = basesize;
 
                 buf->buf_mode = BUFIO_MODE_LIMIT;                  buf->buf_mode = BUFIO_MODE_LIMIT;
           }
   
        buf->buf_base = *base;#ifndef __linux__
        buf->buf_size = basesize; 
 
 #ifdef __NetBSD__  #ifdef __NetBSD__
         if (buf->buf_mode == BUFIO_MODE_INFINIT)          if (buf->buf_mode == BUFIO_MODE_INFINIT)
                 f = funopen(buf, (int (*)(void *, char *, int)) rf_lim,                   f = funopen(buf, (int (*)(void *, char *, int)) rf_lim, 
Line 306  io_fmemopen(void ** __restrict base, off_t basesize) Line 314  io_fmemopen(void ** __restrict base, off_t basesize)
                                 (fpos_t (*)(void *, fpos_t, int)) sf_lim,                                   (fpos_t (*)(void *, fpos_t, int)) sf_lim, 
                                 (int (*)(void *)) cf_);                                  (int (*)(void *)) cf_);
 #endif  #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) {          if (!f) {
                 LOGERR;                  LOGERR;
   #ifndef __linux__
                 if (buf->buf_mode == BUFIO_MODE_INFINIT) {                  if (buf->buf_mode == BUFIO_MODE_INFINIT) {
                        io_free(*base);                        e_free(*base);
                         *base = NULL;                          *base = NULL;
                 }                  }
                io_free(buf);#endif
                 e_free(buf);
                 return NULL;                  return NULL;
         }          }
   #ifdef __linux__
           if (buf->buf_mode == BUFIO_MODE_INFINIT)
                   *base = buf->buf_base;
   #endif
   
         return f;          return f;
 }  }
Line 373  io_fmapopen(const char *csFile, int mode, int perm, in Line 393  io_fmapopen(const char *csFile, int mode, int perm, in
         }          }
   
   
        buf = io_malloc(sizeof(struct tagBufIO));        buf = e_malloc(sizeof(struct tagBufIO));
         if (!buf) {          if (!buf) {
                 LOGERR;                  LOGERR;
                 munmap(base, basesize);                  munmap(base, basesize);
Line 386  io_fmapopen(const char *csFile, int mode, int perm, in Line 406  io_fmapopen(const char *csFile, int mode, int perm, in
         buf->buf_size = basesize;          buf->buf_size = basesize;
         buf->buf_unmap = unmap_cf;          buf->buf_unmap = unmap_cf;
   
   #ifndef __linux__
 #ifdef __NetBSD__  #ifdef __NetBSD__
         f = funopen(buf, (int (*)(void *, char *, int)) rf_lim,           f = funopen(buf, (int (*)(void *, char *, int)) rf_lim, 
                         (int (*)(void *, char const *, int)) wf_lim,                           (int (*)(void *, char const *, int)) wf_lim, 
Line 397  io_fmapopen(const char *csFile, int mode, int perm, in Line 418  io_fmapopen(const char *csFile, int mode, int perm, in
                         (fpos_t (*)(void *, fpos_t, int)) sf_lim,                           (fpos_t (*)(void *, fpos_t, int)) sf_lim, 
                         (int (*)(void *)) cf_);                          (int (*)(void *)) cf_);
 #endif  #endif
   #else
           f = fmemopen(buf->buf_base, buf->buf_size, "r+");
   #endif
         if (!f) {          if (!f) {
                 LOGERR;                  LOGERR;
                io_free(buf);                e_free(buf);
                 munmap(base, basesize);                  munmap(base, basesize);
                 return NULL;                  return NULL;
         }          }
Line 447  err: Line 471  err:
  * @mode = Permissions for new buffered file I/O   * @mode = Permissions for new buffered file I/O
  * return: NULL error or open buffered file   * return: NULL error or open buffered file
  */   */
inline FILE *FILE *
 io_fd2buf(int fd, const char *mode)  io_fd2buf(int fd, const char *mode)
 {  {
         FILE *f;          FILE *f;

Removed from v.1.6  
changed lines
  Added in v.1.9.8.1


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>