Re: Implementing a 64 bits file access, improved 2.
"Igor V. Melichev" <[email protected]> Mon, 4 Sep 2006 18:05:17 +0400
| Newsgroups | gmane.comp.printing.ghostscript.patches |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
------=_NextPart_000_0084_01C6D04C.ADB94550
Content-Type: text/plain; format=flowed; charset="koi8-r"; reply-type=original
Content-Transfer-Encoding: 7bit
[Log message beg]
Implementing a 64 bits file access.
DETAILS :
This is a preliminary implementation.
Now it compiles for MSVC8, Linux/gcc .
For other platforms/compilers it is stubbed with 32 bits file access.
We could not figure out why Cygwin/gcc defines fopen64, ftello64, fseeko64,
and then cannot link them. Maybe something is wrong with linker options ?
EXPECTED DIFFERENCES :
None.
[Log message end]
See attachment.
------=_NextPart_000_0084_01C6D04C.ADB94550
Content-Type: text/plain; format=flowed; name="patch.txt"; reply-type=original
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="patch.txt"
=20
=20
=20
=20
*** F:\SVN-GS\HEAD\gs\src\gp.h Wed Mar 22 10:37:51 2006=0A=
--- files\gs\src\gp.h Thu Aug 31 15:38:31 2006=0A=
***************=0A=
*** 37,40 ****=0A=
--- 37,45 ----=0A=
#include "srdline.h"
=20
+ /*
+ * int64_t is used in the 64 bits file access.
+ */
+ #include "stdint_.h"
+=20
/* ------ Initialization/termination ------ */
=20
***************=0A=
*** 405,407 ****=0A=
--- 410,459 ----=0A=
void gp_enumerate_fonts_free(void *enum_state);
=20
+ /* --------- 64 bit file access ----------- */
+=20
+ /* The following functions are analogues of ones with
+ same name without the "_64" suffix.=20
+ They perform same function with allowing big files
+ (over 4 gygabytes length).
+=20
+ If the platform does not allow big files,
+ these functions are mapped to regular file i/o functions.
+ On 64 bits platforms they work same as
+ regular file i/o functions.
+=20
+ We continue using the old file i/o functions
+ because most files do not need 64 bits access.
+ The upgrading of old code to the new 64 bits access
+ to be done step by step on real necessity,
+ with replacing old function names with=20
+ new function names through code,
+ together with providing the int64_t type for storing=20
+ file offsets in intermediate structures and variables.
+=20
+ We assume that the result of 64 bits variant of 'ftell'
+ can be represented in int64_t on all platforms,
+ rather the result type of the native 64 bits function is
+ compiler dependent (__off_t on Linux, _off_t on Cygwin,=20
+ __int64 on Windows).
+ */
+=20
+ FILE *gp_fopen_64(const char *filename, const char *mode);
+=20
+ FILE *gp_open_scratch_file_64(const char *prefix,
+ char fname[gp_file_name_sizeof],
+ const char *mode);
+ FILE *gp_open_printer_64(char fname[gp_file_name_sizeof], int =
binary_mode);
+=20
+ int64_t gp_ftell_64(FILE *stream);
+=20
+ int gp_fseek_64(FILE *stream, int64_t offset, int origin);
+=20
+ /* We don't define gp_fread_64, gp_fwrite_64,
+ because (1) known platforms allow regular fread, fwrite
+ to be applied to a file opened with O_LARGEFILE,=20
+ fopen64, etc.; (2) Ghostscript code does not
+ perform writing/reading a long (over 4gb) block
+ in one operation.
+ */
+=20
#endif /* gp_INCLUDED */
=20
=20
=20
*** F:\SVN-GS\HEAD\gs\src\gpmisc.c Wed Aug 23 14:21:32 2006=0A=
--- files\gs\src\gpmisc.c Fri Sep 1 12:24:59 2006=0A=
***************=0A=
*** 46,51 ****=0A=
* conditions and symlink attacks.
*/
! FILE *
! gp_fopentemp(const char *fname, const char *mode)
{
int flags =3D O_EXCL;
--- 46,51 ----=0A=
* conditions and symlink attacks.
*/
! private FILE *
! gp_fopentemp_generic(const char *fname, const char *mode, bool b64)
{
int flags =3D O_EXCL;
***************=0A=
*** 55,58 ****=0A=
--- 55,66 ----=0A=
FILE *file;
=20
+ #if defined (O_LARGEFILE)
+ /* It works for Linux/gcc. */
+ if (b64)
+ flags |=3D O_LARGEFILE;
+ #else
+ /* fixme : Not sure what to do. Unimplemented. */
+ /* MSVC has no O_LARGEFILE, but MSVC build never calls this =
function. */
+ #endif
while (*p)
switch (*p++) {
***************=0A=
*** 86,90 ****=0A=
--- 94,102 ----=0A=
* which defines it as (const char *). Patch this here.
*/
+ #if defined (O_LARGEFILE)
+ file =3D (b64 ? fdopen64 : fdopen)(fildes, (char *)mode); /* still =
really const */
+ #else
file =3D fdopen(fildes, (char *)mode); /* still really const */
+ #endif
if (file =3D=3D 0)
close(fildes);
***************=0A=
*** 92,95 ****=0A=
--- 104,117 ----=0A=
}
=20
+ FILE *gp_fopentemp_64(const char *fname, const char *mode)
+ {
+ return gp_fopentemp_generic(fname, mode, true);
+ }
+=20
+ FILE *gp_fopentemp(const char *fname, const char *mode)
+ {
+ return gp_fopentemp_generic(fname, mode, false);
+ }
+=20
/* Append a string to buffer. */
private inline bool
=20
=20
=20
*** F:\SVN-GS\HEAD\gs\src\gpmisc.h Wed Mar 15 15:05:05 2006=0A=
--- files\gs\src\gpmisc.h Thu Aug 31 21:25:23 2006=0A=
***************=0A=
*** 35,38 ****=0A=
--- 35,39 ----=0A=
*/
FILE *gp_fopentemp(const char *fname, const char *mode);
+ FILE *gp_fopentemp_64(const char *fname, const char *mode);
=20
/*
=20
=20
=20
*** F:\SVN-GS\HEAD\gs\src\gp_iwatc.c Wed Mar 15 15:04:29 2006=0A=
--- files\gs\src\gp_iwatc.c Thu Aug 31 21:06:27 2006=0A=
***************=0A=
*** 195,196 ****=0A=
--- 195,232 ----=0A=
{
} =20
+=20
+ /* --------- 64 bit file access ----------- */
+ /* fixme: Not implemented yet.
+ * Currently we stub it with 32 bits access.=20
+ */
+=20
+ FILE *gp_fopen_64(const char *filename, const char *mode)
+ {
+ return fopen(filename, mode);
+ }
+=20
+ FILE *gp_open_scratch_file_64(const char *prefix,
+ char fname[gp_file_name_sizeof],
+ const char *mode)
+ {
+ return gp_open_scratch_file(prefix, fname, mode);
+ }
+=20
+ FILE *gp_open_printer_64(char fname[gp_file_name_sizeof], int =
binary_mode)
+ {
+ return gp_open_printer(fname, binary_mode);
+ }
+=20
+ int64_t gp_ftell_64(FILE *stream)
+ {
+ return ftell(stream);
+ }
+=20
+ int gp_fseek_64(FILE *stream, int64_t offset, int origin)
+ {
+ long offset1 =3D (long)offset;
+ =20
+ if (offset !=3D offset1)
+ return -1;
+ return fseek(stream, offset1, origin);
+ }
=20
=20
=20
*** F:\SVN-GS\HEAD\gs\src\gp_macio.c Wed Mar 15 15:04:37 2006=0A=
--- files\gs\src\gp_macio.c Thu Aug 31 21:06:41 2006=0A=
***************=0A=
*** 1015,1016 ****=0A=
--- 1015,1051 ----=0A=
}
=
=20
+ /* --------- 64 bit file access ----------- */
+ /* fixme: Not implemented yet.
+ * Currently we stub it with 32 bits access.=20
+ */
+=20
+ FILE *gp_fopen_64(const char *filename, const char *mode)
+ {
+ return fopen(filename, mode);
+ }
+=20
+ FILE *gp_open_scratch_file_64(const char *prefix,
+ char fname[gp_file_name_sizeof],
+ const char *mode)
+ {
+ return gp_open_scratch_file(prefix, fname, mode);
+ }
+=20
+ FILE *gp_open_printer_64(char fname[gp_file_name_sizeof], int =
binary_mode)
+ {
+ return gp_open_printer(fname, binary_mode);
+ }
+=20
+ int64_t gp_ftell_64(FILE *stream)
+ {
+ return ftell(stream);
+ }
+=20
+ int gp_fseek_64(FILE *stream, int64_t offset, int origin)
+ {
+ long offset1 =3D (long)offset;
+ =20
+ if (offset !=3D offset1)
+ return -1;
+ return fseek(stream, offset1, origin);
+ }
=20
=20
=20
*** F:\SVN-GS\HEAD\gs\src\gp_mswin.c Wed Mar 15 15:04:47 2006=0A=
--- files\gs\src\gp_mswin.c Fri Sep 1 12:27:11 2006=0A=
***************=0A=
*** 799,800 ****=0A=
--- 799,853 ----=0A=
{
} =20
+=20
+ /* --------- 64 bit file access ----------- */
+ /* MSVC versions before 8 doen't provide big files.
+ MSVC 8 doesn't distinguish big and small files,
+ but provide special positioning functions
+ to access data behind 4GB.
+ Currently we support 64 bits file access with MSVC only.
+ */
+=20
+ FILE *gp_fopen_64(const char *filename, const char *mode)
+ {
+ return fopen(filename, mode);
+ }
+=20
+ FILE *gp_open_scratch_file_64(const char *prefix,
+ char fname[gp_file_name_sizeof],
+ const char *mode)
+ {
+ return gp_open_scratch_file(prefix, fname, mode);
+ }
+=20
+ FILE *gp_open_printer_64(char fname[gp_file_name_sizeof], int =
binary_mode)
+ {
+ /* Assuming gp_open_scratch_file_64 is same as =
gp_open_scratch_file -
+ see the body of gp_open_printer. */
+ return gp_open_printer(fname, binary_mode);
+ }
+=20
+ int64_t gp_ftell_64(FILE *stream)
+ {
+ #if !defined(_MSC_VER)
+ return ftell(steram);
+ #elif _MSC_VER < 1400
+ return ftell(steram);
+ #else
+ return _ftelli64(stream);
+ #endif
+ }
+=20
+ int gp_fseek_64(FILE *stream, int64_t offset, int origin)
+ {
+ #if !defined(_MSC_VER)
+ return fseek(steram, offset, origin);
+ #elif _MSC_VER < 1400
+ long offset1 =3D (long)offset;
+ =20
+ if (offset !=3D offset1)
+ return -1;
+ return fseek(stream, offset1, origin);
+ #else
+ return _fseeki64(stream, offset, origin);
+ #endif
+ }
=20
=20
=20
*** F:\SVN-GS\HEAD\gs\src\gp_os2.c Wed Mar 15 15:04:20 2006=0A=
--- files\gs\src\gp_os2.c Thu Aug 31 21:06:54 2006=0A=
***************=0A=
*** 859,860 ****=0A=
--- 859,896 ----=0A=
{
} =20
+=20
+ /* --------- 64 bit file access ----------- */
+ /* fixme: Not implemented yet.
+ * Currently we stub it with 32 bits access.=20
+ */
+=20
+ FILE *gp_fopen_64(const char *filename, const char *mode)
+ {
+ return fopen(filename, mode);
+ }
+=20
+ FILE *gp_open_scratch_file_64(const char *prefix,
+ char fname[gp_file_name_sizeof],
+ const char *mode)
+ {
+ return gp_open_scratch_file(prefix, fname, mode);
+ }
+=20
+ FILE *gp_open_printer_64(char fname[gp_file_name_sizeof], int =
binary_mode)
+ {
+ return gp_open_printer(fname, binary_mode);
+ }
+=20
+ int64_t gp_ftell_64(FILE *stream)
+ {
+ return ftell(stream);
+ }
+=20
+ int gp_fseek_64(FILE *stream, int64_t offset, int origin)
+ {
+ long offset1 =3D (long)offset;
+ =20
+ if (offset !=3D offset1)
+ return -1;
+ return fseek(stream, offset1, origin);
+ }
=20
=20
=20
*** F:\SVN-GS\HEAD\gs\src\gp_unifs.c Wed Mar 15 15:04:15 2006=0A=
--- files\gs\src\gp_unifs.c Mon Sep 4 18:00:14 2006=0A=
***************=0A=
*** 15,21 ****=0A=
/* "Unix-like" file system platform routines for Ghostscript */
=20
#include "memory_.h"
#include "string_.h"
- #include "stdio_.h" /* for FILENAME_MAX */
#include "gx.h"
#include "gp.h"
--- 15,21 ----=0A=
/* "Unix-like" file system platform routines for Ghostscript */
=20
+ #include "stdio_.h" /* for FILENAME_MAX */
#include "memory_.h"
#include "string_.h"
#include "gx.h"
#include "gp.h"
***************=0A=
*** 58,64 ****=0A=
/* Create and open a scratch file with a given name prefix. */
/* Write the actual file name at fname. */
! FILE *
! gp_open_scratch_file(const char *prefix, char =
fname[gp_file_name_sizeof],
! const char *mode)
{ /* The -8 is for XXXXXX plus a possible final / and -. */
int prefix_length =3D strlen(prefix);
--- 58,64 ----=0A=
/* Create and open a scratch file with a given name prefix. */
/* Write the actual file name at fname. */
! private FILE *
! gp_open_scratch_file_generic(const char *prefix, char =
fname[gp_file_name_sizeof],
! const char *mode, bool b64)
{ /* The -8 is for XXXXXX plus a possible final / and -. */
int prefix_length =3D strlen(prefix);
***************=0A=
*** 90,94 ****=0A=
--- 90,101 ----=0A=
memcpy(ofname, fname, gp_file_name_sizeof);
=20
+ #ifndef _LARGEFILE64_SOURCE
+ if (b64)
+ file =3D mkstemp64(fname);
+ else
+ #endif
file =3D mkstemp(fname);
+=20
+ /* Fixme : what top do with b64 ? Unimplemented. */
if (file < -1) {
eprintf1("**** Could not open temporary file %s\n", ofname);
***************=0A=
*** 101,105 ****=0A=
#else
mktemp(fname);
! fp =3D gp_fopentemp(fname, mode);
#endif
if (fp =3D=3D NULL)
--- 108,112 ----=0A=
#else
mktemp(fname);
! fp =3D (b64 ? gp_fopentemp : gp_fopentemp_64)(fname, mode);
#endif
if (fp =3D=3D NULL)
***************=0A=
*** 107,110 ****=0A=
--- 114,123 ----=0A=
return fp;
}
+ FILE *
+ gp_open_scratch_file(const char *prefix, char =
fname[gp_file_name_sizeof],
+ const char *mode)
+ {
+ return gp_open_scratch_file_generic(prefix, fname, mode, false);
+ }
=20
/* Open a file with the given name, as a stream of uninterpreted =
bytes. */
***************=0A=
*** 463,464 ****=0A=
--- 476,519 ----=0A=
(/t*?/?*.ps) {=3D=3D} 100 string filenameforall
*/
+=20
+ /* --------- 64 bit file access ----------- */
+=20
+ FILE *gp_fopen_64(const char *filename, const char *mode)
+ {
+ #ifdef _LARGEFILE64_SOURCE
+ return fopen(filename, mode);
+ #else
+ return fopen64(filename, mode);
+ #endif
+ }
+=20
+ FILE *gp_open_scratch_file_64(const char *prefix,
+ char fname[gp_file_name_sizeof],
+ const char *mode)
+ {
+ return gp_open_scratch_file_generic(prefix, fname, mode, true);
+ }
+=20
+ /* gp_open_printer_64 is defined in gp_unix.h */
+=20
+ int64_t gp_ftell_64(FILE *stream)
+ {
+ #ifdef _LARGEFILE64_SOURCE
+ return ftello(stream);
+ #else
+ return ftello64(stream);
+ #endif
+ }
+=20
+ int gp_fseek_64(FILE *stream, int64_t offset, int origin)
+ {
+ #ifdef _LARGEFILE64_SOURCE
+ long offset1 =3D (long)offset;
+ =20
+ if (offset !=3D offset1)
+ return -1;
+ return fseeko(stream, offset1, origin);
+ #else
+ return fseeko64(stream, offset, origin);
+ #endif
+ }
=20
=20
=20
*** F:\SVN-GS\HEAD\gs\src\gp_unix.c Wed Mar 15 15:05:02 2006=0A=
--- files\gs\src\gp_unix.c Thu Aug 31 21:34:44 2006=0A=
***************=0A=
*** 155,158 ****=0A=
--- 155,165 ----=0A=
return (strlen(fname) =3D=3D 0 ? 0 : fopen(fname, fmode));
}
+ FILE *
+ gp_open_printer_64(char fname[gp_file_name_sizeof], int binary_mode)
+ {
+ const char *fmode =3D (binary_mode ? "wb" : "w");
+=20
+ return (strlen(fname) =3D=3D 0 ? 0 : gp_fopen_64(fname, fmode));
+ }
=20
/* Close the connection to the printer. */
=20
=20
=20
*** F:\SVN-GS\HEAD\gs\src\gp_vms.c Thu Jun 1 10:37:39 2006=0A=
--- files\gs\src\gp_vms.c Thu Aug 31 21:07:42 2006=0A=
***************=0A=
*** 652,653 ****=0A=
--- 652,688 ----=0A=
}
=20
+ /* --------- 64 bit file access ----------- */
+ /* fixme: Not implemented yet.
+ * Currently we stub it with 32 bits access.=20
+ */
+=20
+ FILE *gp_fopen_64(const char *filename, const char *mode)
+ {
+ return fopen(filename, mode);
+ }
+=20
+ FILE *gp_open_scratch_file_64(const char *prefix,
+ char fname[gp_file_name_sizeof],
+ const char *mode)
+ {
+ return gp_open_scratch_file(prefix, fname, mode);
+ }
+=20
+ FILE *gp_open_printer_64(char fname[gp_file_name_sizeof], int =
binary_mode)
+ {
+ return gp_open_printer(fname, binary_mode);
+ }
+=20
+ int64_t gp_ftell_64(FILE *stream)
+ {
+ return ftell(stream);
+ }
+=20
+ int gp_fseek_64(FILE *stream, int64_t offset, int origin)
+ {
+ long offset1 =3D (long)offset;
+ =20
+ if (offset !=3D offset1)
+ return -1;
+ return fseek(stream, offset1, origin);
+ }
=20
=20
=20
*** F:\SVN-GS\HEAD\gs\src\lib.mak Mon Sep 4 16:50:38 2006=0A=
--- files\gs\src\lib.mak Thu Aug 31 15:40:10 2006=0A=
***************=0A=
*** 11,15 ****=0A=
# San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further =
information.
#
! # $Id: lib.mak 7021 2006-09-04 12:50:36Z leonardo $
# (Platform-independent) makefile for Ghostscript graphics library
# and other support code.
--- 11,15 ----=0A=
# San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further =
information.
#
! # $Id: lib.mak 7011 2006-08-30 00:24:55Z giles $
# (Platform-independent) makefile for Ghostscript graphics library
# and other support code.
***************=0A=
*** 50,53 ****=0A=
--- 50,54 ----=0A=
stdpre_h=3D$(GLSRC)stdpre.h $(stdpn_h)
std_h=3D$(GLSRC)std.h $(arch_h) $(stdpre_h)
+ stdint__h=3D$(GLSRC)stdint_.h $(std_h)
=20
$(GLGEN)arch.h : $(GENARCH_XE)
***************=0A=
*** 61,65 ****=0A=
gpgetenv_h=3D$(GLSRC)gpgetenv.h
gpmisc_h=3D$(GLSRC)gpmisc.h
! gp_h=3D$(GLSRC)gp.h $(gpgetenv_h) $(gstypes_h) $(srdline_h)
gpcheck_h=3D$(GLSRC)gpcheck.h
gpsync_h=3D$(GLSRC)gpsync.h
--- 62,66 ----=0A=
gpgetenv_h=3D$(GLSRC)gpgetenv.h
gpmisc_h=3D$(GLSRC)gpmisc.h
! gp_h=3D$(GLSRC)gp.h $(gpgetenv_h) $(gstypes_h) $(srdline_h) =
$(stdint__h)
gpcheck_h=3D$(GLSRC)gpcheck.h
gpsync_h=3D$(GLSRC)gpsync.h
***************=0A=
*** 91,95 ****=0A=
setjmp__h=3D$(GLSRC)setjmp_.h
stat__h=3D$(GLSRC)stat_.h $(std_h)
- stdint__h=3D$(GLSRC)stdint_.h $(std_h)
stdio__h=3D$(GLSRC)stdio_.h $(std_h)
string__h=3D$(GLSRC)string_.h $(std_h)
--- 92,95 ----=0A=
***************=0A=
*** 694,698 ****=0A=
$(GLOBJ)gxpdash.$(OBJ) : $(GLSRC)gxpdash.c $(GX) $(math__h)\
$(gscoord_h) $(gsline_h) $(gsmatrix_h)\
! $(gxfixed_h) $(gxarith_h) $(gzline_h) $(gzpath_h)
$(GLCC) $(GLO_)gxpdash.$(OBJ) $(C_) $(GLSRC)gxpdash.c
=20
--- 694,698 ----=0A=
$(GLOBJ)gxpdash.$(OBJ) : $(GLSRC)gxpdash.c $(GX) $(math__h)\
$(gscoord_h) $(gsline_h) $(gsmatrix_h)\
! $(gxfixed_h) $(gzline_h) $(gzpath_h)
$(GLCC) $(GLO_)gxpdash.$(OBJ) $(C_) $(GLSRC)gxpdash.c
=20
=20
=20
=20
=20
=20
=20
=20
------=_NextPart_000_0084_01C6D04C.ADB94550
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
gs-code-review mailing list
[email protected]
http://www.ghostscript.com/mailman/listinfo/gs-code-review
------=_NextPart_000_0084_01C6D04C.ADB94550--