diff -r 000cdd124115 -r 5f80c5d0e87f dav/tar.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dav/tar.h Sat Oct 28 15:25:17 2017 +0200 @@ -0,0 +1,133 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2017 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TAR_H +#define TAR_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define T_ISUID 04000 +#define T_ISGID 02000 +#define T_IRUSR 00400 +#define T_IWUSR 00200 +#define T_IXUSR 00100 +#define T_IRGRP 00040 +#define T_IWGRP 00020 +#define T_IXGRP 00010 +#define T_IROTH 00004 +#define T_IWOTH 00002 +#define T_IXOTH 00001 + +#define TAR_TYPE_FILE '0' +#define TAR_TYPE_DIRECTORY '5' + +enum TarError { + TAR_OK = 0, + TAR_PATH_TOO_LONG, + TAR_FILE_TOO_LARGE, + TAR_CONTENT_TOO_LARGE, + TAR_UNFINISHED_FILE, + TAR_CONTENT_BROKEN, + TAR_ERROR +}; + +typedef enum TarError TarError; + +typedef struct TarHeader { + char name[100]; + char mode[8]; + char uid[8]; + char gid[8]; + char size[12]; + char mtime[12]; + char chksum[8]; + char typeflag; + char linkname[100]; + char magic[6]; + char version[2]; + char uname[32]; + char gname[32]; + char devmajor[8]; + char devminor[8]; + char prefix[155]; + char padding[12]; +} TarHeader; + +typedef struct TarOutputStream { + FILE *file; + uint64_t cur_filesize; + uint64_t cur_written; + TarError error; +} TarOutputStream; + +typedef struct TarEntry { + char *path; + uint64_t size; + int type; +} TarEntry; + +typedef struct TarInputStream { + FILE *file; + TarEntry cur_entry; + uint64_t cur_read; + TarError error; +} TarInputStream; + +const char* tar_error2str(TarError error); + +TarOutputStream* tar_open(FILE *f); +int tar_add_dir(TarOutputStream *tar, char *path, uint32_t mode, time_t mtime); +int tar_begin_file( + TarOutputStream *tar, + char *path, + uint32_t mode, + uint64_t size, + time_t mtime); +size_t tar_fwrite(const void *ptr, size_t s, size_t n, TarOutputStream *stream); +int tar_end_file(TarOutputStream *tar); +int tar_close(TarOutputStream *tar); + +TarInputStream* tar_inputstream_open(FILE *f); +TarEntry* tar_read_entry(TarInputStream *tar); +size_t tar_fread(void *ptr, size_t s, size_t n, TarInputStream *stream); +int tar_inputstream_close(TarInputStream *tar); + + +#ifdef __cplusplus +} +#endif + +#endif /* TAR_H */ +