Logo Search packages:      
Sourcecode: tardy version File versions  Download package

int tar_input_filename::read_header ( tar_header &   )  [virtual]

The read_header method is used to read file information from the input. Returns 0 at end of input.

Implements tar_input.

Definition at line 99 of file filename.cc.

References tar_input::fatal(), length, name, source, and rcstring::to_c_string().

{
      result = tar_header();
      struct stat statbuf;
      if (lstat(name.to_c_string(), &statbuf))
            fatal("cannot stat: %s", strerror(errno));
      result.name = name;
      result.user_id = statbuf.st_uid;
      struct passwd *pw = getpwuid(statbuf.st_uid);
      if (pw)
            result.user_name = rcstring(pw->pw_name);
      result.group_id = statbuf.st_gid;
      struct group *gr = getgrgid(statbuf.st_gid);
      if (gr)
            result.group_name = rcstring(gr->gr_name);
      result.inode_number = statbuf.st_ino;
      switch (statbuf.st_mode & S_IFMT)
      {
      case S_IFSOCK:
            result.type = tar_header::type_socket;
            break;

      case S_IFLNK:
            {
                  result.type = tar_header::type_link_symbolic;
                  char linkname[2000];
                  int nbytes =
                        readlink
                        (
                                    name.to_c_string(),
                                    linkname,
                                    sizeof(linkname)
                        );
                  result.linkname = rcstring(linkname, nbytes);
            }
            break;

      case S_IFREG:
            result.type = tar_header::type_normal;
            length = statbuf.st_size;
            result.size = statbuf.st_size;
            source = new file_input_normal(name);
            break;

      case S_IFBLK:
            result.type = tar_header::type_device_block;
            result.device_major = major(statbuf.st_rdev);
            result.device_minor = minor(statbuf.st_rdev);
            break;

      case S_IFDIR:
            result.type = tar_header::type_directory;
            break;

      case S_IFCHR:
            result.type = tar_header::type_device_character;
            result.device_major = major(statbuf.st_rdev);
            result.device_minor = minor(statbuf.st_rdev);
            break;

      case S_IFIFO:
            result.type = tar_header::type_fifo;
            break;

      default:
            fatal("file type unknown");
            result.type = tar_header::type_normal;
            break;
      }
      result.atime = statbuf.st_atime;
      result.ctime = statbuf.st_ctime;
      result.mtime = statbuf.st_mtime;
      result.mode = statbuf.st_mode & 07777;
      return 1;
}


Generated by  Doxygen 1.6.0   Back to index