2 ** Copyright 1998-2003 University of Illinois Board of Trustees
3 ** Copyright 1998-2003 Mark D. Roth
4 ** All rights reserved.
6 ** handle.c - libtar code for initializing a TAR handle
8 ** Mark D. Roth <roth@uiuc.edu>
9 ** Campus Information Technologies and Educational Services
10 ** University of Illinois at Urbana-Champaign
28 const char libtar_version
[] = PACKAGE_VERSION
;
30 static tartype_t default_type
= { open
, close
, read
, write
};
34 tar_init(TAR
**t
, char *pathname
, tartype_t
*type
,
35 int oflags
, int mode
, int options
)
37 if ((oflags
& O_ACCMODE
) == O_RDWR
)
43 *t
= (TAR
*)calloc(1, sizeof(TAR
));
47 (*t
)->pathname
= pathname
;
48 (*t
)->options
= options
;
49 (*t
)->type
= (type
? type
: &default_type
);
50 (*t
)->oflags
= oflags
;
52 if ((oflags
& O_ACCMODE
) == O_RDONLY
)
53 (*t
)->h
= libtar_hash_new(256,
54 (libtar_hashfunc_t
)path_hashfunc
);
56 (*t
)->h
= libtar_hash_new(16, (libtar_hashfunc_t
)dev_hash
);
67 /* open a new tarfile handle */
69 tar_open(TAR
**t
, char *pathname
, tartype_t
*type
,
70 int oflags
, int mode
, int options
)
72 if (tar_init(t
, pathname
, type
, oflags
, mode
, options
) == -1)
75 if ((options
& TAR_NOOVERWRITE
) && (oflags
& O_CREAT
))
82 (*t
)->fd
= (*((*t
)->type
->openfunc
))(pathname
, oflags
, mode
);
94 tar_fdopen(TAR
**t
, int fd
, char *pathname
, tartype_t
*type
,
95 int oflags
, int mode
, int options
)
97 if (tar_init(t
, pathname
, type
, oflags
, mode
, options
) == -1)
112 /* close tarfile handle */
118 i
= (*(t
->type
->closefunc
))(t
->fd
);
121 libtar_hash_free(t
->h
, ((t
->oflags
& O_ACCMODE
) == O_RDONLY
123 : (libtar_freefunc_t
)tar_dev_free
));