[Zlib-devel] zlib 1.2.4 released!
John Bowler
jbowler at frontiernet.net
Thu Mar 18 00:56:31 EDT 2010
From: William A. Rowe Jr. [mailto:wrowe at rowe-clan.net]
>Yes, it is a CRT object. The fd is an index to an array of crt structs of which
>HFILE is but one member. Remember 'fd's support several posix modalities which
>aren't part of the Win32 API, so more context is required.
You are correct, the program at the end verifies this and shows (as well, when LIBTEST is 1) that the multiple-CRT environment breaks gzdopen. In both cases the first 'write' within gz_comp in gzwrite.c fails with the msg "Bad file descriptor". In the OS (CreateFile) case the fd value is an OS HANDLE, nominally void* but actually also a small integer (48 or 52 in my test cases), in the LIBTEST case the fd is 3 - apaprently not POSIX compliant (since it is apparently per-CRT).
I generated the LIBTEST break by compiling with Visual Studio 2010 (msvcr100) but linking against your (MSVCRT) zdll.lib and using your zlib1.dll to test.
John Bowler <jbowler at acm.org>
--------------------------------------------------------------------------
#include <windows.h>
#include "zlib.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define LIBTEST 1
static char text[] = "this is some test text";
int main(int argc, const char **args) {
const char *tz = "temporary_file_for_tz.gz";
printf("zlib version: %s\n", zlibVersion());
{
#if LIBTEST
int out = open(tz, O_CREAT | O_WRONLY);
#else /* OS handle test */
int out = (int)CreateFileA(tz, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
#endif
printf("CreateFile(%s, write) -> %d\n", tz, out);
if (out == HFILE_ERROR || out < 0)
fprintf(stderr, "tz: %s: open(out) failed %x\n", tz, GetLastError());
else {
gzFile gout = gzdopen(out, "wb");
int err;
if (gout == 0)
fprintf(stderr, "tz: %s: gzdopen(wb) failed\n", tz);
else if (gzwrite(gout, text, sizeof text) != sizeof text)
fprintf(stderr, "gzwrite(%s) failed\n", tz);
else if ((err = gzclose(gout)) != Z_OK)
fprintf(stderr, "gzclose(%s) failed %d\n", tz, err);
else {
#if LIBTEST
int in = open(tz, O_RDONLY);
#else
int in = (int)CreateFileA(tz, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
#endif
printf("CreateFile(%s, read) -> %d\n", tz, in);
if (in == HFILE_ERROR)
fprintf(stderr, "tz: %s: open(in) failed %x\n", tz, GetLastError());
else {
gzFile gin = gzdopen(in, "rb");
if (gin == 0)
fprintf(stderr, "tz: %s: gzdopen(rb) failed\n", tz);
else {
char buffer[(sizeof text)+1];
int len = gzread(gin, buffer, sizeof buffer);
if (len < 0)
fprintf(stderr, "gzread(%s) failed\n", tz);
else if (len != sizeof text)
fprintf(stderr, "gzread(%s) returned wrong value (%d not %d)\n", tz, len, sizeof text);
else if (strcmp(buffer, text))
fprintf(stderr, "gzread(%s) returned wrong bytes (%s)\n", tz, buffer);
else {
printf("read/write completed\n");
err = gzclose(gin);
if (err != Z_OK)
fprintf(stderr, "gzclose(%s) failed %d\n", tz, err);
else
exit(0);
}
}
}
}
}
}
exit(1);
}
More information about the Zlib-devel
mailing list