示例#1
0
static int z_fgetc(void *_fh)
{     struct z_file *fh = _fh;
      int c;
      if (fh->err || fh->eof)
      {  c = XEOF;
         goto done;
      }
      c = gzgetc(fh->file);
      if (c < 0)
      {  int errnum;
         const char *msg;
         msg = gzerror(fh->file, &errnum);
         if (errnum == Z_STREAM_END)
            fh->eof = 1;
         else if (errnum == Z_ERRNO)
         {  fh->err = 1;
            lib_err_msg(strerror(errno));
         }
         else
         {  fh->err = 1;
            lib_err_msg(msg);
         }
         c = XEOF;
      }
      else
         xassert(0x00 <= c && c <= 0xFF);
done: return c;
}
示例#2
0
void *xdlopen(const char *module)
{     void *h = NULL;
      if (lt_dlinit() != 0)
      {  lib_err_msg(lt_dlerror());
         goto done;
      }
      h = lt_dlopen(module);
      if (h == NULL)
      {  lib_err_msg(lt_dlerror());
         if (lt_dlexit() != 0)
            xerror("xdlopen: %s\n", lt_dlerror());
      }
done: return h;
}
示例#3
0
void *xdlopen(const char *module)
{     void *h;
      h = dlopen(module, RTLD_NOW);
      if (h == NULL)
         lib_err_msg(dlerror());
      return h;
}
示例#4
0
void *xdlopen(const char *module)
{     void *h;
      h = LoadLibrary(module);
      if (h == NULL)
      {  char msg[20];
         sprintf(msg, "Error %d", GetLastError());
         lib_err_msg(msg);
      }
      return h;
}
示例#5
0
static int z_fflush(void *_fh)
{     struct z_file *fh = _fh;
      int ret;
      ret = gzflush(fh->file, Z_FINISH);
      if (ret == Z_OK)
         ret = 0;
      else
      {  int errnum;
         const char *msg;
         fh->err = 1;
         msg = gzerror(fh->file, &errnum);
         if (errnum == Z_ERRNO)
            lib_err_msg(strerror(errno));
         else
            lib_err_msg(msg);
         ret = XEOF;
      }
      return ret;
}
示例#6
0
static int c_fflush(void *_fh)
{     FILE *fh = _fh;
      int ret;
      ret = fflush(fh);
      if (ret != 0)
      {  lib_err_msg(strerror(errno));
         ret = XEOF;
      }
      return ret;
}
示例#7
0
static int z_fputc(int c, void *_fh)
{     struct z_file *fh = _fh;
      if (fh->err)
      {  c = XEOF;
         goto done;
      }
      c = (unsigned char)c;
      if (gzputc(fh->file, c) < 0)
      {  int errnum;
         const char *msg;
         fh->err = 1;
         msg = gzerror(fh->file, &errnum);
         if (errnum == Z_ERRNO)
            lib_err_msg(strerror(errno));
         else
            lib_err_msg(msg);
         c = XEOF;
      }
done: return c;
}
示例#8
0
static void *z_fopen(const char *fname, const char *mode)
{     struct z_file *fh;
      gzFile file;
      if (strcmp(mode, "r") == 0 || strcmp(mode, "rb") == 0)
         mode = "rb";
      else if (strcmp(mode, "w") == 0 || strcmp(mode, "wb") == 0)
         mode = "wb";
      else
      {  lib_err_msg("Invalid open mode");
         fh = NULL;
         goto done;
      }
      file = gzopen(fname, mode);
      if (file == NULL)
      {  lib_err_msg(strerror(errno));
         fh = NULL;
         goto done;
      }
      fh = xmalloc(sizeof(struct z_file));
      fh->file = file;
      fh->err = fh->eof = 0;
done: return fh;
}
示例#9
0
static int c_fputc(int c, void *_fh)
{     FILE *fh = _fh;
      if (ferror(fh))
      {  c = XEOF;
         goto done;
      }
      c = (unsigned char)c;
      fputc(c, fh);
      if (ferror(fh))
      {  lib_err_msg(strerror(errno));
         c = XEOF;
      }
done: return c;
}
示例#10
0
static void *c_fopen(const char *fname, const char *mode)
{     FILE *fh;
      if (strcmp(fname, "/dev/stdin") == 0)
         fh = stdin;
      else if (strcmp(fname, "/dev/stdout") == 0)
         fh = stdout;
      else if (strcmp(fname, "/dev/stderr") == 0)
         fh = stderr;
      else
         fh = fopen(fname, mode);
      if (fh == NULL)
         lib_err_msg(strerror(errno));
      return fh;
}
示例#11
0
static int c_fclose(void *_fh)
{     FILE *fh = _fh;
      int ret;
      if (fh == stdin)
         ret = 0;
      else if (fh == stdout || fh == stderr)
         fflush(fh), ret = 0;
      else
         ret = fclose(fh);
      if (ret != 0)
      {  lib_err_msg(strerror(errno));
         ret = XEOF;
      }
      return ret;
}
示例#12
0
static int c_fgetc(void *_fh)
{     FILE *fh = _fh;
      int c;
      if (ferror(fh) || feof(fh))
      {  c = XEOF;
         goto done;
      }
      c = fgetc(fh);
      if (ferror(fh))
      {  lib_err_msg(strerror(errno));
         c = XEOF;
      }
      else if (feof(fh))
         c = XEOF;
      else
         xassert(0x00 <= c && c <= 0xFF);
done: return c;
}
示例#13
0
void *xdlopen(const char *module)
{     xassert(module == module);
      lib_err_msg("Shared libraries not supported");
      return NULL;
}
示例#14
0
static void *z_fopen(const char *fname, const char *mode)
{     xassert(fname == fname);
      xassert(mode == mode);
      lib_err_msg("Compressed files not supported");
      return NULL;
}