Dear guyz,

I am creating a file archiver/extractor(like tar), using POSIX API system calls in C. I have done part of the archiving bit.

I would like to know if any one could help me with some C source code(using above) to create a file header for a file in C(where header acts as an index not a header file), which describes the files attributes/meta data(name,date time,etc).All I have done so far is understand(not sure if thats even correct) that to create a header file it needs
a struct to hold the meta data, and lseek is needed to seek to beginning/end of file
like:

FileName=file.txt
FileSize=0

FileDir=./blah/blah

FilePerms=000

\n\n

The archiving part of program has this process:

1. Get a list of all the files from the command line.( I can do this part)

2. Create a structure to hold the meta data about each file: name (255 char), size (64-bit int), date and time, and permissions.

3. For each file, get its stats.

4. Store the stats of each file within an array of structures.

5. Open the archive for writing.( I can do this part)

6. Write the header structure.

7. For each file, append its content to the archive file.(at the end/start of each file).

8. Close the archive file.( I can do this part)

I am having difficulty in creating the header file as a whole even though I know what it needs to do, as mentioned in numbered points above the bits I cant do are stated.(2,3,4,6,7).

Any help will be appreciated.
Thanks.

Header files are only there for convenient access to type and function declarations, they don't (rather, shouldn't) contain definitions or any executable code. As such, it's often easier to lump everything in a single *.c file until you have a working draft, then break out the declarations into a header.

sorry may I just edit what I wrote in the post it was very unclear.

Be a part of the DaniWeb community

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