BOOL FCopy (char *src, char *dst) { HANDLE srcfh, dstfh; BOOL result; ATTRIBUTE_TYPE Attributes; unsigned filedate, filetime; GET_ATTRIBUTES(src, Attributes); if (Attributes == FILE_ATTRIBUTE_DIRECTORY) { fprintf( stderr, "\nUnable to open source"); return FALSE; } if (_dos_creatnew( src, _A_RDONLY, &srcfh) != 0) if (_dos_open( src, O_RDONLY, &srcfh) != 0) { fprintf( stderr, "\nUnable to open source, error code %d", GetLastError() ); if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh ); return FALSE; } if (_dos_getftime(srcfh, &filedate, &filetime) != 0) { fprintf( stderr, "\nUnable to get time of source"); if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh ); return FALSE; } if (_dos_creatnew( dst, _A_NORMAL, &dstfh) != 0) if (_dos_open( dst, O_RDWR, &dstfh) != 0) { fprintf( stderr, "\nUnable to create destination, error code %d", GetLastError() ); if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh ); if (dstfh != INVALID_HANDLE_VALUE) CloseHandle( dstfh ); return FALSE; } result = fastcopy( srcfh, dstfh ); if(!result) { if (dstfh != INVALID_HANDLE_VALUE) { CloseHandle( dstfh ); dstfh = INVALID_HANDLE_VALUE; } DeleteFile( dst ); if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh ); fprintf( stderr, "\nUnable to copy file"); return FALSE; } if (_dos_setftime(dstfh, filedate, filetime != 0)) { fprintf( stderr, "\nUnable to set time of destination"); if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh ); if (dstfh != INVALID_HANDLE_VALUE) CloseHandle( dstfh ); return FALSE; } if (srcfh != INVALID_HANDLE_VALUE) CloseHandle( srcfh ); if (dstfh != INVALID_HANDLE_VALUE) CloseHandle( dstfh ); return TRUE; } // FCopy
int _RTLENTRY _EXPFUNC creatnew (const char *pathP, int attr) { int handle; if (_dos_creatnew(pathP, attr, &handle) != 0) return (-1); _openfd[handle] = _FMODE & (O_TEXT | O_BINARY); return (handle); }
void main() { int handle1, handle2; if( _dos_creat( "file", _A_NORMAL, &handle1 ) ){ printf( "Unable to create file\n" ); } else { printf( "Create succeeded\n" ); if( _dos_creatnew( "file", _A_NORMAL, &handle2 ) ){ printf( "Unable to create new file\n" ); } _dos_close( handle1 ); } }