]> Dogcows Code - chaz/tar/blob - src/mangle.c
(first_mangle, mangled_num): Remove.
[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 /*---------------------------------------------------------------------.
37 | Extract a GNUTYPE_NAMES record contents. It seems that such are not |
38 | produced anymore by GNU tar, but we leave the reading code around |
39 | nevertheless, for salvaging old tapes. |
40 `---------------------------------------------------------------------*/
41
42 void
43 extract_mangle (void)
44 {
45 off_t size = current_stat.st_size;
46 char *buffer = xmalloc ((size_t) (size + 1));
47 char *copy = buffer;
48 char *cursor = buffer;
49
50 if (size != (size_t) size || size == (size_t) -1)
51 FATAL_ERROR ((0, 0, _("Memory exhausted")));
52
53 buffer[size] = '\0';
54
55 while (size > 0)
56 {
57 union block *block = find_next_block ();
58 size_t available;
59
60 if (!block)
61 {
62 ERROR ((0, 0, _("Unexpected EOF in mangled names")));
63 return;
64 }
65 available = available_space_after (block);
66 if (available > size)
67 available = size;
68 memcpy (copy, block->buffer, available);
69 copy += available;
70 size -= available;
71 set_next_block_after ((union block *) (block->buffer + available - 1));
72 }
73
74 while (*cursor)
75 {
76 char *next_cursor;
77 char *name;
78 char *name_end;
79
80 next_cursor = strchr (cursor, '\n');
81 *next_cursor++ = '\0';
82
83 if (!strncmp (cursor, "Rename ", 7))
84 {
85
86 name = cursor + 7;
87 name_end = strchr (name, ' ');
88 while (strncmp (name_end, " to ", 4))
89 {
90 name_end++;
91 name_end = strchr (name_end, ' ');
92 }
93 *name_end = '\0';
94 if (next_cursor[-2] == '/')
95 next_cursor[-2] = '\0';
96 unquote_string (name_end + 4);
97 if (rename (name, name_end + 4))
98 ERROR ((0, errno, _("Cannot rename %s to %s"), name, name_end + 4));
99 else if (verbose_option)
100 WARN ((0, 0, _("Renamed %s to %s"), name, name_end + 4));
101 }
102 #ifdef HAVE_SYMLINK
103 else if (!strncmp (cursor, "Symlink ", 8))
104 {
105 name = cursor + 8;
106 name_end = strchr (name, ' ');
107 while (strncmp (name_end, " to ", 4))
108 {
109 name_end++;
110 name_end = strchr (name_end, ' ');
111 }
112 *name_end = '\0';
113 unquote_string (name);
114 unquote_string (name_end + 4);
115 if (symlink (name, name_end + 4)
116 && (unlink (name_end + 4) || symlink (name, name_end + 4)))
117 ERROR ((0, errno, _("Cannot symlink %s to %s"),
118 name, name_end + 4));
119 else if (verbose_option)
120 WARN ((0, 0, _("Symlinked %s to %s"), name, name_end + 4));
121 }
122 #endif
123 else
124 ERROR ((0, 0, _("Unknown demangling command %s"), cursor));
125
126 cursor = next_cursor;
127 }
128 }
This page took 0.0426 seconds and 5 git commands to generate.