home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************
- *
- * XDEVCAN.C
- * this is called and the file is copied via read and write to
- * the other device, sure it may be slow but it solves a problem
- * of cross device links crossdevcan(OLDFILE, NEWFILE)
- *
- ***********************************************************************/
-
- #include "can.h"
-
- crossdevcan(OLDFILE, NEWFILE)
- char *OLDFILE, *NEWFILE;
- {
- int oldFD, newFD; /* File Descriptors for access */
- char NEXTCHAR[512]; /* used to transfer the char to new place */
- int RWSIZE = 512; /* amount to read and write */
- struct stat BUF; /* used to transfer all stats of old file to new */
- int n_read; /* the number of bytes successfully read */
-
- /* create the new file in the trashcan */
- if((newFD = creat(NEWFILE, 00777)) < 0)
- {
- perror("Cross Device can");
- return;
- }
- /* open the old one to be read */
- if((oldFD = open(OLDFILE, O_RDONLY)) < 0)
- {
- perror("Cross Device can");
- return;
- }
- /* repeatedly read and write until whole file is copied */
- while((n_read = read(oldFD, NEXTCHAR, RWSIZE)) != 0)
- {
- if((write(newFD, NEXTCHAR, n_read)) != n_read)
- {
- perror("Cross Device can");
- return;
- }
- }
- /* close the files */
- close(oldFD);
- close(newFD);
- /* get info concerning the old file */
- stat(OLDFILE, &BUF);
- /* make the new file's modes the same as the old one's */
- if(chmod(NEWFILE, (int)(BUF.st_mode & 0777)) != 0)
- {
- perror("Cross Device can");
- return;
- }
- /* make the new file's times the same as the old one's */
- TIMES.actime= BUF.st_atime;
- TIMES.modtime= BUF.st_mtime;
- if(utime(NEWFILE, &TIMES) != 0)
- {
- perror("Cross Device can");
- return;
- }
- }
-