CopyLZFile

3.1

  #include <lzexpand.h>    

  LONG CopyLZFile(hfSource, hfDest)    
  HFILE hfSource; /* handle of source file */
  HFILE hfDest; /* handle of destination file */

The CopyLZFile function copies a source file to a destination file. If the source file is compressed, this function creates a decompressed destination file. If the source file is not compressed, this function duplicates the original file.

Parameters

hfSource

Identifies the source file.

hfDest

Identifies the destination file.

Return Value

The return value specifies the size, in bytes, of the destination file if the function is successful. Otherwise, it is an error value less than zero; it may be one of the following:

Value Meaning

LZERROR_BADINHANDLE The handle identifying the source file was not valid.
LZERROR_BADOUTHANDLE The handle identifying the destination file was not valid.
LZERROR_READ The source file format was not valid.
LZERROR_WRITE There is insufficient space for the output file.
LZERROR_GLOBALLOC There is insufficient memory for the required buffers.
LZERROR_UNKNOWNALG The file was compressed with an unrecognized compression algorithm.

Comments

This function is identical to the LZCopy function.

The CopyLZFile function is designed for copying or decompressing multiple files, or both. To allocate required buffers, an application should call the LZStart function prior to calling CopyLZFile. To free these buffers, an application should call the LZDone function after copying the files.

If the function is successful, the file identified by hfDest is decompressed.

If the source or destination file is opened by using a C run-time function (rather than by using the _lopen or OpenFile function), it must be opened in binary mode.

Example

The following example uses the CopyLZFile function to create copies of four text files:

#define STRICT

#include <windows.h>
#include <lzexpand.h>


#define NUM_FILES   4

char *szSrc[NUM_FILES] =
    {"readme.txt", "data.txt", "update.txt", "list.txt"};
char *szDest[NUM_FILES] =
    {"readme.bak", "data.bak", "update.bak", "list.bak"};
OFSTRUCT ofStrSrc;
OFSTRUCT ofStrDest;
HFILE hfSrcFile, hfDstFile;
int i;

/* Allocate internal buffers for the CopyLZFile function. */

LZStart();

/* Open, copy, and then close the files. */

for (i = 0; i < NUM_FILES; i++) {
    hfSrcFile = LZOpenFile(szSrc[i], &ofStrSrc, OF_READ);
    hfDstFile = LZOpenFile(szDest[i], &ofStrDest, OF_CREATE);
    CopyLZFile(hfSrcFile, hfDstFile);
    LZClose(hfSrcFile);
    LZClose(hfDstFile);
}

LZDone(); /* free the internal buffers */

See Also

_lopen, LZCopy, LZDone, LZStart, OpenFile