This repository has been archived on 2026-07-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
cmc/3sem/seminars/l3/01.c
T
2025-04-13 21:48:15 +03:00

41 lines
683 B
C
Executable File

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
int
main(int argc, char *argv[])
{
char *fin = argv[1];
char *fout = argv[2];
// printf("fdin: %d\n", fin);
int fdin = open(fin, O_RDONLY);
if (fdin == -1) {
return 1;
}
int fdout = open(fout, O_WRONLY | O_CREAT | O_TRUNC, 0777);
for (;;) {
char c[1024];
int r = read(fdin, c, 1024);
if (r == -1) {
return 1;
}
if (r == 0) {
break;
}
write(fdout, c, r);
}
close(fdin);
close(fdout);
return 0;
}