Пример #1
0
static int
create(char *tarfile, char *rootdir, libtar_list_t *l)
{
  TAR *t;
  char *pathname;
  char buf[TAR_MAXPATHLEN];
  libtar_listptr_t lp;

  if (tar_open(&t, tarfile,
#ifdef HAVE_LIBZ
         (use_zlib ? &gztype : NULL),
#else
         NULL,
#endif
         O_WRONLY | O_CREAT, 0644,
         (verbose ? TAR_VERBOSE : 0)
         | (use_gnu ? TAR_GNU : 0)) == -1)
  {
    fprintf(stderr, "tar_open(): %s\n", strerror(errno));
    return -1;
  }

  libtar_listptr_reset(&lp);
  while (libtar_list_next(l, &lp) != 0)
  {
    pathname = (char *)libtar_listptr_data(&lp);
    if (pathname[0] != '/' && rootdir != NULL)
      snprintf(buf, sizeof(buf), "%s/%s", rootdir, pathname);
    else
      strlcpy(buf, pathname, sizeof(buf));
    if (tar_append_tree(t, buf, pathname) != 0)
    {
      fprintf(stderr,
        "tar_append_tree(\"%s\", \"%s\"): %s\n", buf,
        pathname, strerror(errno));
      tar_close(t);
      return -1;
    }
  }

  if (tar_append_eof(t) != 0)
  {
    fprintf(stderr, "tar_append_eof(): %s\n", strerror(errno));
    tar_close(t);
    return -1;
  }

  if (tar_close(t) != 0)
  {
    fprintf(stderr, "tar_close(): %s\n", strerror(errno));
    return -1;
  }

  return 0;
}
Пример #2
0
/*
** libtar_hash_search() - iterative search for an element in a hash
** returns:
**	1			match found
**	0			no match
*/
int
libtar_hash_search(libtar_hash_t *h,
			      libtar_hashptr_t *hp, void *data,
			      libtar_matchfunc_t matchfunc)
{
	while (libtar_hash_next(h, hp) != 0)
		if ((*matchfunc)(data, libtar_listptr_data(&(hp->node))) != 0)
			return 1;

	return 0;
}
Пример #3
0
static int par_create(char *file, char *rootdir, libtar_list_t *l) {
	PAR *t;
	char *pathname;
	char buf[MAXPATHLEN];
	libtar_listptr_t lp;

	if (par_open(&t, file, 1, O_WRONLY | O_CREAT, 0644, 0) == -1) {
		fprintf(stderr, "tar_open(): %s\n", strerror(errno));
		return -1;
	}

	if (par_write_header(t) == -1) {
		fprintf(stderr, "par_write_header(): %s\n", strerror(errno));
		par_close(t);
		return -1;
	}

	libtar_listptr_reset(&lp);
	while (libtar_list_next(l, &lp) != 0) {
		pathname = (char *)libtar_listptr_data(&lp);
		if (pathname[0] != '/' && rootdir != NULL)
			snprintf(buf, sizeof(buf), "%s/%s", rootdir, pathname);
		else
			strlcpy(buf, pathname, sizeof(buf));
		
		if (par_append_tree(t, buf, pathname) != 0) {
			fprintf(stderr, "tar_append_tree(\"%s\", \"%s\"): %s\n", buf,
				pathname, strerror(errno));
			par_close(t);
			return -1;
		}
	}

	if (par_append_eof(t) != 0) {
		fprintf(stderr, "tar_append_eof(): %s\n", strerror(errno));
		par_close(t);
		return -1;
	}

	if (par_close(t) != 0) {
		fprintf(stderr, "tar_close(): %s\n", strerror(errno));
		return -1;
	}

	return 0;
}
Пример #4
0
static int tarupthelist(char *tarfile, char *rootdir, libtar_list_t *l)
{
    TAR *t;
    char *pathname;
    char buf[TAR_MAXPATHLEN];

    if (tar_open(&t, tarfile, NULL, O_WRONLY | O_CREAT, 0644, (use_gnu ? TAR_GNU : 0)) == -1) {
        fprintf(stderr, "tar_open(): %s\n", strerror(errno));
        return -1;
    }

    libtar_listptr_t lp;
    libtar_listptr_reset(&lp);
    while (libtar_list_next(l, &lp) != 0) {
        pathname = (char *)libtar_listptr_data(&lp);
        if (pathname[0] != '/' && rootdir != NULL)
            snprintf(buf, sizeof(buf), "%s/%s", rootdir, pathname);
        else
            strncpy(buf, pathname, sizeof(buf));
        if (tar_append_tree(t, buf, pathname) != 0) {
            fprintf(stderr, "tar_append_tree(\"%s\", \"%s\"): %s\n", buf, pathname, strerror(errno));
            tar_close(t);
            return -1;
        }
    }

    if (tar_append_eof(t) != 0) {
        fprintf(stderr, "tar_append_eof(): %s\n", strerror(errno));
        tar_close(t);
        return -1;
    }

    if (tar_close(t) != 0) {
        fprintf(stderr, "tar_close(): %s\n", strerror(errno));
        return -1;
    }
    return 0;
}
Пример #5
0
/*
** libtar_hashptr_data() - retrieve the data being pointed to
*/
void *
libtar_hashptr_data(libtar_hashptr_t *hp)
{
	return libtar_listptr_data(&(hp->node));
}