File:  [WindowsNT SDKs] / ntddk / src / print / lib / hndcopy.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 18:31:12 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: ntddk-nov-1993, HEAD
Microsoft Windows NT Build 511 (DDK SDK) 11-01-1993

/************************** MODULE HEADER **********************************
 * hndcopy.c
 *      Module to allow copying of file data using handles.
 *
 *
 * Copyright (C) 1992  Microsoft Corporation
 *
 ***************************************************************************/

#include        <windows.h>


/************************** Function Header ********************************
 * lFICopy
 *      Copy the file contents of the input handle to that of the output
 *      handle.
 *
 * RETURNS:
 *      Number of bytes copied,  -1 on error, 0 is legitimate.
 *
 * HISTORY:
 *  18:06 on Mon 24 Feb 1992    -by-    Lindsay Harris   [lindsayh]
 *      Start
 *
 ***************************************************************************/


long
lFICopy( hOut, hIn )
HANDLE   hOut;          /* Output file:  write to current position */
HANDLE   hIn;           /* Input file: copy from current position to EOF */
{

    /*
     *   Simple read/write operations until EOF is reached on the input.
     * May also be errors,  so handle these too.  As we are dealing with
     * relatively small files (a few 10s of k), we use a stack buffer.
     */

#define CPBSZ   2048

    DWORD  dwSize;
    DWORD  dwGot;
    DWORD  dwTot;               /* Accumulate number of bytes copied */

    BYTE   ajBuf[ CPBSZ ];

    dwTot = 0;

    while( ReadFile( hIn, &ajBuf, CPBSZ, &dwGot, NULL ) )
    {
        /*  A read of zero means we have reached EOF  */

        if( dwGot == 0 )
            return  dwTot;              /* However much so far */

        if( !WriteFile( hOut, &ajBuf, dwGot, &dwSize, NULL ) ||
            dwSize != dwGot )
        {
            /*  Assume some serious problem */

            return  -1;
        }

        dwTot += dwSize;
    }

    /*
     *   We only come here for an error,  so return the bad news.
     */

    return  -1;
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.