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