Skip to content
Snippets Groups Projects
Commit 7ac71774 authored by iliya.saroukha's avatar iliya.saroukha
Browse files

finished copy (syscall)

parent dad302a3
No related branches found
No related tags found
No related merge requests found
.gitignore 100644 → 100755
File mode changed from 100644 to 100755
Makefile 100644 → 100755
File mode changed from 100644 to 100755
README.md 100644 → 100755
File mode changed from 100644 to 100755
struct/lib_fs.c 100644 → 100755
......@@ -7,11 +7,35 @@
int copy(char *src, char *dst, unsigned int buf_size)
{
int byte_count = 0;
size_t real_size = 0;
char buff[buf_size];
int fd_src = open(src, O_RDONLY);
if (fd_src < 0)
{
perror(src);
return -1;
}
int fd_dst = open(dst, O_WRONLY | O_CREAT, 0640);
if (fd_dst < 0)
{
perror(dst);
return -1;
}
while ((real_size = read(fd_src, buff, buf_size)))
{
fprintf(stdout, "Real number of bytes copied : %zu\n", real_size);
byte_count += write(fd_dst, buff, real_size);
}
close(fd_src);
close(fd_dst);
return byte_count;
}
int copyf(char *src, char *dst, unsigned int buf_size)
......
File mode changed from 100644 to 100755
test_lib.c 100644 → 100755
......@@ -5,17 +5,50 @@
int main(int argc, char **argv)
{
if (argc < 2)
if (argc < 3)
{
fprintf(stderr, "Not enough arguments were provided\n");
fprintf(stderr, "\tUsage: ./%s <buf_size>\n", basename(argv[0]));
fprintf(stderr, "\tUsage: ./%s <buf_size> <mode (0 => copy; 1 => copyf)>\n", basename(argv[0]));
return EXIT_FAILURE;
}
char *src = "./src.txt";
int ret = 0;
char *src = "./srb.txt";
char *dst = "./dst.txt";
fprintf(stdout, "\ncopyf(char %s, char %s, unsigned int %d)\tNumber of bytes copied: %d\n", src, dst, atoi(argv[1]), copyf(src, dst, atoi(argv[1])));
switch (atoi(argv[2]))
{
case 0:
ret = copy(src, dst, atoi(argv[1]));
if (ret != -1)
{
fprintf(stdout, "\ncopy(char %s, char %s, unsigned int %d)\tNumber of bytes copied: %d\n", src, dst, atoi(argv[1]), ret);
}
else
{
return EXIT_FAILURE;
}
break;
case 1:
ret = copyf(src, dst, atoi(argv[1]));
if (ret != -1)
{
fprintf(stdout, "\ncopyf(char %s, char %s, unsigned int %d)\tNumber of bytes copied: %d\n", src, dst, atoi(argv[1]), ret);
}
else
{
return EXIT_FAILURE;
}
break;
default:
break;
}
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment