Annotation of ntddk/src/print/lib/hndncopy.c, revision 1.1.1.1

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:  * lFInCopy
                     15:  *      Copy the file contents of the input handle to that of the output
                     16:  *      handle.  Copy is limited to the number of bytes passed in.
                     17:  *
                     18:  * RETURNS:
                     19:  *      Number of bytes copied,  -1 on error, 0 is legitimate.
                     20:  *
                     21:  * HISTORY:
                     22:  *  13:20 on Tue 25 Feb 1992    -by-    Lindsay Harris   [lindsayh]
                     23:  *      Based on lFICopy
                     24:  *
                     25:  ***************************************************************************/
                     26: 
                     27: 
                     28: long
                     29: lFInCopy( hOut, hIn, lCount )
                     30: HANDLE   hOut;          /* Output file:  write to current position */
                     31: HANDLE   hIn;           /* Input file: copy from current position to EOF */
                     32: long     lCount;        /* Number of bytes to copy */
                     33: {
                     34: 
                     35:     /*
                     36:      *   Simple read/write operations until EOF is reached on the input.
                     37:      * May also be errors,  so handle these too.  As we are dealing with
                     38:      * relatively small files (a few 10s of k), we use a stack buffer.
                     39:      */
                     40: 
                     41: #define CPBSZ   2048
                     42: 
                     43:     DWORD  dwSize;
                     44:     DWORD  dwGot;
                     45:     DWORD  dwTot;               /* Accumulate number of bytes copied */
                     46:     DWORD  dwLeft;              /* Number of bytes remaining */
                     47: 
                     48:     BYTE   ajBuf[ CPBSZ ];
                     49: 
                     50:     if( lCount < 0 )
                     51:         return  0;              /* Can't copy the other direction! */
                     52: 
                     53: 
                     54:     dwTot = 0;
                     55:     dwLeft = lCount;
                     56: 
                     57:     while( dwLeft > 0 )
                     58:     {
                     59:         dwSize = dwLeft > CPBSZ ? CPBSZ : dwLeft;
                     60: 
                     61:         if( !ReadFile( hIn, &ajBuf, dwSize, &dwGot, NULL ) )
                     62:             return  -1;                 /* Bad news on error */
                     63: 
                     64:         /*  A read of zero means we have reached EOF  */
                     65: 
                     66:         if( dwGot == 0 )
                     67:             return  dwTot;              /* However much so far */
                     68: 
                     69:         dwLeft -= dwGot;                /* Adjuest the remainder */
                     70: 
                     71:         if( !WriteFile( hOut, &ajBuf, dwGot, &dwSize, NULL ) ||
                     72:             dwSize != dwGot )
                     73:         {
                     74:             /*  Assume some serious problem */
                     75: 
                     76:             return  -1;
                     77:         }
                     78: 
                     79:         dwTot += dwSize;
                     80:     }
                     81: 
                     82:     /*
                     83:      *   We only come here after reading the desired amount.
                     84:      */
                     85: 
                     86:     return  dwTot;
                     87: }

unix.superglobalmegacorp.com

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