Mercurial > pidgin.yaz
annotate src/win32/untar.c @ 10798:08981462ebbb
[gaim-migrate @ 12441]
smooth scrolling
I'll assume you can figure out how to adjust how long it takes to scroll,
so you can play with it.
I expect feedback.
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Fri, 08 Apr 2005 22:44:02 +0000 |
parents | 0f7452b1f777 |
children |
rev | line source |
---|---|
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
1 /* untar.c */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
2 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
3 /*#define VERSION "1.4"*/ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
4 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
5 /* DESCRIPTION: |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
6 * Untar extracts files from an uncompressed tar archive, or one which |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
7 * has been compressed with gzip. Usually such archives will have file |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
8 * names that end with ".tar" or ".tgz" respectively, although untar |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
9 * doesn't depend on any naming conventions. For a summary of the |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
10 * command-line options, run untar with no arguments. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
11 * |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
12 * HOW TO COMPILE: |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
13 * Untar doesn't require any special libraries or compile-time flags. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
14 * A simple "cc untar.c -o untar" (or the local equivalent) is |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
15 * sufficient. Even "make untar" works, without needing a Makefile. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
16 * For Microsoft Visual C++, the command is "cl /D_WEAK_POSIX untar.c" |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
17 * (for 32 bit compilers) or "cl /F 1400 untar.c" (for 16-bit). |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
18 * |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
19 * IF YOU SEE COMPILER WARNINGS, THAT'S NORMAL; you can ignore them. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
20 * Most of the warnings could be eliminated by adding #include <string.h> |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
21 * but that isn't portable -- some systems require <strings.h> and |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
22 * <malloc.h>, for example. Because <string.h> isn't quite portable, |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
23 * and isn't really necessary in the context of this program, it isn't |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
24 * included. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
25 * |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
26 * PORTABILITY: |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
27 * Untar only requires the <stdio.h> header. It uses old-style function |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
28 * definitions. It opens all files in binary mode. Taken together, |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
29 * this means that untar should compile & run on just about anything. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
30 * |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
31 * If your system supports the POSIX chmod(2), utime(2), link(2), and |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
32 * symlink(2) calls, then you may wish to compile with -D_POSIX_SOURCE, |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
33 * which will enable untar to use those system calls to restore the |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
34 * timestamp and permissions of the extracted files, and restore links. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
35 * (For Linux, _POSIX_SOURCE is always defined.) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
36 * |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
37 * For systems which support some POSIX features but not enough to support |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
38 * -D_POSIX_SOURCE, you might be able to use -D_WEAK_POSIX. This allows |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
39 * untar to restore time stamps and file permissions, but not links. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
40 * This should work for Microsoft systems, and hopefully others as well. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
41 * |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
42 * AUTHOR & COPYRIGHT INFO: |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
43 * Written by Steve Kirkendall, kirkenda@cs.pdx.edu |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
44 * Placed in public domain, 6 October 1995 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
45 * |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
46 * Portions derived from inflate.c -- Not copyrighted 1992 by Mark Adler |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
47 * version c10p1, 10 January 1993 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
48 * |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
49 * Altered by Herman Bloggs <hermanator12002@yahoo.com> |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
50 * April 4, 2003 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
51 * Changes: Stripped out gz compression code, added better interface for |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
52 * untar. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
53 */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
54 #include <windows.h> |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
55 #include <stdio.h> |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
56 #include <io.h> |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
57 #include <string.h> |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
58 #include <stdlib.h> |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
59 #ifndef SEEK_SET |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
60 # define SEEK_SET 0 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
61 #endif |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
62 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
63 #ifdef _WEAK_POSIX |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
64 # ifndef _POSIX_SOURCE |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
65 # define _POSIX_SOURCE |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
66 # endif |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
67 #endif |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
68 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
69 #ifdef _POSIX_SOURCE |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
70 # include <sys/types.h> |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
71 # include <sys/stat.h> |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
72 # include <sys/utime.h> |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
73 # ifdef _WEAK_POSIX |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
74 # define mode_t int |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
75 # else |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
76 # include <unistd.h> |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
77 # endif |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
78 #endif |
6425
26b739bc9f1a
[gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5005
diff
changeset
|
79 #include "debug.h" |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
80 #include "untar.h" |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
81 #include <glib.h> |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
82 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
83 #if GLIB_CHECK_VERSION(2,6,0) |
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
84 # include <glib/gstdio.h> |
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
85 #else |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
86 #define mkdir(a,b) _mkdir((a)) |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
87 #define g_mkdir mkdir |
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
88 #define g_fopen fopen |
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
89 #define g_unlink unlink |
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
90 #endif |
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
91 |
7242
59ffe137176d
[gaim-migrate @ 7817]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
92 #define untar_error( error, args... ) gaim_debug(GAIM_DEBUG_ERROR, "untar", error, ## args ) |
59ffe137176d
[gaim-migrate @ 7817]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
6425
diff
changeset
|
93 #define untar_warning( warning, args... ) gaim_debug(GAIM_DEBUG_WARNING, "untar", warning, ## args ) |
6425
26b739bc9f1a
[gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5005
diff
changeset
|
94 #define untar_verbose( args... ) gaim_debug(GAIM_DEBUG_INFO, "untar", ## args ) |
26b739bc9f1a
[gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5005
diff
changeset
|
95 |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
96 #define WSIZE 32768 /* size of decompression buffer */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
97 #define TSIZE 512 /* size of a "tape" block */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
98 #define CR 13 /* carriage-return character */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
99 #define LF 10 /* line-feed character */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
100 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
101 typedef unsigned char Uchar_t; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
102 typedef unsigned short Ushort_t; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
103 typedef unsigned long Ulong_t; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
104 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
105 typedef struct |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
106 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
107 char filename[100]; /* 0 name of next file */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
108 char mode[8]; /* 100 Permissions and type (octal digits) */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
109 char owner[8]; /* 108 Owner ID (ignored) */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
110 char group[8]; /* 116 Group ID (ignored) */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
111 char size[12]; /* 124 Bytes in file (octal digits) */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
112 char mtime[12]; /* 136 Modification time stamp (octal digits)*/ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
113 char checksum[8]; /* 148 Header checksum (ignored) */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
114 char type; /* 156 File type (see below) */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
115 char linkto[100]; /* 157 Linked-to name */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
116 char brand[8]; /* 257 Identifies tar version (ignored) */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
117 char ownername[32]; /* 265 Name of owner (ignored) */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
118 char groupname[32]; /* 297 Name of group (ignored) */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
119 char devmajor[8]; /* 329 Device major number (ignored) */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
120 char defminor[8]; /* 337 Device minor number (ignored) */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
121 char prefix[155]; /* 345 Prefix of name (optional) */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
122 char RESERVED[12]; /* 500 Pad header size to 512 bytes */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
123 } tar_t; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
124 #define ISREGULAR(hdr) ((hdr).type < '1' || (hdr).type > '6') |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
125 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
126 Uchar_t slide[WSIZE]; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
127 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
128 static const char *inname = NULL; /* name of input archive */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
129 static FILE *infp = NULL; /* input byte stream */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
130 static FILE *outfp = NULL; /* output stream, for file currently being extracted */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
131 static Ulong_t outsize = 0; /* number of bytes remainin in file currently being extracted */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
132 static char **only = NULL; /* array of filenames to extract/list */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
133 static int nonlys = 0; /* number of filenames in "only" array; 0=extract all */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
134 static int didabs = 0; /* were any filenames affected by the absence of -p? */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
135 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
136 static untar_opt untarops = 0; /* Untar options */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
137 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
138 /* Options checked during untar process */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
139 #define LISTING (untarops & UNTAR_LISTING) /* 1 if listing, 0 if extracting */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
140 #define QUIET (untarops & UNTAR_QUIET) /* 1 to write nothing to stdout, 0 for normal chatter */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
141 #define VERBOSE (untarops & UNTAR_VERBOSE) /* 1 to write extra information to stdout */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
142 #define FORCE (untarops & UNTAR_FORCE) /* 1 to overwrite existing files, 0 to skip them */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
143 #define ABSPATH (untarops & UNTAR_ABSPATH) /* 1 to allow leading '/', 0 to strip leading '/' */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
144 #define CONVERT (untarops & UNTAR_CONVERT) /* 1 to convert newlines, 0 to leave unchanged */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
145 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
146 /*----------------------------------------------------------------------------*/ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
147 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
148 /* create a file for writing. If necessary, create the directories leading up |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
149 * to that file as well. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
150 */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
151 static FILE *createpath(name) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
152 char *name; /* pathname of file to create */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
153 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
154 FILE *fp; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
155 int i; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
156 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
157 /* if we aren't allowed to overwrite and this file exists, return NULL */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
158 if (!FORCE && access(name, 0) == 0) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
159 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
160 untar_warning("%s: exists, will not overwrite without \"FORCE option\"\n", name); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
161 return NULL; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
162 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
163 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
164 /* first try creating it the easy way */ |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
165 fp = g_fopen(name, CONVERT ? "w" : "wb"); |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
166 if (fp) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
167 return fp; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
168 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
169 /* Else try making all of its directories, and then try creating |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
170 * the file again. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
171 */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
172 for (i = 0; name[i]; i++) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
173 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
174 /* If this is a slash, then temporarily replace the '/' |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
175 * with a '\0' and do a mkdir() on the resulting string. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
176 * Ignore errors for now. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
177 */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
178 if (name[i] == '/') |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
179 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
180 name[i] = '\0'; |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
181 (void)g_mkdir(name, 0777); |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
182 name[i] = '/'; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
183 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
184 } |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
185 fp = g_fopen(name, CONVERT ? "w" : "wb"); |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
186 if (!fp) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
187 untar_error("Error opening: %s\n", name); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
188 return fp; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
189 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
190 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
191 /* Create a link, or copy a file. If the file is copied (not linked) then |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
192 * give a warning. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
193 */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
194 static void linkorcopy(src, dst, sym) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
195 char *src; /* name of existing source file */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
196 char *dst; /* name of new destination file */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
197 int sym; /* use symlink instead of link */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
198 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
199 FILE *fpsrc; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
200 FILE *fpdst; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
201 int c; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
202 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
203 /* Open the source file. We do this first to make sure it exists */ |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
204 fpsrc = g_fopen(src, "rb"); |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
205 if (!fpsrc) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
206 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
207 untar_error("Error opening: %s\n", src); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
208 return; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
209 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
210 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
211 /* Create the destination file. On POSIX systems, this is just to |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
212 * make sure the directory path exists. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
213 */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
214 fpdst = createpath(dst); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
215 if (!fpdst) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
216 /* error message already given */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
217 return; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
218 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
219 #ifdef _POSIX_SOURCE |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
220 # ifndef _WEAK_POSIX |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
221 /* first try to link it over, instead of copying */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
222 fclose(fpdst); |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
223 g_unlink(dst); |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
224 if (sym) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
225 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
226 if (symlink(src, dst)) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
227 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
228 perror(dst); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
229 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
230 fclose(fpsrc); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
231 return; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
232 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
233 if (!link(src, dst)) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
234 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
235 /* This story had a happy ending */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
236 fclose(fpsrc); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
237 return; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
238 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
239 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
240 /* Dang. Reopen the destination again */ |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
241 fpdst = g_fopen(dst, "wb"); |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
242 /* This *can't* fail */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
243 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
244 # endif /* _WEAK_POSIX */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
245 #endif /* _POSIX_SOURCE */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
246 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
247 /* Copy characters */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
248 while ((c = getc(fpsrc)) != EOF) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
249 putc(c, fpdst); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
250 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
251 /* Close the files */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
252 fclose(fpsrc); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
253 fclose(fpdst); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
254 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
255 /* Give a warning */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
256 untar_warning("%s: copy instead of link\n", dst); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
257 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
258 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
259 /* This calls fwrite(), possibly after converting CR-LF to LF */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
260 static void cvtwrite(blk, size, fp) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
261 Uchar_t *blk; /* the block to be written */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
262 Ulong_t size; /* number of characters to be written */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
263 FILE *fp; /* file to write to */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
264 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
265 int i, j; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
266 static Uchar_t mod[TSIZE]; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
267 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
268 if (CONVERT) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
269 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
270 for (i = j = 0; i < size; i++) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
271 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
272 /* convert LF to local newline convention */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
273 if (blk[i] == LF) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
274 mod[j++] = '\n'; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
275 /* If CR-LF pair, then delete the CR */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
276 else if (blk[i] == CR && (i+1 >= size || blk[i+1] == LF)) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
277 ; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
278 /* other characters copied literally */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
279 else |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
280 mod[j++] = blk[i]; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
281 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
282 size = j; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
283 blk = mod; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
284 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
285 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
286 fwrite(blk, (size_t)size, sizeof(Uchar_t), fp); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
287 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
288 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
289 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
290 /* Compute the checksum of a tar header block, and return it as a long int. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
291 * The checksum can be computed using either POSIX rules (unsigned bytes) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
292 * or Sun rules (signed bytes). |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
293 */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
294 static long checksum(tblk, sunny) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
295 tar_t *tblk; /* buffer containing the tar header block */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
296 int sunny; /* Boolean: Sun-style checksums? (else POSIX) */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
297 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
298 long sum; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
299 char *scan; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
300 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
301 /* compute the sum of the first 148 bytes -- everything up to but not |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
302 * including the checksum field itself. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
303 */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
304 sum = 0L; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
305 for (scan = (char *)tblk; scan < tblk->checksum; scan++) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
306 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
307 sum += (*scan) & 0xff; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
308 if (sunny && (*scan & 0x80) != 0) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
309 sum -= 256; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
310 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
311 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
312 /* for the 8 bytes of the checksum field, add blanks to the sum */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
313 sum += ' ' * sizeof tblk->checksum; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
314 scan += sizeof tblk->checksum; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
315 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
316 /* finish counting the sum of the rest of the block */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
317 for (; scan < (char *)tblk + sizeof *tblk; scan++) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
318 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
319 sum += (*scan) & 0xff; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
320 if (sunny && (*scan & 0x80) != 0) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
321 sum -= 256; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
322 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
323 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
324 return sum; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
325 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
326 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
327 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
328 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
329 /* list files in an archive, and optionally extract them as well */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
330 static int untar_block(Uchar_t *blk) { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
331 static char nbuf[256];/* storage space for prefix+name, combined */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
332 static char *name,*n2;/* prefix and name, combined */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
333 static int first = 1;/* Boolean: first block of archive? */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
334 long sum; /* checksum for this block */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
335 int i; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
336 tar_t tblk[1]; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
337 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
338 #ifdef _POSIX_SOURCE |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
339 static mode_t mode; /* file permissions */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
340 static struct utimbuf timestamp; /* file timestamp */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
341 #endif |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
342 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
343 /* make a local copy of the block, and treat it as a tar header */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
344 tblk[0] = *(tar_t *)blk; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
345 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
346 /* process each type of tape block differently */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
347 if (outsize > TSIZE) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
348 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
349 /* data block, but not the last one */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
350 if (outfp) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
351 cvtwrite(blk, (Ulong_t)TSIZE, outfp); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
352 outsize -= TSIZE; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
353 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
354 else if (outsize > 0) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
355 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
356 /* last data block of current file */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
357 if (outfp) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
358 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
359 cvtwrite(blk, outsize, outfp); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
360 fclose(outfp); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
361 outfp = NULL; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
362 #ifdef _POSIX_SOURCE |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
363 utime(nbuf, ×tamp); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
364 chmod(nbuf, mode); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
365 #endif |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
366 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
367 outsize = 0; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
368 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
369 else if ((tblk)->filename[0] == '\0') |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
370 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
371 /* end-of-archive marker */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
372 if (didabs) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
373 untar_warning("Removed leading slashes because \"ABSPATH option\" wasn't given.\n"); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
374 return 1; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
375 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
376 else |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
377 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
378 /* file header */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
379 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
380 /* half-assed verification -- does it look like header? */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
381 if ((tblk)->filename[99] != '\0' |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
382 || ((tblk)->size[0] < '0' |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
383 && (tblk)->size[0] != ' ') |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
384 || (tblk)->size[0] > '9') |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
385 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
386 if (first) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
387 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
388 untar_error("%s: not a valid tar file\n", inname); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
389 return 0; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
390 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
391 else |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
392 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
393 untar_error("Garbage detected; preceding file may be damaged\n"); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
394 return 0; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
395 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
396 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
397 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
398 /* combine prefix and filename */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
399 memset(nbuf, 0, sizeof nbuf); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
400 name = nbuf; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
401 if ((tblk)->prefix[0]) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
402 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
403 strncpy(name, (tblk)->prefix, sizeof (tblk)->prefix); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
404 strcat(name, "/"); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
405 strncat(name + strlen(name), (tblk)->filename, |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
406 sizeof (tblk)->filename); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
407 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
408 else |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
409 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
410 strncpy(name, (tblk)->filename, |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
411 sizeof (tblk)->filename); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
412 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
413 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
414 /* Convert any backslashes to forward slashes, and guard |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
415 * against doubled-up slashes. (Some DOS versions of "tar" |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
416 * get this wrong.) Also strip off leading slashes. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
417 */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
418 if (!ABSPATH && (*name == '/' || *name == '\\')) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
419 didabs = 1; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
420 for (n2 = nbuf; *name; name++) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
421 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
422 if (*name == '\\') |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
423 *name = '/'; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
424 if (*name != '/' |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
425 || (ABSPATH && n2 == nbuf) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
426 || (n2 != nbuf && n2[-1] != '/')) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
427 *n2++ = *name; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
428 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
429 if (n2 == nbuf) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
430 *n2++ = '/'; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
431 *n2 = '\0'; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
432 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
433 /* verify the checksum */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
434 for (sum = 0L, i = 0; i < sizeof((tblk)->checksum); i++) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
435 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
436 if ((tblk)->checksum[i] >= '0' |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
437 && (tblk)->checksum[i] <= '7') |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
438 sum = sum * 8 + (tblk)->checksum[i] - '0'; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
439 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
440 if (sum != checksum(tblk, 0) && sum != checksum(tblk, 1)) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
441 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
442 if (!first) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
443 untar_error("Garbage detected; preceding file may be damaged\n"); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
444 untar_error("%s: header has bad checksum for %s\n", inname, nbuf); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
445 return 0; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
446 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
447 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
448 /* From this point on, we don't care whether this is the first |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
449 * block or not. Might as well reset the "first" flag now. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
450 */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
451 first = 0; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
452 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
453 /* if last character of name is '/' then assume directory */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
454 if (*nbuf && nbuf[strlen(nbuf) - 1] == '/') |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
455 (tblk)->type = '5'; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
456 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
457 /* convert file size */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
458 for (outsize = 0L, i = 0; i < sizeof((tblk)->size); i++) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
459 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
460 if ((tblk)->size[i] >= '0' && (tblk)->size[i] <= '7') |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
461 outsize = outsize * 8 + (tblk)->size[i] - '0'; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
462 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
463 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
464 #ifdef _POSIX_SOURCE |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
465 /* convert file timestamp */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
466 for (timestamp.modtime=0L, i=0; i < sizeof((tblk)->mtime); i++) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
467 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
468 if ((tblk)->mtime[i] >= '0' && (tblk)->mtime[i] <= '7') |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
469 timestamp.modtime = timestamp.modtime * 8 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
470 + (tblk)->mtime[i] - '0'; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
471 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
472 timestamp.actime = timestamp.modtime; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
473 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
474 /* convert file permissions */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
475 for (mode = i = 0; i < sizeof((tblk)->mode); i++) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
476 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
477 if ((tblk)->mode[i] >= '0' && (tblk)->mode[i] <= '7') |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
478 mode = mode * 8 + (tblk)->mode[i] - '0'; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
479 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
480 #endif |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
481 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
482 /* If we have an "only" list, and this file isn't in it, |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
483 * then skip it. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
484 */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
485 if (nonlys > 0) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
486 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
487 for (i = 0; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
488 i < nonlys |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
489 && strcmp(only[i], nbuf) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
490 && (strncmp(only[i], nbuf, strlen(only[i])) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
491 || nbuf[strlen(only[i])] != '/'); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
492 i++) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
493 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
494 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
495 if (i >= nonlys) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
496 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
497 outfp = NULL; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
498 return 1; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
499 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
500 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
501 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
502 /* list the file */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
503 if (VERBOSE) |
6425
26b739bc9f1a
[gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5005
diff
changeset
|
504 untar_verbose("%c %s", |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
505 ISREGULAR(*tblk) ? '-' : ("hlcbdp"[(tblk)->type - '1']), |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
506 nbuf); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
507 else if (!QUIET) |
6425
26b739bc9f1a
[gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5005
diff
changeset
|
508 untar_verbose("%s\n", nbuf); |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
509 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
510 /* if link, then do the link-or-copy thing */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
511 if (tblk->type == '1' || tblk->type == '2') |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
512 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
513 if (VERBOSE) |
6425
26b739bc9f1a
[gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5005
diff
changeset
|
514 untar_verbose(" -> %s\n", tblk->linkto); |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
515 if (!LISTING) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
516 linkorcopy(tblk->linkto, nbuf, tblk->type == '2'); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
517 outsize = 0L; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
518 return 1; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
519 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
520 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
521 /* If directory, then make a weak attempt to create it. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
522 * Ideally we would do the "create path" thing, but that |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
523 * seems like more trouble than it's worth since traditional |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
524 * tar archives don't contain directories anyway. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
525 */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
526 if (tblk->type == '5') |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
527 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
528 if (LISTING) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
529 n2 = " directory"; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
530 #ifdef _POSIX_SOURCE |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
531 else if (mkdir(nbuf, mode) == 0) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
532 #else |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
533 else if (g_mkdir(nbuf, 0755) == 0) |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
534 #endif |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
535 n2 = " created"; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
536 else |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
537 n2 = " ignored"; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
538 if (VERBOSE) |
6425
26b739bc9f1a
[gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5005
diff
changeset
|
539 untar_verbose("%s\n", n2); |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
540 return 1; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
541 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
542 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
543 /* if not a regular file, then skip it */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
544 if (!ISREGULAR(*tblk)) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
545 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
546 if (VERBOSE) |
6425
26b739bc9f1a
[gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5005
diff
changeset
|
547 untar_verbose(" ignored\n"); |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
548 outsize = 0L; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
549 return 1; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
550 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
551 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
552 /* print file statistics */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
553 if (VERBOSE) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
554 { |
6425
26b739bc9f1a
[gaim-migrate @ 6933]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5005
diff
changeset
|
555 untar_verbose(" (%ld byte%s, %ld tape block%s)\n", |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
556 outsize, |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
557 outsize == 1 ? "" : "s", |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
558 (outsize + TSIZE - 1) / TSIZE, |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
559 (outsize > 0 && outsize <= TSIZE) ? "" : "s"); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
560 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
561 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
562 /* if extracting, then try to create the file */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
563 if (!LISTING) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
564 outfp = createpath(nbuf); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
565 else |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
566 outfp = NULL; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
567 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
568 /* if file is 0 bytes long, then we're done already! */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
569 if (outsize == 0 && outfp) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
570 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
571 fclose(outfp); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
572 #ifdef _POSIX_SOURCE |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
573 utime(nbuf, ×tamp); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
574 chmod(nbuf, mode); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
575 #endif |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
576 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
577 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
578 return 1; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
579 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
580 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
581 /* Process an archive file. This involves reading the blocks one at a time |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
582 * and passing them to a untar() function. |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
583 */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
584 int untar(const char *filename, const char* destdir, untar_opt options) { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
585 int ret=1; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
586 char curdir[_MAX_PATH]; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
587 untarops = options; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
588 /* open the archive */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
589 inname = filename; |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
7242
diff
changeset
|
590 infp = g_fopen(filename, "rb"); |
5005
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
591 if (!infp) |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
592 { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
593 untar_error("Error opening: %s\n", filename); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
594 return 0; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
595 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
596 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
597 /* Set current directory */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
598 if(!GetCurrentDirectory(_MAX_PATH, curdir)) { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
599 untar_error("Could not get current directory (error %d).\n", GetLastError()); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
600 fclose(infp); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
601 return 0; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
602 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
603 if(!SetCurrentDirectory(destdir)) { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
604 untar_error("Could not set current directory to (error %d): %s\n", GetLastError(), destdir); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
605 fclose(infp); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
606 return 0; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
607 } else { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
608 /* UNCOMPRESSED */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
609 /* send each block to the untar_block() function */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
610 while (fread(slide, 1, TSIZE, infp) == TSIZE) { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
611 if(!untar_block(slide)) { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
612 untar_error("untar failure: %s\n", filename); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
613 fclose(infp); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
614 ret=0; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
615 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
616 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
617 if (outsize > 0 && ret) { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
618 untar_warning("Last file might be truncated!\n"); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
619 fclose(outfp); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
620 outfp = NULL; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
621 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
622 if(!SetCurrentDirectory(curdir)) { |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
623 untar_error("Could not set current dir back to original (error %d).\n", GetLastError()); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
624 ret=0; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
625 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
626 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
627 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
628 /* close the archive file. */ |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
629 fclose(infp); |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
630 |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
631 return ret; |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
632 } |
a1f9725f4816
[gaim-migrate @ 5340]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
633 |