|
|
1.1 ! root 1: /************************** MODULE HEADER ********************************** ! 2: * hndcopy.c ! 3: * Module to allow copying of file data using handles. ! 4: * ! 5: * ! 6: * Copyright (C) 1992 Microsoft Corporation ! 7: * ! 8: ***************************************************************************/ ! 9: ! 10: #include <windows.h> ! 11: ! 12: ! 13: /************************** Function Header ******************************** ! 14: * lFICopy ! 15: * Copy the file contents of the input handle to that of the output ! 16: * handle. ! 17: * ! 18: * RETURNS: ! 19: * Number of bytes copied, -1 on error, 0 is legitimate. ! 20: * ! 21: * HISTORY: ! 22: * 18:06 on Mon 24 Feb 1992 -by- Lindsay Harris [lindsayh] ! 23: * Start ! 24: * ! 25: ***************************************************************************/ ! 26: ! 27: ! 28: long ! 29: lFICopy( hOut, hIn ) ! 30: HANDLE hOut; /* Output file: write to current position */ ! 31: HANDLE hIn; /* Input file: copy from current position to EOF */ ! 32: { ! 33: ! 34: /* ! 35: * Simple read/write operations until EOF is reached on the input. ! 36: * May also be errors, so handle these too. As we are dealing with ! 37: * relatively small files (a few 10s of k), we use a stack buffer. ! 38: */ ! 39: ! 40: #define CPBSZ 2048 ! 41: ! 42: DWORD dwSize; ! 43: DWORD dwGot; ! 44: DWORD dwTot; /* Accumulate number of bytes copied */ ! 45: ! 46: BYTE ajBuf[ CPBSZ ]; ! 47: ! 48: dwTot = 0; ! 49: ! 50: while( ReadFile( hIn, &ajBuf, CPBSZ, &dwGot, NULL ) ) ! 51: { ! 52: /* A read of zero means we have reached EOF */ ! 53: ! 54: if( dwGot == 0 ) ! 55: return dwTot; /* However much so far */ ! 56: ! 57: if( !WriteFile( hOut, &ajBuf, dwGot, &dwSize, NULL ) || ! 58: dwSize != dwGot ) ! 59: { ! 60: /* Assume some serious problem */ ! 61: ! 62: return -1; ! 63: } ! 64: ! 65: dwTot += dwSize; ! 66: } ! 67: ! 68: /* ! 69: * We only come here for an error, so return the bad news. ! 70: */ ! 71: ! 72: return -1; ! 73: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.