]> Dogcows Code - chaz/tar/blob - src/mangle.c
(time): Do not declare if defined.
[chaz/tar] / src / mangle.c
1 /* Encode long filenames for GNU tar.
2 Copyright 1988, 1992, 1994, 1996, 1997, 1999 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12 Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 #include "system.h"
19
20 #include <time.h>
21 #ifndef time
22 time_t time ();
23 #endif
24
25 #include "common.h"
26
27 struct mangled
28 {
29 struct mangled *next;
30 int type;
31 char mangled[NAME_FIELD_SIZE];
32 char *linked_to;
33 char normal[1];
34 };
35
36 /* Should use a hash table, etc. . */
37 static struct mangled *first_mangle;
38 static int mangled_num;
39
40 /*---------------------------------------------------------------------.
41 | Extract a GNUTYPE_NAMES record contents. It seems that such are not |
42 | produced anymore by GNU tar, but we leave the reading code around |
43 | nevertheless, for salvaging old tapes. |
44 `---------------------------------------------------------------------*/
45
46 void
47 extract_mangle (void)
48 {
49 off_t size = current_stat.st_size;
50 char *buffer = xmalloc ((size_t) (size + 1));
51 char *copy = buffer;
52 char *cursor = buffer;
53
54 if (size != (size_t) size || size == (size_t) -1)
55 FATAL_ERROR ((0, 0, _("Memory exhausted")));
56
57 buffer[size] = '\0';
58
59 while (size > 0)
60 {
61 union block *block = find_next_block ();
62 size_t available;
63
64 if (!block)
65 {
66 ERROR ((0, 0, _("Unexpected EOF in mangled names")));
67 return;
68 }
69 available = available_space_after (block);
70 if (available > size)
71 available = size;
72 memcpy (copy, block->buffer, available);
73 copy += available;
74 size -= available;
75 set_next_block_after ((union block *) (block->buffer + available - 1));
76 }
77
78 while (*cursor)
79 {
80 char *next_cursor;
81 char *name;
82 char *name_end;
83
84 next_cursor = strchr (cursor, '\n');
85 *next_cursor++ = '\0';
86
87 if (!strncmp (cursor, "Rename ", 7))
88 {
89
90 name = cursor + 7;
91 name_end = strchr (name, ' ');
92 while (strncmp (name_end, " to ", 4))
93 {
94 name_end++;
95 name_end = strchr (name_end, ' ');
96 }
97 *name_end = '\0';
98 if (next_cursor[-2] == '/')
99 next_cursor[-2] = '\0';
100 unquote_string (name_end + 4);
101 if (rename (name, name_end + 4))
102 ERROR ((0, errno, _("Cannot rename %s to %s"), name, name_end + 4));
103 else if (verbose_option)
104 WARN ((0, 0, _("Renamed %s to %s"), name, name_end + 4));
105 }
106 #ifdef HAVE_SYMLINK
107 else if (!strncmp (cursor, "Symlink ", 8))
108 {
109 name = cursor + 8;
110 name_end = strchr (name, ' ');
111 while (strncmp (name_end, " to ", 4))
112 {
113 name_end++;
114 name_end = strchr (name_end, ' ');
115 }
116 *name_end = '\0';
117 unquote_string (name);
118 unquote_string (name_end + 4);
119 if (symlink (name, name_end + 4)
120 && (unlink (name_end + 4) || symlink (name, name_end + 4)))
121 ERROR ((0, errno, _("Cannot symlink %s to %s"),
122 name, name_end + 4));
123 else if (verbose_option)
124 WARN ((0, 0, _("Symlinked %s to %s"), name, name_end + 4));
125 }
126 #endif
127 else
128 ERROR ((0, 0, _("Unknown demangling command %s"), cursor));
129
130 cursor = next_cursor;
131 }
132 }
This page took 0.047317 seconds and 5 git commands to generate.