Don_k 0 Newbie Poster

Hi, I would like to using POSIX API system calls in C, and via command line arguments know how to go about extracting from an archive file.(in Linux).

I have done the archiving process it archives the files I enter into the command line , and the last but one file mentioned is the archived file.

e.g. ./tar file1 archivedfile

    Contents of file1 = abc.


    now looks like:

    archivedfile(this is a header)


How would I by using the filename (the header in archive file) extract the archive file out.

HERE is my pseudo code of how I want it to work:

if(argv[i]==0){printf("extracting...");} /*//this means if the file entered 
//on command line is archivefile you want to extract.then go onto extract process...
while(buffer[count]!='\n')     //loop to get filename.
{//add characters to array e.g. filestringarray
set pointer using lseek to poin at if fname=file1 then lseek to point to 6 until reach start of next file.

  another loop to get body of file:while(..){}
createopen a file from filename,read filename, read contents.
need to use strtok to find \n token for filename...*/

The above is how I would like my code to work if anyone could help me on any of the parts mentioned above It would be greatly appreciated. For example even the first line argvi==0 I'm not sure that even makes sense so, what I wanted the line to do is if the filename entered by the user is an archive file then continue with the extraction process of the archived file.

Thank you all for any help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.