Hi,
I'd like to copy one directory to another, including subdirectories. Each file that is copied over needs to have its own thread and each following thread must wait for the previous one to finish and exit before being created.
The directory names are passed in *arg separated by a null char.
This is what I have so far...
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>
void *copydirectory(void *arg);
void *copyfilepass(void *arg);
// Copy Directory function:
void *copydirectory (void *arg)
{
int error;
int fd;
pthread_t tid;
/* Version 1:
* Directory names passed in arg, seperated by null char
* Assume both directories exist
* Each file copied, create a thread to run copyfilepass
*/
// Assuming Directories exist!
// Create thread to copy:
if (error = pthread_create(&tid, NULL, copyfilepass, &fd))
{
fprintf(stderr, "Failed to create thread: %s\n", strerror(error));
}
else
{
fprintf("Thread created\n");
}
}
copyfilepass will receive the directory name in arg, the code for copyfilepass is:
#include <unistd.h>
#include "restart.h"
void *copyfilepass(void *arg)
{
int *argint;
argint = (int *)arg;
argint[2] = copyfile(argint[0], argint[1]);
r_close(argint[0]);
r_close(argint[1]);
return argint + 2;
}
I think where I'm getting confused is the using of file descriptors. I want to copy from Directory One to Directory Two, but it looks like it's becoming an integer?
If anyone could explain this to me or point me in the right direction it would be muchly appreciated.'
Thanks