Exemple #1
0
int gzip68_buffer(void * dst, int dsize, const void * src, int csize)
{
  error68("gzip68: *NOT SUPPORTED*");
  return -1;
}
Exemple #2
0
void *gzip68_load(const char *fname, int *ptr_ulen)
{
  int fd, err;
  gzFile f = 0;
  int ulen = 0;
  void * uncompr = 0;
  off_t len;
  const int omode = O_RDONLY | _O_BINARY;

  fd = open(fname, omode);
  if (fd == -1) {
    error68("gzip68: load '%s' -- %s", fname, strerror(errno));
    goto error;
  }

  len = lseek(fd, 0, SEEK_END);
  if (len == (off_t) -1) {
    error68("gzip68: load '%s' -- %s", fname, strerror(errno));
    goto error;
  }

  if (lseek(fd, 0, SEEK_SET) != 0) {
    error68("gzip68: load '%s' -- %s", fname, strerror(errno));
    goto error;
  }

  ulen = is_gz(fd, len);
  if (ulen == -1) {
    ulen = len;
  }

  f = gzdopen(fd, "rb");
  if (!f) {
    error68("gzip68: load '%s' -- %s", fname, gzerror(f, &err));
    goto error;
  }
  fd = 0; /* $$$ Closed by gzclose(). Verify fdopen() rules. */

  uncompr = malloc(ulen);
  if (!uncompr) {
    error68("gzip68: load '%s' -- alloc error", fname);
    goto error;
  }
  len = gzread(f, uncompr, ulen);

  if (len != ulen) {
    error68("gzip68: load '%s' -- read error (%s)",fname, gzerror(f, &err));
    goto error;
  }
  goto end;

error:
  if (uncompr) {
    free(uncompr);
    uncompr = 0;
    ulen = 0;
  }

end:
  if (fd) {
    close(fd);
  }
  if (f) {
    gzclose(f);
  }
  if (ptr_ulen) {
    *ptr_ulen = ulen;
  }

  return uncompr;
}
Exemple #3
0
void *gzip68_load(const char *fname, int *ptr_ulen)
{
  if (ptr_ulen) *ptr_ulen=0;
  error68("gzip68: *NOT SUPPORTED*");
  return 0;
}
Exemple #4
0
int file68_init(int argc, char **argv)
{
  char tmp[1024];
  option68_t * opt;

  if (init) {
    const int i = init & 3;
    const char *message[4] = {
      "clean","initialized","shutdowning","initializing"
    };
    error68("file68: init error -- *%s*", message[i]);
    argc = -1;
    goto out_no_init;
  }
  init = 3;

  /* Options */
  option68_init();

  /* Zlib */
  istream68_z_init();

  /* Curl */
  istream68_curl_init();

  /* Xiph AO */
  istream68_ao_init();

  /* Init resource */
  rsc68_init();

  /* Loader */
  file68_loader_init();

  option68_append(opts,sizeof(opts)/sizeof(*opts));
  argc = option68_parse(argc, argv, 1);

  /* Check for --sc68-no-debug */
  opt = option68_get("no-debug", 1);
  if (opt && opt->val.num) {
    /* Remove all debug messages whatsoever. */
    msg68_set_handler(0);
  }

  /* Check for --sc68-asid=off|safe|force */
  if (opt = option68_get("asid",1), opt) {
    if (!strcmp68(opt->val.str,"no"))
      aSIDify = 0;
    else if (!strcmp68(opt->val.str,"safe"))
      aSIDify = 1;
    else if (!strcmp68(opt->val.str,"force"))
      aSIDify = 2;
    else
      msg68_notice("file68: ignore invalid mode for --sc68-asid -- *%s*\n", opt->val.str);
  }

  /* Check for --sc68-debug= */

  /* postpone: at this point most debug features have not been created
     yet. it is pretty much useless to set the mask right now. It will
     be done after all inits.
  */
#if 0
  opt = option68_get("debug", 1);
  if (op) {
    debugmsg68_mask = opt->val.num;
  }
#endif

  /* Get share path from registry */
  opt = option68_get("data", 0);
  if (opt) {

    /* Get data path from registry */
    if (!option68_isset(opt)) {
      char * e;
      const char path[] = "Resources";
      e = get_reg_path(registry68_rootkey(REGISTRY68_LMK),
                       "SOFTWARE/sashipa/sc68/Install_Dir",
                       tmp, sizeof(tmp));
      if (e && (e+sizeof(path) < tmp+sizeof(tmp))) {
        memcpy(e, path, sizeof(path));
        option68_set(opt,tmp);
      }
    }

    /* Setup new data path */
    if (option68_isset(opt)) {
      rsc68_set_share(opt->val.str);
#if 0 /* not needed anynore since option68 properly alloc strings */
      if (opt->val.str == tmp)
        option68_unset(opt);    /* Must release tmp ! */
#endif
    }

  }

  /* Get user path  */
  opt = option68_get("home", 0);
  if (opt) {

    /* Get user path from HOME */
    if (!option68_isset(opt)) {
      const char path[] = "/.sc68";
      const char * env = mygetenv("HOME");
      if(env && strlen(env)+sizeof(path) < sizeof(tmp)) {
        strncpy(tmp,env,sizeof(tmp));
        strcat68(tmp,path,sizeof(tmp));
        /* $$$ We should test if this directory actually exists */
        option68_set(opt,tmp);
      }
    }


    /* Get user path from registry */
    if (!option68_isset(opt)) {
      char * e;
      const char path[] = "sc68";
      e = get_reg_path(registry68_rootkey(REGISTRY68_CUK),
                       "Volatile Environment/APPDATA",
                       tmp, sizeof(tmp));
      if (e && (e+sizeof(path) < tmp+sizeof(tmp))) {
        memcpy(e, path, sizeof(path));
        option68_set(opt,tmp);
      }
    }


    /* Setup new user path */
    if (option68_isset(opt)) {
      rsc68_set_user(opt->val.str);
      if (opt->val.str == tmp)
        option68_unset(opt);    /* Must release tmp ! */
    }

  }

  /* Setup new music path */
  opt = option68_get("music", 1);
  if (opt) {
    rsc68_set_music(opt->val.str);
  }

  /* Setup new remote path */
  opt = option68_get("remote", 1);
  if (opt) {
    rsc68_set_remote_music(opt->val.str);
  }

  init = 1;
out_no_init:
  return argc;
}