]>
Dogcows Code - chaz/tar/blob - src/xheader.c
1 /* This file is part of GNU Tar
3 Copyright (C) 2003 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any later
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 /* Forward declarations */
29 static void dummy_handler (struct tar_stat_info
*st
, char *keyword
, char *arg
);
31 static void atime_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
32 static void atime_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
34 static void gid_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
35 static void gid_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
37 static void gname_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
38 static void gname_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
40 static void linkpath_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
41 static void linkpath_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
43 static void mtime_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
44 static void mtime_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
46 static void ctime_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
47 static void ctime_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
49 static void path_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
50 static void path_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
52 static void size_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
53 static void size_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
55 static void uid_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
56 static void uid_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
58 static void uname_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
59 static void uname_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
);
61 /* General Interface */
66 void (*coder
) (struct tar_stat_info
*st
, char *keyword
, char *arg
);
67 void (*decoder
) (struct tar_stat_info
*st
, char *keyword
, char *arg
);
70 struct xhdr_tab xhdr_tab
[] = {
71 { "atime", atime_coder
, atime_decoder
},
72 { "comment", dummy_handler
, dummy_handler
},
73 { "charset", dummy_handler
, dummy_handler
},
74 { "ctime", ctime_coder
, ctime_decoder
},
75 { "gid", gid_coder
, gid_decoder
},
76 { "gname", gname_coder
, gname_decoder
},
77 { "linkpath", linkpath_coder
, linkpath_decoder
},
78 { "mtime", mtime_coder
, mtime_decoder
},
79 { "path", path_coder
, path_decoder
},
80 { "size", size_coder
, size_decoder
},
81 { "uid", uid_coder
, uid_decoder
},
82 { "uname", uname_coder
, uname_decoder
},
86 static struct xhdr_tab
*
87 locate_handler (char *keyword
)
91 for (p
= xhdr_tab
; p
->keyword
; p
++)
92 if (strcmp (p
->keyword
, keyword
) == 0)
98 decode_record (char **p
, struct tar_stat_info
*st
)
108 len
= strtoul (*p
, p
, 10);
111 ERROR ((0, 0, _("Malformed extended headed")));
116 for (;*p
< start
+ len
; ++*p
)
122 ERROR ((0, 0, _("Malformed extended headed")));
128 t
= locate_handler (keyword
);
138 t
->decoder (st
, keyword
, value
);
147 xheader_decode (struct tar_stat_info
*st
)
151 p
= extended_header
.blocks
->buffer
;
152 endp
= &extended_header
.blocks
[extended_header
.nblocks
-1].buffer
153 [sizeof(extended_header
.blocks
[0])-1];
155 if (decode_record (&p
, st
))
160 xheader_read (union block
*p
, size_t size
)
164 free (extended_header
.blocks
);
165 extended_header
.nblocks
= (size
+ BLOCKSIZE
- 1) / BLOCKSIZE
;
166 extended_header
.blocks
= xmalloc (sizeof (extended_header
.blocks
[0]) *
167 extended_header
.nblocks
);
168 set_next_block_after (p
);
169 for (i
= 0; i
< extended_header
.nblocks
; i
++)
171 p
= find_next_block ();
172 memcpy (&extended_header
.blocks
[i
], p
, sizeof (p
[0]));
173 set_next_block_after (p
);
178 /* Implementations */
180 dummy_handler (struct tar_stat_info
*st
, char *keyword
, char *arg
)
185 atime_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
190 atime_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
192 st
->stat
.st_atime
= strtoul (arg
, NULL
, 0);
196 gid_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
201 gid_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
203 st
->stat
.st_gid
= strtoul (arg
, NULL
, 0);
207 gname_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
212 gname_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
214 st
->gname
= strdup (arg
);
218 linkpath_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
223 linkpath_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
225 st
->link_name
= strdup (arg
);
229 ctime_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
234 ctime_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
236 st
->stat
.st_ctime
= strtoul (arg
, NULL
, 0);
240 mtime_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
245 mtime_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
247 st
->stat
.st_mtime
= strtoul (arg
, NULL
, 0);
251 path_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
256 path_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
258 assign_string (&st
->orig_file_name
, arg
);
259 assign_string (&st
->file_name
, arg
);
260 st
->had_trailing_slash
= strip_trailing_slashes (st
->file_name
);
264 size_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
269 size_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
271 st
->stat
.st_size
= strtoul (arg
, NULL
, 0);
275 uid_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
280 uid_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
282 st
->stat
.st_uid
= strtoul (arg
, NULL
, 0);
286 uname_coder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
291 uname_decoder (struct tar_stat_info
*st
, char *keyword
, char *arg
)
293 st
->uname
= strdup (arg
);
This page took 0.048266 seconds and 5 git commands to generate.