Regenerate Japanese resources
[cygwin-setup.git] / archive_tar_file.cc
blob1b43677393944f4b55a2c2a80f000352dacc05c0
1 /*
2 * Copyright (c) 2001, Robert Collins
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
12 * Written by Robert Collins <rbtcollins@hotmail.com>
16 /* An individual stream from a tar archive. */
18 #include <errno.h>
19 #include <algorithm>
21 #include "io_stream.h"
22 #include "compress.h"
23 #include "archive.h"
24 #include "archive_tar.h"
26 archive_tar_file::archive_tar_file (tar_state & newstate):read_something (false), state (newstate)
30 archive_tar_file::~archive_tar_file ()
32 if (read_something)
33 state.header_read = 0;
36 /* Virtual memebrs */
37 ssize_t archive_tar_file::read (void *buffer, size_t len)
39 /* how many bytes do we want to give the user */
40 int
41 want = std::min ((off_t) len, state.file_length - state.file_offset);
42 /* how many do we need to read after that to line up the file pointer */
43 int
44 roundup = (512 - (want % 512)) % 512;
45 read_something = true;
46 if (want)
48 int need = want;
49 char *p = (char *)buffer;
50 while (need > 0)
52 ssize_t got = state.parent->read (p, need);
53 if (got <= 0)
55 /* unexpected EOF or read error in the tar parent stream */
56 /* the user can query the parent for the error */
57 state.lasterr = EIO;
58 return -1;
60 p += got;
61 need -= got;
64 char throwaway[512];
65 p = &throwaway[0];
66 while (roundup > 0)
68 ssize_t got2 = state.parent->read (p, roundup);
69 if (got2 <= 0)
71 /* unexpected EOF or read error in the tar parent stream */
72 /* the user can query the parent for the error */
73 state.lasterr = EIO;
74 return -1;
76 p += got2;
77 roundup -= got2;
80 state.file_offset += want;
81 return want;
83 return 0;
86 /* provide data to (double duh!) */
87 ssize_t archive_tar_file::write (const void *buffer, size_t len)
89 /* write not supported */
90 state.lasterr = EBADF;
91 return -1;
94 /* read data without removing it from the class's internal buffer */
95 ssize_t archive_tar_file::peek (void *buffer, size_t len)
97 int
98 want = std::min ((off_t) len, state.file_length - state.file_offset);
99 if (want)
101 ssize_t
102 got = state.parent->peek (buffer, want);
103 if (got == want)
105 return got;
107 else
109 /* unexpected EOF or read error in the tar parent stream */
110 /* the user can query the parent for the error */
111 state.lasterr = EIO;
112 return -1;
115 return 0;
118 off_t
119 archive_tar_file::tell ()
121 return state.file_offset;
124 off_t
125 archive_tar_file::seek (off_t where, io_stream_seek_t whence)
127 /* nothing needs seeking here yet. Implement when needed
129 state.lasterr = EINVAL;
130 return -1;
133 /* try guessing this one */
135 archive_tar_file::error ()
137 return state.lasterr;
140 time_t
141 archive_tar_file::get_mtime ()
143 unsigned long mtime;
144 sscanf (state.tar_header.mtime, "%lo", &mtime);
145 return (time_t) mtime;
148 mode_t
149 archive_tar_file::get_mode ()
151 unsigned long mode;
152 sscanf (state.tar_header.mode, "%lo", &mode);
153 return (mode_t) mode;