-2

有人可以指出如何将多个文件附加到 C 中的存档文件的正确方向吗?

下面是我打算做的。你能告诉我这是否是正确的方法(如果不是,你能告诉我哪种方法更好)吗?非常感谢!

- 使用 OPEN 打开归档文件 (O_RDONLY | O_WRONLY | O_APPEND) - 使用 WRITE 将常规文件写入归档

4

2 回答 2

1

You should hopefully have a system header file named ar.h (normally located in /usr/include/), if you check that you will see the format of the archive files.

Each file in the archive is a ar_hdr structure followed by the data of the file contents. So to append a file to the archive, you just write a correct structure followed by the contents of the file you want to append.

于 2013-07-19T18:34:59.173 回答
0

为了将文件(甚至一个文件)添加到存档文件中,您首先需要知道存档的格式。如果您已经研究过您的操作系统提供的文件格式的文档(正如您对上一个问题的回答中所建议的那样),那么您应该已经对文件格式有足够的了解,您不需要问我们如何去做吧。

C 没有名为OPENor的函数WRITE。有open()write()但是,请注意O_RDONLY|O_WRONLY不等同于O_RDWR。您可以使用write()将文件的内容写入存档的末尾,是的,但是(a)不要忘记先写入文件头,并且(b)您确定不需要更新存档的符号表?(如果这样做,您可能需要重写整个文件。)

你为什么不ar再次使用命令行实用程序?

于 2013-07-19T18:51:23.760 回答