]> cygwin.com Git - cygwin-apps/setup.git/blame - archive_tar_file.cc
2003-10-23 Jerry D. Hedden <jerry@hedden.us>
[cygwin-apps/setup.git] / archive_tar_file.cc
CommitLineData
b24c88b3
RC
1/*
2 * Copyright (c) 2001, Robert Collins
3 *
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.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by Robert Collins <rbtcollins@hotmail.com>
13 *
14 */
15
16/* An individual stream from a tar archive. */
17
18#if 0
19static const char *cvsid = "\n%%% $Id$\n";
20#endif
21
b24c88b3 22#include <errno.h>
b34fb59f 23#include <algorithm>
b24c88b3
RC
24
25#include "zlib/zlib.h"
26#include "io_stream.h"
27#include "compress.h"
28#include "archive.h"
29#include "archive_tar.h"
30#include "log.h"
b24c88b3
RC
31
32#include "port.h"
33
34archive_tar_file::archive_tar_file (tar_state & newstate):state (newstate)
35{
36}
37
38archive_tar_file::~archive_tar_file ()
39{
40 state.header_read = 0;
e9440f0f 41 destroyed = 1;
b24c88b3
RC
42}
43
44/* Virtual memebrs */
45ssize_t archive_tar_file::read (void *buffer, size_t len)
46{
47 /* how many bytes do we want to give the user */
48 int
b34fb59f 49 want = std::min (len, state.file_length - state.file_offset);
b24c88b3
RC
50 /* how many do we need to read after that to line up the file pointer */
51 int
52 roundup = (512 - (want % 512)) % 512;
53 if (want)
54 {
55 ssize_t
56 got = state.parent->read (buffer, want);
57 char
58 throwaway[512];
59 ssize_t
60 got2 = state.parent->read (throwaway, roundup);
61 if (got == want && got2 == roundup)
62 {
63 state.file_offset += got;
64 return got;
65 }
66 else
67 {
68 /* unexpected EOF or read error in the tar parent stream */
69 /* the user can query the parent for the error */
70 state.lasterr = EIO;
71 return EIO;
72 }
73 }
74 return 0;
75}
76
77/* provide data to (double duh!) */
ca9506cc 78ssize_t archive_tar_file::write (const void *buffer, size_t len)
b24c88b3
RC
79{
80 /* write not supported */
81 return EBADF;
82}
83
84/* read data without removing it from the class's internal buffer */
85ssize_t archive_tar_file::peek (void *buffer, size_t len)
86{
87 int
b34fb59f 88 want = std::min (len, state.file_length - state.file_offset);
b24c88b3
RC
89 if (want)
90 {
91 ssize_t
92 got = state.parent->peek (buffer, want);
93 if (got == want)
94 {
95 return got;
96 }
97 else
98 {
99 /* unexpected EOF or read error in the tar parent stream */
100 /* the user can query the parent for the error */
101 state.lasterr = EIO;
102 return EIO;
103 }
104 }
105 return 0;
106}
107
108long
109archive_tar_file::tell ()
110{
111 return state.file_offset;
112}
113
ca9506cc
RC
114int
115archive_tar_file::seek (long where, io_stream_seek_t whence)
116{
117 /* nothing needs seeking here yet. Implement when needed
118 */
119 return -1;
120}
121
b24c88b3
RC
122/* try guessing this one */
123int
124archive_tar_file::error ()
125{
126 return state.lasterr;
127}
128
129int
130archive_tar_file::get_mtime ()
131{
132 int mtime;
133 sscanf (state.tar_header.mtime, "%o", &mtime);
134 return mtime;
135}
This page took 0.042222 seconds and 5 git commands to generate.