work in progress - fio, untar
This commit is contained in:
@ -41,6 +41,7 @@ include_HEADERS = \
|
||||
hio-dns.h \
|
||||
hio-ecs.h \
|
||||
hio-fcgi.h \
|
||||
hio-fio.h \
|
||||
hio-fmt.h \
|
||||
hio-htb.h \
|
||||
hio-htrd.h \
|
||||
@ -76,6 +77,7 @@ libhio_la_SOURCES = \
|
||||
ecs-imp.h \
|
||||
err.c \
|
||||
fcgi-cli.c \
|
||||
fio.c \
|
||||
fmt.c \
|
||||
fmt-imp.h \
|
||||
htb.c \
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Makefile.in generated by automake 1.16.2 from Makefile.am.
|
||||
# Makefile.in generated by automake 1.16.3 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994-2020 Free Software Foundation, Inc.
|
||||
@ -148,8 +148,8 @@ libhio_la_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \
|
||||
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
|
||||
$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_4)
|
||||
am__libhio_la_SOURCES_DIST = chr.c dhcp-svr.c dns.c dns-cli.c ecs.c \
|
||||
ecs-imp.h err.c fcgi-cli.c fmt.c fmt-imp.h htb.c htrd.c htre.c \
|
||||
http.c http-cgi.c http-fcgi.c http-file.c http-prv.h \
|
||||
ecs-imp.h err.c fcgi-cli.c fio.c fmt.c fmt-imp.h htb.c htrd.c \
|
||||
htre.c http.c http-cgi.c http-fcgi.c http-file.c http-prv.h \
|
||||
http-svr.c http-thr.c http-txt.c json.c hio-prv.h hio.c md5.c \
|
||||
nwif.c opt.c opt-imp.h path.c pipe.c pro.c pty.c rad-msg.c \
|
||||
sck.c shw.c skad.c sys.c sys-ass.c sys-err.c sys-log.c \
|
||||
@ -159,20 +159,21 @@ am__libhio_la_SOURCES_DIST = chr.c dhcp-svr.c dns.c dns-cli.c ecs.c \
|
||||
@ENABLE_MARIADB_TRUE@ libhio_la-mar-cli.lo
|
||||
am_libhio_la_OBJECTS = libhio_la-chr.lo libhio_la-dhcp-svr.lo \
|
||||
libhio_la-dns.lo libhio_la-dns-cli.lo libhio_la-ecs.lo \
|
||||
libhio_la-err.lo libhio_la-fcgi-cli.lo libhio_la-fmt.lo \
|
||||
libhio_la-htb.lo libhio_la-htrd.lo libhio_la-htre.lo \
|
||||
libhio_la-http.lo libhio_la-http-cgi.lo libhio_la-http-fcgi.lo \
|
||||
libhio_la-http-file.lo libhio_la-http-svr.lo \
|
||||
libhio_la-http-thr.lo libhio_la-http-txt.lo libhio_la-json.lo \
|
||||
libhio_la-hio.lo libhio_la-md5.lo libhio_la-nwif.lo \
|
||||
libhio_la-opt.lo libhio_la-path.lo libhio_la-pipe.lo \
|
||||
libhio_la-pro.lo libhio_la-pty.lo libhio_la-rad-msg.lo \
|
||||
libhio_la-sck.lo libhio_la-shw.lo libhio_la-skad.lo \
|
||||
libhio_la-sys.lo libhio_la-sys-ass.lo libhio_la-sys-err.lo \
|
||||
libhio_la-sys-log.lo libhio_la-sys-mux.lo libhio_la-sys-tim.lo \
|
||||
libhio_la-thr.lo libhio_la-tar.lo libhio_la-tmr.lo \
|
||||
libhio_la-utf8.lo libhio_la-utl.lo libhio_la-utl-siph.lo \
|
||||
libhio_la-utl-str.lo $(am__objects_1)
|
||||
libhio_la-err.lo libhio_la-fcgi-cli.lo libhio_la-fio.lo \
|
||||
libhio_la-fmt.lo libhio_la-htb.lo libhio_la-htrd.lo \
|
||||
libhio_la-htre.lo libhio_la-http.lo libhio_la-http-cgi.lo \
|
||||
libhio_la-http-fcgi.lo libhio_la-http-file.lo \
|
||||
libhio_la-http-svr.lo libhio_la-http-thr.lo \
|
||||
libhio_la-http-txt.lo libhio_la-json.lo libhio_la-hio.lo \
|
||||
libhio_la-md5.lo libhio_la-nwif.lo libhio_la-opt.lo \
|
||||
libhio_la-path.lo libhio_la-pipe.lo libhio_la-pro.lo \
|
||||
libhio_la-pty.lo libhio_la-rad-msg.lo libhio_la-sck.lo \
|
||||
libhio_la-shw.lo libhio_la-skad.lo libhio_la-sys.lo \
|
||||
libhio_la-sys-ass.lo libhio_la-sys-err.lo libhio_la-sys-log.lo \
|
||||
libhio_la-sys-mux.lo libhio_la-sys-tim.lo libhio_la-thr.lo \
|
||||
libhio_la-tar.lo libhio_la-tmr.lo libhio_la-utf8.lo \
|
||||
libhio_la-utl.lo libhio_la-utl-siph.lo libhio_la-utl-str.lo \
|
||||
$(am__objects_1)
|
||||
libhio_la_OBJECTS = $(am_libhio_la_OBJECTS)
|
||||
AM_V_lt = $(am__v_lt_@AM_V@)
|
||||
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
|
||||
@ -202,9 +203,9 @@ am__depfiles_remade = ./$(DEPDIR)/libhio_la-chr.Plo \
|
||||
./$(DEPDIR)/libhio_la-dns.Plo ./$(DEPDIR)/libhio_la-ecs.Plo \
|
||||
./$(DEPDIR)/libhio_la-err.Plo \
|
||||
./$(DEPDIR)/libhio_la-fcgi-cli.Plo \
|
||||
./$(DEPDIR)/libhio_la-fmt.Plo ./$(DEPDIR)/libhio_la-hio.Plo \
|
||||
./$(DEPDIR)/libhio_la-htb.Plo ./$(DEPDIR)/libhio_la-htrd.Plo \
|
||||
./$(DEPDIR)/libhio_la-htre.Plo \
|
||||
./$(DEPDIR)/libhio_la-fio.Plo ./$(DEPDIR)/libhio_la-fmt.Plo \
|
||||
./$(DEPDIR)/libhio_la-hio.Plo ./$(DEPDIR)/libhio_la-htb.Plo \
|
||||
./$(DEPDIR)/libhio_la-htrd.Plo ./$(DEPDIR)/libhio_la-htre.Plo \
|
||||
./$(DEPDIR)/libhio_la-http-cgi.Plo \
|
||||
./$(DEPDIR)/libhio_la-http-fcgi.Plo \
|
||||
./$(DEPDIR)/libhio_la-http-file.Plo \
|
||||
@ -258,11 +259,11 @@ am__can_run_installinfo = \
|
||||
*) (install-info --version) >/dev/null 2>&1;; \
|
||||
esac
|
||||
am__include_HEADERS_DIST = hio-chr.h hio-cmn.h hio-dhcp.h hio-dns.h \
|
||||
hio-ecs.h hio-fcgi.h hio-fmt.h hio-htb.h hio-htrd.h hio-htre.h \
|
||||
hio-http.h hio-json.h hio-md5.h hio-nwif.h hio-opt.h \
|
||||
hio-pac1.h hio-path.h hio-pipe.h hio-pro.h hio-pty.h hio-rad.h \
|
||||
hio-sck.h hio-shw.h hio-skad.h hio-str.h hio-tar.h hio-thr.h \
|
||||
hio-upac.h hio-utl.h hio.h hio-mar.h
|
||||
hio-ecs.h hio-fcgi.h hio-fio.h hio-fmt.h hio-htb.h hio-htrd.h \
|
||||
hio-htre.h hio-http.h hio-json.h hio-md5.h hio-nwif.h \
|
||||
hio-opt.h hio-pac1.h hio-path.h hio-pipe.h hio-pro.h hio-pty.h \
|
||||
hio-rad.h hio-sck.h hio-shw.h hio-skad.h hio-str.h hio-tar.h \
|
||||
hio-thr.h hio-upac.h hio-utl.h hio.h hio-mar.h
|
||||
HEADERS = $(include_HEADERS)
|
||||
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \
|
||||
hio-cfg.h.in
|
||||
@ -461,20 +462,20 @@ LIBADD_LIB_COMMON = $(LIBM)
|
||||
|
||||
# Never list hio-cfg.h in include_HEADERS.
|
||||
include_HEADERS = hio-chr.h hio-cmn.h hio-dhcp.h hio-dns.h hio-ecs.h \
|
||||
hio-fcgi.h hio-fmt.h hio-htb.h hio-htrd.h hio-htre.h \
|
||||
hio-fcgi.h hio-fio.h hio-fmt.h hio-htb.h hio-htrd.h hio-htre.h \
|
||||
hio-http.h hio-json.h hio-md5.h hio-nwif.h hio-opt.h \
|
||||
hio-pac1.h hio-path.h hio-pipe.h hio-pro.h hio-pty.h hio-rad.h \
|
||||
hio-sck.h hio-shw.h hio-skad.h hio-str.h hio-tar.h hio-thr.h \
|
||||
hio-upac.h hio-utl.h hio.h $(am__append_1)
|
||||
lib_LTLIBRARIES = libhio.la
|
||||
libhio_la_SOURCES = chr.c dhcp-svr.c dns.c dns-cli.c ecs.c ecs-imp.h \
|
||||
err.c fcgi-cli.c fmt.c fmt-imp.h htb.c htrd.c htre.c http.c \
|
||||
http-cgi.c http-fcgi.c http-file.c http-prv.h http-svr.c \
|
||||
http-thr.c http-txt.c json.c hio-prv.h hio.c md5.c nwif.c \
|
||||
opt.c opt-imp.h path.c pipe.c pro.c pty.c rad-msg.c sck.c \
|
||||
shw.c skad.c sys.c sys-ass.c sys-err.c sys-log.c sys-mux.c \
|
||||
sys-prv.h sys-tim.c thr.c uch-case.h uch-prop.h tar.c tmr.c \
|
||||
utf8.c utl.c utl-siph.c utl-str.c $(am__append_2)
|
||||
err.c fcgi-cli.c fio.c fmt.c fmt-imp.h htb.c htrd.c htre.c \
|
||||
http.c http-cgi.c http-fcgi.c http-file.c http-prv.h \
|
||||
http-svr.c http-thr.c http-txt.c json.c hio-prv.h hio.c md5.c \
|
||||
nwif.c opt.c opt-imp.h path.c pipe.c pro.c pty.c rad-msg.c \
|
||||
sck.c shw.c skad.c sys.c sys-ass.c sys-err.c sys-log.c \
|
||||
sys-mux.c sys-prv.h sys-tim.c thr.c uch-case.h uch-prop.h \
|
||||
tar.c tmr.c utf8.c utl.c utl-siph.c utl-str.c $(am__append_2)
|
||||
libhio_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
||||
libhio_la_CFLAGS = $(CFLAGS_LIB_COMMON) $(am__append_3)
|
||||
libhio_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) $(am__append_4)
|
||||
@ -581,6 +582,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-ecs.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-err.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-fcgi-cli.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-fio.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-fmt.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-hio.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-htb.Plo@am__quote@ # am--include-marker
|
||||
@ -700,6 +702,13 @@ libhio_la-fcgi-cli.lo: fcgi-cli.c
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -c -o libhio_la-fcgi-cli.lo `test -f 'fcgi-cli.c' || echo '$(srcdir)/'`fcgi-cli.c
|
||||
|
||||
libhio_la-fio.lo: fio.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -MT libhio_la-fio.lo -MD -MP -MF $(DEPDIR)/libhio_la-fio.Tpo -c -o libhio_la-fio.lo `test -f 'fio.c' || echo '$(srcdir)/'`fio.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhio_la-fio.Tpo $(DEPDIR)/libhio_la-fio.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='fio.c' object='libhio_la-fio.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -c -o libhio_la-fio.lo `test -f 'fio.c' || echo '$(srcdir)/'`fio.c
|
||||
|
||||
libhio_la-fmt.lo: fmt.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -MT libhio_la-fmt.lo -MD -MP -MF $(DEPDIR)/libhio_la-fmt.Tpo -c -o libhio_la-fmt.lo `test -f 'fmt.c' || echo '$(srcdir)/'`fmt.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhio_la-fmt.Tpo $(DEPDIR)/libhio_la-fmt.Plo
|
||||
@ -1095,7 +1104,8 @@ installdirs:
|
||||
done
|
||||
install: $(BUILT_SOURCES)
|
||||
$(MAKE) $(AM_MAKEFLAGS) install-am
|
||||
install-exec: install-exec-am
|
||||
install-exec: $(BUILT_SOURCES)
|
||||
$(MAKE) $(AM_MAKEFLAGS) install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
@ -1138,6 +1148,7 @@ distclean: distclean-am
|
||||
-rm -f ./$(DEPDIR)/libhio_la-ecs.Plo
|
||||
-rm -f ./$(DEPDIR)/libhio_la-err.Plo
|
||||
-rm -f ./$(DEPDIR)/libhio_la-fcgi-cli.Plo
|
||||
-rm -f ./$(DEPDIR)/libhio_la-fio.Plo
|
||||
-rm -f ./$(DEPDIR)/libhio_la-fmt.Plo
|
||||
-rm -f ./$(DEPDIR)/libhio_la-hio.Plo
|
||||
-rm -f ./$(DEPDIR)/libhio_la-htb.Plo
|
||||
@ -1230,6 +1241,7 @@ maintainer-clean: maintainer-clean-am
|
||||
-rm -f ./$(DEPDIR)/libhio_la-ecs.Plo
|
||||
-rm -f ./$(DEPDIR)/libhio_la-err.Plo
|
||||
-rm -f ./$(DEPDIR)/libhio_la-fcgi-cli.Plo
|
||||
-rm -f ./$(DEPDIR)/libhio_la-fio.Plo
|
||||
-rm -f ./$(DEPDIR)/libhio_la-fmt.Plo
|
||||
-rm -f ./$(DEPDIR)/libhio_la-hio.Plo
|
||||
-rm -f ./$(DEPDIR)/libhio_la-htb.Plo
|
||||
@ -1288,8 +1300,8 @@ ps-am:
|
||||
uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES
|
||||
@$(NORMAL_INSTALL)
|
||||
$(MAKE) $(AM_MAKEFLAGS) uninstall-hook
|
||||
.MAKE: all check install install-am install-data-am install-strip \
|
||||
uninstall-am
|
||||
.MAKE: all check install install-am install-data-am install-exec \
|
||||
install-strip uninstall-am
|
||||
|
||||
.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \
|
||||
clean-generic clean-libLTLIBRARIES clean-libtool cscopelist-am \
|
||||
|
@ -11,13 +11,14 @@ struct hio_tar_hdr_t
|
||||
char mode[8]; /* 100 */
|
||||
char uid[8]; /* 108 */
|
||||
char gid[8]; /* 116 */
|
||||
char size[12]; /* 124 */
|
||||
char size[12]; /* 124 - file size in an ascii octal string */
|
||||
char mtime[12]; /* 136 */
|
||||
char chksum[8]; /* 148 */
|
||||
char typeflag; /* 156 */
|
||||
char linkname[100]; /* 157 */
|
||||
char magic[6]; /* 257 */
|
||||
char version[2]; /* 263 */
|
||||
|
||||
char magic[6]; /* 257 - ustar indicator */
|
||||
char version[2]; /* 263 - ustar version */
|
||||
char uname[32]; /* 265 */
|
||||
char gname[32]; /* 297 */
|
||||
char devmajor[8]; /* 329 */
|
||||
@ -32,7 +33,6 @@ struct hio_tar_hdr_t
|
||||
|
||||
typedef struct hio_tar_hdr_t hio_tar_hdr_t;
|
||||
|
||||
|
||||
#define HIO_TAR_MAGIC "ustar" /* ustar and a null */
|
||||
#define HIO_TAR_MAGLEN 6
|
||||
#define HIO_TAR_VERSION "00" /* 00 and no null */
|
||||
@ -88,6 +88,12 @@ struct hio_tar_t
|
||||
hio_uint8_t buf[HIO_TAR_BLKSIZE];
|
||||
hio_oow_t len;
|
||||
} blk;
|
||||
|
||||
struct
|
||||
{
|
||||
hio_uintmax_t filesize;
|
||||
void* fp;
|
||||
} hi;
|
||||
};
|
||||
typedef struct hio_tar_t hio_tar_t;
|
||||
|
||||
@ -98,23 +104,31 @@ extern "C" {
|
||||
HIO_EXPORT int hio_extract_tar (hio_t* hio, const hio_bch_t* archive_file);
|
||||
|
||||
|
||||
hio_tar_t* hio_tar_open (
|
||||
HIO_EXPORT hio_tar_t* hio_tar_open (
|
||||
hio_t* hio,
|
||||
hio_oow_t xtnsize
|
||||
);
|
||||
|
||||
void hio_tar_close (
|
||||
HIO_EXPORT void hio_tar_close (
|
||||
hio_tar_t* tar
|
||||
);
|
||||
|
||||
int hio_tar_init (
|
||||
HIO_EXPORT int hio_tar_init (
|
||||
hio_tar_t* tar
|
||||
);
|
||||
|
||||
void hio_tar_fini (
|
||||
HIO_EXPORT void hio_tar_fini (
|
||||
hio_tar_t* tar
|
||||
);
|
||||
|
||||
#define hio_tar_endfeed(tar) hio_tar_feed(tar, HIO_NULL, 0)
|
||||
|
||||
HIO_EXPORT int hio_tar_feed (
|
||||
hio_tar_t* tar,
|
||||
const void* ptr,
|
||||
hio_oow_t len
|
||||
);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
88
lib/tar.c
88
lib/tar.c
@ -223,25 +223,69 @@ void hio_tar_fini (hio_tar_t* tar)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static int process_header (hio_tar_t* tar)
|
||||
{
|
||||
hio_tar_hdr_t* hdr;
|
||||
|
||||
HIO_ASSERT (tar->hio, tar->state == HIO_TAR_STATE_START);
|
||||
HIO_ASSERT (tar->hio, tar->blk.len == HIO_TAR_BLKSIZE);
|
||||
hdr = (hio_tar_hdr_t*)tar->blk.buf;
|
||||
|
||||
/* all-zero byte block ends the archive */
|
||||
if (HIO_MEMCMP(hdr, _end_block, HIO_TAR_BLKSIZE) == 0)
|
||||
{
|
||||
/* TODO: is it correct? */
|
||||
tar->state = HIO_TAR_STATE_END;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int is_sober;
|
||||
const hio_bch_t* endptr;
|
||||
|
||||
/* if (hdr->typeflag) TODO: do different jobs depending on types... */
|
||||
|
||||
tar->hi.filesize = hio_bchars_to_uintmax(hdr->size, HIO_COUNTOF(hdr->size), HIO_BCHARS_TO_UINTMAX_MAKE_OPTION(0,0,0,8), &endptr, &is_sober);
|
||||
//mode = hio_bchars_to_uintmax(hdr->mode, HIO_COUNTOF(hdr->mode), HIO_BCHARS_TO_UINTMAX_MAKE_OPTION(0,0,0,8), &endptr, &is_sober);
|
||||
|
||||
if (tar->hi.filesize > 0)
|
||||
{
|
||||
tar->state = HIO_TAR_STATE_FILE;
|
||||
/* open here? */
|
||||
/* COMPOSE an actual file name...
|
||||
hdr->prefix + hdr->name
|
||||
fp = fopen(hdr->name, "w");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* empty file? just create an empty file here??? */
|
||||
/* open ... close or just create */
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define hio_tar_endfeed(tar) hio_tar_feed(tar, HIO_NULL, 0)
|
||||
static int process_content (hio_tar_t* tar)
|
||||
{
|
||||
hio_oow_t chunksize;
|
||||
|
||||
HIO_ASSERT (tar->hio, tar->blk.len == HIO_TAR_BLKSIZE);
|
||||
HIO_ASSERT (tar->hio, tar->hi.filesize > 0);
|
||||
|
||||
|
||||
chunksize = tar->hi.filesize < tar->blk.len? tar->hi.filesize: tar->blk.len;
|
||||
|
||||
#if 0
|
||||
write callback(tar->hi.).. tar->blk.buf, tar->blk.len);
|
||||
#endif
|
||||
|
||||
tar->hi.filesize -= chunksize;
|
||||
if (tar->hi.filesize <= 0)
|
||||
{
|
||||
/* end of file */
|
||||
/* close file??? also close if there is an exception or error??? */
|
||||
}
|
||||
}
|
||||
|
||||
int hio_tar_feed (hio_tar_t* tar, const void* ptr, hio_oow_t len)
|
||||
{
|
||||
@ -251,34 +295,40 @@ int hio_tar_feed (hio_tar_t* tar, const void* ptr, hio_oow_t len)
|
||||
if (tar->state != HIO_TAR_STATE_END || tar->blk.len > 0)
|
||||
{
|
||||
/* ERROR - premature end of file */
|
||||
hio_seterrbfmt (tar->hio, HIO_EINVAL, "premature end of feed");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
switch (tar->state)
|
||||
hio_oow_t cplen;
|
||||
|
||||
cplen = HIO_COUNTOF(tar->blk.buf) - tar->blk.len; /* required length to fill a block */
|
||||
if (len < cplen) cplen = len; /* not enough to fill a block */
|
||||
|
||||
HIO_MEMCPY (&tar->blk.buf[tar->blk.len], ptr, cplen);
|
||||
tar->blk.len += cplen;
|
||||
len -= cplen;
|
||||
|
||||
if (tar->blk.len == HIO_COUNTOF(tar->blk.buf))
|
||||
{
|
||||
case HIO_TAR_STATE_START:
|
||||
/* on a complete block */
|
||||
switch (tar->state)
|
||||
{
|
||||
hio_oow_t cplen;
|
||||
cplen = HIO_COUNTOF(tar->blk.buf) - tar->blk.len;
|
||||
if (len < cplen) cplen = len;
|
||||
HIO_MEMCPY (&tar->blk.buf[tar->blk.len], ptr, cplen);
|
||||
len -= cplen;
|
||||
break;
|
||||
}
|
||||
case HIO_TAR_STATE_START:
|
||||
if (process_header(tar) <= -1) return -1;
|
||||
break;
|
||||
|
||||
case HIO_TAR_STATE_FILE:
|
||||
break;
|
||||
case HIO_TAR_STATE_FILE:
|
||||
if (process_content(tar) <= -1) return -1;
|
||||
break;
|
||||
|
||||
case HIO_TAR_STATE_END:
|
||||
if (len > 0)
|
||||
{
|
||||
case HIO_TAR_STATE_END:
|
||||
/* garbage after the final ending block */
|
||||
hio_seterrbfmt (tar->hio, HIO_EINVAL, "trailing garbage at the end of feed");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user