1. Check a tar file

Here is a small function to check if a file is a tar archive

include get.e 
 
function isTar(sequence filename) 
  sequence signature 
  integer f_in, c, n 
 
  puts(1, "Filename: "&filename&"\n") 
  f_in = open(filename, "rb") 
  if f_in = -1 then return 0 end if 
  puts(1, "File found\n") 
  n = 0 
  signature = "" 
  while n < 261 do 
    c = getc(f_in) 
    if c = -1 then exit end if 
    n += 1 
    if n > 256 then 
      signature &= c 
      puts(1, "Signature: "&signature&"\n") 
    end if 
    if n = 261 then 
      if equal(signature, "ustar") then 
        close(f_in) 
        return 1 
      end if 
    end if 
  end while 
  close(f_in) 
  return 0 
end function 

Jean-Marc

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu