Re: Fix compilation on 64-bit UNIX platforms.
"Leonardo" <[email protected]> Mon, 27 Aug 2007 10:43:07 +0400
| Newsgroups | gmane.comp.printing.ghostscript.patches |
|---|---|
| Message-ID | <[email protected]> |
Fine with me. ----- Original Message ----- From: "Alex Cherepanov" <[email protected]> To: <[email protected]> Sent: Monday, August 27, 2007 7:02 AM Subject: [gs-code-review] Fix compilation on 64-bit UNIX platforms. > Current Ghostscript assumes that all marked stdio FILE calls are > available when fopen64() is available. In fact, availability of > every call varies between different platforms independently. So > we have to check for every call separately. > > BTW, fdopen64() is especially rare and most often mentioned on the > net in connection with Ghostscript build problems. > -------------------------------------------------------------------------------- > Index: gs/src/gp_unifs.c > =================================================================== > --- gs/src/gp_unifs.c (revision 8204) > +++ gs/src/gp_unifs.c (working copy) > @@ -88,19 +88,27 @@ > > /* save the old filename template in case mkstemp fails */ > memcpy(ofname, fname, gp_file_name_sizeof); > -#if defined(HAVE_FILE64) && !defined(_LARGEFILE64_SOURCE) > - if (b64) > - file = mkstemp64(fname); > - else > +#ifdef HAVE_MKSTEMP64 > + file = (b64 ? mkstemp64 : mkstemp)(fname); > +#else > + file = mkstemp(fname); > #endif > - file = mkstemp(fname); > - > - /* Fixme : what to do with b64 and 32-bit mkstemp? Unimplemented. */ > if (file < -1) { > eprintf1("**** Could not open temporary file %s\n", ofname); > return NULL; > } > +#if defined(O_LARGEFILE) && defined(__hpux) > + if (b64) > + fcntl(file, F_SETFD, fcntl(file, F_GETFD) | O_LARGEFILE); > +#else > + /* Fixme : what to do with b64 and 32-bit mkstemp? Unimplemented. */ > +#endif > + > +#ifdef HAVE_FDOPEN64 > + fp = (b64 ? fdopen64 : fdopen)(file, mode); > +#else > fp = fdopen(file, mode); > +#endif > if (fp == NULL) > close(file); > } > Index: gs/src/Makefile.in > =================================================================== > --- gs/src/Makefile.in (revision 8204) > +++ gs/src/Makefile.in (working copy) > @@ -120,8 +120,14 @@ > # > # -DHAVE_FILE64 > # use marked versions of the stdio FILE calls, fopen64() et al. > +# > +# -DHAVE_FDOPEN64 > +# use non-standard function fdopen64() > +# > +# -DHAVE_MKSTEMP64 > +# use non-standard function mkstemp64() > > -CAPOPT= @HAVE_MKSTEMP@ @HAVE_HYPOT@ @HAVE_FILE64@ @HAVE_FONTCONFIG@ > +CAPOPT= @HAVE_MKSTEMP@ @HAVE_HYPOT@ @HAVE_FILE64@ @HAVE_FDOPEN64@ > @HAVE_MKSTEMP64@ @HAVE_FONTCONFIG@ > > # Define the name of the executable file. > > Index: gs/src/configure.ac > =================================================================== > --- gs/src/configure.ac (revision 8204) > +++ gs/src/configure.ac (working copy) > @@ -924,6 +924,12 @@ > AC_CHECK_FUNCS([fopen64], [HAVE_FILE64=-DHAVE_FILE64]) > AC_SUBST(HAVE_FILE64) > > +AC_CHECK_FUNCS([fdopen64], [HAVE_FDOPEN64=-DHAVE_FDOPEN64]) > +AC_SUBST(HAVE_FDOPEN64) > + > +AC_CHECK_FUNCS([mkstemp64], [HAVE_MKSTEMP64=-DHAVE_MKSTEMP64]) > +AC_SUBST(HAVE_MKSTEMP64) > + > AC_PROG_GCC_TRADITIONAL > > dnl NB: We don't actually provide autoconf-switched fallbacks for any > Index: gs/src/gpmisc.c > =================================================================== > --- gs/src/gpmisc.c (revision 8204) > +++ gs/src/gpmisc.c (working copy) > @@ -93,7 +93,7 @@ > * fdopen as (char *), rather than following the POSIX.1 standard, > * which defines it as (const char *). Patch this here. > */ > -#if defined (O_LARGEFILE) > +#if defined (HAVE_FDOPEN64) > file = (b64 ? fdopen64 : fdopen)(fildes, (char *)mode); /* still > really const */ > #else > file = fdopen(fildes, (char *)mode); /* still really const */ >