bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

copyin.c cpio probably questions/rfc


From: Grzegorz Jaskiewicz
Subject: copyin.c cpio probably questions/rfc
Date: Tue, 24 Jun 2003 17:12:45 +0100
User-agent: KMail/1.5.9

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi!

I am currently working on module that (in GNU software) will be able to 
read/write cpio format (only ascii). Thus i am separating some of cpio 
structures into libcpio. I've been going through copyin.c file and i found 
this:

      while (archive_format == arf_unknown)
        {
          peeked_bytes = tape_buffered_peek (tmpbuf, in_des, 512);
          if (peeked_bytes < 6)
            error (1, 0, "premature end of archive");

          if (!strncmp (tmpbuf, "070701", 6))
            archive_format = arf_newascii;
          else if (!strncmp (tmpbuf, "070707", 6))
            archive_format = arf_oldascii;
..........
Some part of file is read into buffer and search for header begin.
Later:

  tape_buffered_read ((char *) file_hdr, in_des, 6L);
  while (1)
    {
      if (append_flag)
        last_header_start = input_bytes - io_block_size
          + (in_buff - input_buffer) - 6;
      if (archive_format == arf_newascii
          && !strncmp ((char *) file_hdr, "070701", 6))
        {
          if (bytes_skipped > 0)
            error (0, 0, "warning: skipped %ld bytes of junk", bytes_skipped);
          read_in_new_ascii (file_hdr, in_des);
          break;
        }

Suprisingly for me, this part is read again (?) type of archive is checked and 
previously checked variable. This might be protection for race conditions, 
but please explain to be why we are reading junk and checking for header in 
it ?

- -- 
Grzegorz Jaskiewicz
K4 Labs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE++HiAqu082fCQYIgRAhLuAJ9OHeqh43l96l09M0mfxP2RcdAObwCfaZok
YVhCFahgBZTiKV6Zh/UKbFc=
=XfNc
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]