<分区>
我正在尝试制作一个复制程序。它类似于 linux 中的 cp 函数。我可以使用 ./copy file1 file2 成功复制文件,但不知何故源中的前提不会复制到目标。有谁知道如何做到这一点?示例和代码如下所示:)
我的文件及其原始权限。
成功复制文件但未复制权限。
#define buff_s 4096
#define mod 0644
void printError(char *, char *);
main(int ac, char *txts[])
{
int input, output, n_chars;
char buf[buff_s];
struct stat file1;
struct stat file2;
stat(txts[1], &file1);
stat(txts[2], &file2);
if ( (input=open(txts[1], O_RDONLY)) == -1 )
printError("error", av[1]);
if ( (output=creat( txts[2], mod)) == -1 )
printError( "error", txts[2]);