home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2003 November / VPR0311.ISO / OLS / TAR32223 / tar32223.lzh / tar32_2 / src / tar32.h < prev    next >
C/C++ Source or Header  |  2003-01-17  |  4KB  |  138 lines

  1. /*
  2.     tar32.h
  3.         tar/tgz/tbz/bz/gz archive manipulation class.
  4.         by Yoshioka Tsuneo(QWF00133@nifty.ne.jp)
  5. */
  6. /*    
  7.     このファイルの利用条件:
  8.         このソースファイルの利用制限は一切ありません。
  9.         ソースの一部、全部を商用、非商用など目的に
  10.         かかわりなく他のプログラムで自由に使用できます。
  11.         パブリック・ドメイン・ソフトウェアと同様に扱えます。
  12.     
  13.     プログラマ向けの要望(制限ではありません):
  14.         ソース中に改善すべき点があればお知らせください。
  15.         ソースコード中にバグを見つけた場合は報告してください。
  16.         直した部分などありましたら教えてください。
  17.         断片的な情報でも結構です。
  18.         このファイルを利用した場合はなるべく教えてください。
  19. */
  20. /*
  21.     LICENSE of this file:
  22.         There is no restriction for using this file.
  23.         You can use this file in your software for any purpose.
  24.         In other words, you can use this file as Public Domain Software.
  25.  
  26.     RECOMMENDATION for Programmer(not restriction):
  27.         If you find points to improve code, please report me.
  28.         If you find bug in source code, please report me.
  29.         If you fixed bug, please teach me.
  30.         I want any trivial information.
  31.         If you use this file, please report me.
  32. */
  33. #include "arcfile.h"
  34. #include <string>
  35.  
  36. #include "tar.h"
  37. #include <sys/types.h>    // stat
  38. #include <sys/stat.h>    // stat
  39.  
  40. using namespace std;
  41.  
  42. struct CTar32FileStatus{
  43.     CTar32FileStatus(){
  44.  
  45.         compress_size = original_size = blocksize = mode = uid = gid = mtime = chksum = typeflag = devmajor = devminor = atime = ctime = offset = 0;
  46.         mode = 0666;    // _S_IWRITE|_S_IREAD
  47.         memcpy(magic_version, TMAGIC "\0" TVERSION/*"ustar\000"*/,8);
  48.         strcpy(uname, "root");
  49.     }
  50.     string filename;
  51.     size_t original_size;
  52.     size_t compress_size;
  53.     int blocksize;
  54.  
  55.     int mode;
  56.     int uid;
  57.     int gid;
  58.     time_t mtime;
  59.     unsigned int chksum;
  60.     int typeflag;
  61.     string linkname;
  62.     char magic_version[8];
  63.     char uname[32];
  64.     char gname[32];
  65.     int  devmajor;
  66.     int  devminor;
  67.     time_t atime;
  68.     time_t ctime;
  69.     int offset;
  70.     bool SetFromFile(const char *fname){
  71.         struct _stat st;
  72.         if(_stat(fname,&st)==-1){return false;}
  73.         mode = st.st_mode;
  74.         uid = st.st_uid;
  75.         gid = st.st_gid;
  76.         mtime = st.st_mtime;
  77.         atime = st.st_atime;
  78.         ctime = st.st_ctime;
  79.         original_size = st.st_size;
  80.         if((st.st_mode & _S_IFMT) == _S_IFDIR){
  81.             typeflag = DIRTYPE;
  82.         }
  83.         return true;
  84.     }
  85. };
  86.  
  87. class CTar32InternalFile;
  88. class CTar32{
  89. public:
  90.     CTar32();
  91.     virtual ~CTar32();
  92.     static int s_get_archive_type(const char *arcfile);
  93.     bool open(const char *arcfile, const char*mode, int archive_type = ARCHIVETYPE_AUTO);
  94.     bool close();
  95.  
  96.     bool readdir(CTar32FileStatus *stat);
  97.     bool readskip();    // service function(not neccesary)
  98.     bool extract(const char *file=NULL);        // service function(not neccesary)
  99.  
  100.     bool addheader(const CTar32FileStatus &stat);
  101.     bool addbody(const char *file);    // survice function(not neccesary)
  102.  
  103.     CTar32FileStatus m_currentfile_status;
  104.     int m_archive_type;
  105.     string get_arc_filename(){return m_pfile->get_arc_filename();}
  106. private:
  107.     ITarArcFile *m_pfile;
  108.     int m_filecount;    
  109.     bool m_write_mode;
  110.     int m_error_code;
  111.  
  112.     /* for ar(a.out) format */
  113.     char *longfilenames_buf;
  114.  
  115.     friend CTar32InternalFile; // use m_currentfile_status.size
  116. };
  117.  
  118.  
  119. class CTar32InternalFile
  120. {
  121. public:
  122.     CTar32InternalFile();
  123.     ~CTar32InternalFile();
  124.     // open after CTar32::readdir() or CTar32()::addheader()
  125.     bool open(CTar32 *pTar32, bool bWrite = false);
  126.     int write(void *buf, int size);
  127.     int read(void *buf, int size);
  128.     bool close();
  129. private:
  130.     ITarArcFile *m_pfile;
  131.     int m_readsize;
  132.     int m_size;
  133.     int m_blocksize;
  134.     bool m_write;
  135. };
  136.  
  137.  
  138.