Sun, 17 Jun 2018 07:11:31 +0200
adds user+pw to repo-url output
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
364
3769ba002fd1
updates copyright date
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
334
diff
changeset
|
4 | * Copyright 2018 Olaf Wintermann. All rights reserved. |
334
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #ifndef TAR_H |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #define TAR_H |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include <stdio.h> |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include <stdlib.h> |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include <time.h> |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include <inttypes.h> |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #ifdef __cplusplus |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | extern "C" { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #endif |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #define T_ISUID 04000 |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #define T_ISGID 02000 |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | #define T_IRUSR 00400 |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | #define T_IWUSR 00200 |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | #define T_IXUSR 00100 |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | #define T_IRGRP 00040 |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | #define T_IWGRP 00020 |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | #define T_IXGRP 00010 |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | #define T_IROTH 00004 |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | #define T_IWOTH 00002 |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | #define T_IXOTH 00001 |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | #define TAR_TYPE_FILE '0' |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | #define TAR_TYPE_DIRECTORY '5' |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | enum TarError { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | TAR_OK = 0, |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | TAR_PATH_TOO_LONG, |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | TAR_FILE_TOO_LARGE, |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | TAR_CONTENT_TOO_LARGE, |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | TAR_UNFINISHED_FILE, |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | TAR_CONTENT_BROKEN, |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | TAR_ERROR |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | }; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | typedef enum TarError TarError; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | typedef struct TarHeader { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | char name[100]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | char mode[8]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | char uid[8]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | char gid[8]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | char size[12]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | char mtime[12]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | char chksum[8]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | char typeflag; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | char linkname[100]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | char magic[6]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | char version[2]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | char uname[32]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | char gname[32]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | char devmajor[8]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | char devminor[8]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | char prefix[155]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | char padding[12]; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | } TarHeader; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | typedef struct TarOutputStream { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | FILE *file; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | uint64_t cur_filesize; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | uint64_t cur_written; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | TarError error; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | } TarOutputStream; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | typedef struct TarEntry { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | char *path; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | uint64_t size; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | int type; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | } TarEntry; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | typedef struct TarInputStream { |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | FILE *file; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | TarEntry cur_entry; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | uint64_t cur_read; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | TarError error; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | } TarInputStream; |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | const char* tar_error2str(TarError error); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | TarOutputStream* tar_open(FILE *f); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | int tar_add_dir(TarOutputStream *tar, char *path, uint32_t mode, time_t mtime); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | int tar_begin_file( |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | TarOutputStream *tar, |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | char *path, |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | uint32_t mode, |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | uint64_t size, |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | time_t mtime); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | size_t tar_fwrite(const void *ptr, size_t s, size_t n, TarOutputStream *stream); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | int tar_end_file(TarOutputStream *tar); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | int tar_close(TarOutputStream *tar); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | TarInputStream* tar_inputstream_open(FILE *f); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | TarEntry* tar_read_entry(TarInputStream *tar); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | size_t tar_fread(void *ptr, size_t s, size_t n, TarInputStream *stream); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | int tar_inputstream_close(TarInputStream *tar); |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | #ifdef __cplusplus |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | } |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | #endif |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | #endif /* TAR_H */ |
5f80c5d0e87f
adds tar import/export
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 |