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

version 1.9.8.1, 2016/08/11 12:25:51 version 1.9.8.2, 2016/08/11 12:51:52
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 71  cf_(struct tagBufIO *buf) Line 70  cf_(struct tagBufIO *buf)
         return 0;          return 0;
 }  }
   
#ifdef __NetBSD__#if defined(__NetBSD__) || defined(__linux__)
 static off_t  static off_t
 sf_lim(struct tagBufIO *buf, off_t pos, int w)  sf_lim(struct tagBufIO *buf, off_t pos, int w)
 #else  #else
Line 140  wf_lim(struct tagBufIO *buf, const char *dat, int siz) Line 139  wf_lim(struct tagBufIO *buf, const char *dat, int siz)
         return siz;          return siz;
 }  }
   
#ifdef __NetBSD__#if defined(__NetBSD__) || defined(__linux__)
 static off_t  static off_t
 sf_inf(struct tagBufIO *buf, off_t pos, int w)  sf_inf(struct tagBufIO *buf, off_t pos, int w)
 #else  #else
Line 241  wf_inf(struct tagBufIO *buf, const char *dat, int siz) Line 240  wf_inf(struct tagBufIO *buf, const char *dat, int siz)
         buf->buf_offset += siz;          buf->buf_offset += siz;
         return siz;          return siz;
 }  }
 #endif  
   
   
 /*  /*
Line 256  io_fmemopen(void ** __restrict base, off_t basesize) Line 254  io_fmemopen(void ** __restrict base, off_t basesize)
 {  {
         FILE *f = NULL;          FILE *f = NULL;
         struct tagBufIO *buf;          struct tagBufIO *buf;
   #ifdef __linux__
           cookie_io_functions_t cookie;
   #endif
   
         if (!base) {          if (!base) {
                 io_SetErr(EINVAL, "Invalid base argument ...");                  io_SetErr(EINVAL, "Invalid base argument ...");
Line 270  io_fmemopen(void ** __restrict base, off_t basesize) Line 271  io_fmemopen(void ** __restrict base, off_t basesize)
                 memset(buf, 0, sizeof(struct tagBufIO));                  memset(buf, 0, sizeof(struct tagBufIO));
   
         if (!*base) {          if (!*base) {
 #ifndef __linux__  
                 *base = e_malloc(basesize);                  *base = e_malloc(basesize);
                 if (!*base) {                  if (!*base) {
                         LOGERR;                          LOGERR;
Line 279  io_fmemopen(void ** __restrict base, off_t basesize) Line 279  io_fmemopen(void ** __restrict base, off_t basesize)
                 } 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;
           buf->buf_size = basesize;
   
 #ifndef __linux__  #ifndef __linux__
 #ifdef __NetBSD__  #ifdef __NetBSD__
         if (buf->buf_mode == BUFIO_MODE_INFINIT)          if (buf->buf_mode == BUFIO_MODE_INFINIT)
Line 315  io_fmemopen(void ** __restrict base, off_t basesize) Line 311  io_fmemopen(void ** __restrict base, off_t basesize)
                                 (int (*)(void *)) cf_);                                  (int (*)(void *)) cf_);
 #endif  #endif
 #else  #else
        if (buf->buf_mode == BUFIO_MODE_INFINIT)        if (buf->buf_mode == BUFIO_MODE_INFINIT) {
                f = open_memstream((char**) &buf->buf_base, (size_t*) &buf->buf_size);                cookie.read = (cookie_read_function_t*) rf_lim;
        else                cookie.write = (cookie_write_function_t*) wf_inf;
                f = fmemopen(buf->buf_base, buf->buf_size, "r+");                cookie.seek = (cookie_seek_function_t*) sf_inf;
                 cookie.close = (cookie_close_function_t*) cf_;
         } else {
                 cookie.read = (cookie_read_function_t*) rf_lim;
                 cookie.write = (cookie_write_function_t*) wf_lim;
                 cookie.seek = (cookie_seek_function_t*) sf_lim;
                 cookie.close = (cookie_close_function_t*) cf_;
         }
 
         f = fopencookie(buf, "r+", cookie);
 #endif  #endif
         if (!f) {          if (!f) {
                 LOGERR;                  LOGERR;
 #ifndef __linux__  
                 if (buf->buf_mode == BUFIO_MODE_INFINIT) {                  if (buf->buf_mode == BUFIO_MODE_INFINIT) {
                         e_free(*base);                          e_free(*base);
                         *base = NULL;                          *base = NULL;
                 }                  }
 #endif  
                 e_free(buf);                  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 358  io_fmapopen(const char *csFile, int mode, int perm, in Line 357  io_fmapopen(const char *csFile, int mode, int perm, in
         void *base;          void *base;
         off_t basesize;          off_t basesize;
         int fd = -1;          int fd = -1;
   #ifdef __linux__
           cookie_io_functions_t cookie = {
                   .read = (cookie_read_function_t*) rf_lim, 
                   .write = (cookie_write_function_t*) wf_lim, 
                   .seek = (cookie_seek_function_t*) sf_lim, 
                   .close = (cookie_close_function_t*) cf_
           };
   #endif
   
         if (csFile) {          if (csFile) {
                 fd = open(csFile, mode, perm);                  fd = open(csFile, mode, perm);
Line 419  io_fmapopen(const char *csFile, int mode, int perm, in Line 426  io_fmapopen(const char *csFile, int mode, int perm, in
                         (int (*)(void *)) cf_);                          (int (*)(void *)) cf_);
 #endif  #endif
 #else  #else
        f = fmemopen(buf->buf_base, buf->buf_size, "r+");        f = fopencookie(buf, "r+", cookie);
 #endif  #endif
         if (!f) {          if (!f) {
                 LOGERR;                  LOGERR;

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


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