[tz] compiling tzcode with mingw gcc compiler

Theo Veenker theo.veenker at beexy.nl
Wed Sep 25 10:08:00 UTC 2013


Dear maintainers of the tzcode,

I noticed I could't build the tzcode from Mingw gcc. Therefore I'd like to
suggest some additions/changes. They are fairly trivial, see below.

Theo Veenker


Main change required is the addition of a (conditional) link() function into
zic.c as this function is not provided on a Windows platform.


private.h:

Add:
#ifndef HAVE_LINK
#define HAVE_LINK		1
#endif /* !defined HAVE_LINK */


zic.c:

Add:
#if !HAVE_LINK
#define SCRATCH_SIZE 8000

int
link(const char * fromname, const char * toname)
{
	FILE * fi;
	FILE * fo;
	char * scratch;
	int err = 0;

	fi = fopen(fromname, "rb");
	if (!fi) return -1;

	fo = fopen(toname, "wb");
	if (!fo) {
		fclose(fi);
		return -1;
	}

	scratch = (char*)emalloc(SCRATCH_SIZE);
	while (!feof(fi)) {
		int nread = fread(scratch, 1, SCRATCH_SIZE, fi);
		if (nread > 0) {
			int nwritten = fwrite(scratch, 1, nread, fo);
			if (nwritten != nread) {
				err = -1;
				break;
			}
		}
		else if (feof(fi)) {
			break;
		}
		else if (ferror(fi)) {
			err = -1;
			break;
		}
	}
	free(scratch);
	fclose(fo);
	fclose(fi);

	return err;
}
#endif /* !HAVE_LINK */


Makefile:

Linking zdump requires asctime.c and asctime.o to be added to symbols
TZDSRCS resp. TZDOBJS:
TZDSRCS=	zdump.c localtime.c asctime.c ialloc.c
TZDOBJS=	zdump.o localtime.o asctime.o ialloc.o

Also add comment:
#  -DHAVE_LINK=0 if your system lacks the link function


To test compilation using i686-w64-mingw32-gcc under Linux:
make CFLAGS="-DHAVE_STDINT_H -DSTD_INSPIRED -DHAVE_SYS_WAIT_H=0 -DHAVE_SYS_STAT_H=0 
-DHAVE_UNISTD_H=0 -DHAVE_SYMLINK=0 -DHAVE_LINK=0" cc=i686-w64-mingw32-gcc

To test compilation using Mingw gcc under Windows:
make CFLAGS="-DHAVE_STDINT_H -DSTD_INSPIRED -DHAVE_SYS_WAIT_H=0 -DHAVE_SYS_STAT_H=0 
-DHAVE_UNISTD_H=0 -DHAVE_SYMLINK=0 -DHAVE_LINK=0" cc=gcc

-- 
Theo Veenker  |  Beexy - Behavioral Experiment Software
+31(0)524-541531  |  +31(0)6-42525777 mobile
theo.veenker at beexy.nl  |  www.beexy.nl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tzcode-2013e.patch
Type: text/x-patch
Size: 2744 bytes
Desc: not available
URL: <http://mm.icann.org/pipermail/tz/attachments/20130925/53918cb7/attachment.bin>


More information about the tz mailing list