Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void cp_file (char* source, char* destination)
- {
- int sourceDev, destDev, sourceIno, destIno, n;
- char* ReadBuf[BLKSIZE];
- char * DestcpyBuf[BLKSIZE];
- sourceIno = getino(fd, source);
- if(sourceIno == 0)
- {
- printf("cannot find source file\n");
- return -1;
- }
- //open return fd
- //we only need to READ
- sourceDev = open_file(source,0);
- if(sourceDev == -1)
- {
- printf("cannot open source file\n");
- return -1;
- }
- //save it cause we're gonna change fd when we call getino
- int Origfd = fd;
- destIno = getino(fd, destination);
- //if we dont have the destfile already the create one
- if(destIno == 0)
- {
- printf("creating a file for destination\n");
- strcpy(source, destination);
- creat_file();
- }
- //get fd from open dest
- //creat_file(destination);
- //why can't i write to it??
- destDev = open_file(destination, 1); // 1 bc we're going to write to it
- if(destDev == -1)
- {
- printf("cannot write to destination\nno device number\n");
- return -1;
- }
- //myread returns n read bytes
- //n = myread1(sourceDev,ReadBuf,BLKSIZE);
- while(n = myread1(sourceDev,ReadBuf,BLKSIZE))
- {
- //mywrite1 write n bytes to readbuf
- mywrite1(destDev,ReadBuf,n);
- }
- close_file(sourceDev);
- close_file(destDev);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement