]>
cygwin.com Git - cygwin-apps/setup.git/blob - archive_tar_file.cc
89f62d22b0483bb8ad9f7fdcbeef0a67a4ecae5b
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
12 * Written by Robert Collins <rbtcollins@hotmail.com>
16 /* An individual stream from a tar archive. */
19 static const char *cvsid
= "\n%%% $Id$\n";
25 #include <sys/types.h>
26 #include <sys/fcntl.h>
29 #include "zlib/zlib.h"
30 #include "io_stream.h"
33 #include "archive_tar.h"
39 archive_tar_file::archive_tar_file (tar_state
& newstate
):state (newstate
)
43 archive_tar_file::~archive_tar_file ()
45 state
.header_read
= 0;
49 ssize_t
archive_tar_file::read (void *buffer
, size_t len
)
51 /* how many bytes do we want to give the user */
53 want
= min (len
, state
.file_length
- state
.file_offset
);
54 /* how many do we need to read after that to line up the file pointer */
56 roundup
= (512 - (want
% 512)) % 512;
60 got
= state
.parent
->read (buffer
, want
);
64 got2
= state
.parent
->read (throwaway
, roundup
);
65 if (got
== want
&& got2
== roundup
)
67 state
.file_offset
+= got
;
72 /* unexpected EOF or read error in the tar parent stream */
73 /* the user can query the parent for the error */
81 /* provide data to (double duh!) */
82 ssize_t
archive_tar_file::write (const void *buffer
, size_t len
)
84 /* write not supported */
88 /* read data without removing it from the class's internal buffer */
89 ssize_t
archive_tar_file::peek (void *buffer
, size_t len
)
92 want
= min (len
, state
.file_length
- state
.file_offset
);
96 got
= state
.parent
->peek (buffer
, want
);
103 /* unexpected EOF or read error in the tar parent stream */
104 /* the user can query the parent for the error */
113 archive_tar_file::tell ()
115 return state
.file_offset
;
119 archive_tar_file::seek (long where
, io_stream_seek_t whence
)
121 /* nothing needs seeking here yet. Implement when needed
126 /* try guessing this one */
128 archive_tar_file::error ()
130 return state
.lasterr
;
134 archive_tar_file::get_mtime ()
137 sscanf (state
.tar_header
.mtime
, "%o", &mtime
);
This page took 0.039694 seconds and 5 git commands to generate.