summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>2002-12-18 02:08:12 +0000
committerGurusamy Sarathy <gsar@cpan.org>2002-12-18 02:08:12 +0000
commit4a9d61009ab1e3df94ef4ecfcc453c9ce73010a4 (patch)
tree5bb486e54adfa3de89ac2448576a0f0d61f72722 /win32
parent87755fa7011638e8ad4f4be9619e28e676b74d12 (diff)
downloadperl-4a9d61009ab1e3df94ef4ecfcc453c9ce73010a4.tar.gz
windows: support for large files
note that this change will break binary compatibility with the default 5.8.0 build options; nevertheless I think it is worth having in 5.8.1 (people who want the compatibility can disable the option in the makefile) p4raw-id: //depot/perl@18327
Diffstat (limited to 'win32')
-rw-r--r--win32/Makefile13
-rw-r--r--win32/config.bc6
-rw-r--r--win32/config.gc6
-rw-r--r--win32/config.vc6
-rw-r--r--win32/config.vc642
-rw-r--r--win32/config_H.bc8
-rw-r--r--win32/config_H.gc8
-rw-r--r--win32/config_H.vc8
-rw-r--r--win32/config_H.vc642
-rw-r--r--win32/config_sh.PL5
-rw-r--r--win32/makefile.mk12
-rw-r--r--win32/perlhost.h4
-rw-r--r--win32/win32.c49
-rw-r--r--win32/win32iop.h2
14 files changed, 103 insertions, 28 deletions
diff --git a/win32/Makefile b/win32/Makefile
index 901ff0cda2..bba77a92cf 100644
--- a/win32/Makefile
+++ b/win32/Makefile
@@ -74,11 +74,17 @@ USE_IMP_SYS = define
USE_PERLIO = define
#
+# Comment this out if you don't want to enable large file support for
+# some reason. Should normally only be changed to maintain compatibility
+# with an older release of perl.
+USE_LARGE_FILES = define
+
+#
# uncomment one of the following lines if you are using either
# Visual C++ 2.x or Visual C++ 6.x (aka Visual Studio 98)
#
#CCTYPE = MSVC20
-#CCTYPE = MSVC60
+CCTYPE = MSVC60
#
# uncomment next line if you want debug version of perl (big,slow)
@@ -216,6 +222,10 @@ USE_IMP_SYS = undef
USE_PERLIO = undef
!ENDIF
+!IF "$(USE_LARGE_FILES)" == ""
+USE_LARGE_FILES = undef
+!ENDIF
+
!IF "$(USE_PERLCRT)" == ""
USE_PERLCRT = undef
!ENDIF
@@ -767,6 +777,7 @@ CFG_VARS = \
"useithreads=$(USE_ITHREADS)" \
"usemultiplicity=$(USE_MULTI)" \
"useperlio=$(USE_PERLIO)" \
+ "uselargefiles=$(USE_LARGE_FILES)" \
"LINK_FLAGS=$(LINK_FLAGS:"=\")" \
"optimize=$(OPTIMIZE:"=\")"
diff --git a/win32/config.bc b/win32/config.bc
index 7d669fffa8..d8ac588975 100644
--- a/win32/config.bc
+++ b/win32/config.bc
@@ -697,8 +697,8 @@ longsize='4'
lp=''
lpr=''
ls='dir'
-lseeksize='4'
-lseektype='off_t'
+lseeksize='8'
+lseektype='__int64'
mail=''
mailx=''
make='dmake'
@@ -904,7 +904,7 @@ use64bitint='undef'
usecrosscompile='undef'
usedl='define'
useithreads='undef'
-uselargefiles='undef'
+uselargefiles='define'
uselongdouble='undef'
usemorebits='undef'
usemultiplicity='undef'
diff --git a/win32/config.gc b/win32/config.gc
index 141fb542ee..f603bee878 100644
--- a/win32/config.gc
+++ b/win32/config.gc
@@ -697,8 +697,8 @@ longsize='4'
lp=''
lpr=''
ls='dir'
-lseeksize='4'
-lseektype='off_t'
+lseeksize='8'
+lseektype='long long'
mail=''
mailx=''
make='dmake'
@@ -904,7 +904,7 @@ use64bitint='undef'
usecrosscompile='undef'
usedl='define'
useithreads='undef'
-uselargefiles='undef'
+uselargefiles='define'
uselongdouble='undef'
usemorebits='undef'
usemultiplicity='undef'
diff --git a/win32/config.vc b/win32/config.vc
index 89192be0a0..3400eff7d3 100644
--- a/win32/config.vc
+++ b/win32/config.vc
@@ -697,8 +697,8 @@ longsize='4'
lp=''
lpr=''
ls='dir'
-lseeksize='4'
-lseektype='off_t'
+lseeksize='8'
+lseektype='__int64'
mail=''
mailx=''
make='nmake'
@@ -904,7 +904,7 @@ use64bitint='undef'
usecrosscompile='undef'
usedl='define'
useithreads='undef'
-uselargefiles='undef'
+uselargefiles='define'
uselongdouble='undef'
usemorebits='undef'
usemultiplicity='undef'
diff --git a/win32/config.vc64 b/win32/config.vc64
index bc969884bb..ca88714ce3 100644
--- a/win32/config.vc64
+++ b/win32/config.vc64
@@ -904,7 +904,7 @@ use64bitint='define'
usecrosscompile='undef'
usedl='define'
useithreads='undef'
-uselargefiles='undef'
+uselargefiles='define'
uselongdouble='undef'
usemorebits='undef'
usemultiplicity='undef'
diff --git a/win32/config_H.bc b/win32/config_H.bc
index f4fec85114..8bcd5fbf47 100644
--- a/win32/config_H.bc
+++ b/win32/config_H.bc
@@ -2950,9 +2950,9 @@
/* Off_t_size:
* This symbol holds the number of bytes used by the Off_t.
*/
-#define Off_t off_t /* <offset> type */
-#define LSEEKSIZE 4 /* <offset> size */
-#define Off_t_size 4 /* <offset> size */
+#define Off_t __int64 /* <offset> type */
+#define LSEEKSIZE 8 /* <offset> size */
+#define Off_t_size 8 /* <offset> size */
/* Free_t:
* This variable contains the return type of free(). It is usually
@@ -3445,7 +3445,7 @@
* should be used when available.
*/
#ifndef USE_LARGE_FILES
-/*#define USE_LARGE_FILES /**/
+#define USE_LARGE_FILES /**/
#endif
/* USE_LONG_DOUBLE:
diff --git a/win32/config_H.gc b/win32/config_H.gc
index 2422466cc2..c9ce6673ac 100644
--- a/win32/config_H.gc
+++ b/win32/config_H.gc
@@ -2950,9 +2950,9 @@
/* Off_t_size:
* This symbol holds the number of bytes used by the Off_t.
*/
-#define Off_t off_t /* <offset> type */
-#define LSEEKSIZE 4 /* <offset> size */
-#define Off_t_size 4 /* <offset> size */
+#define Off_t long long /* <offset> type */
+#define LSEEKSIZE 8 /* <offset> size */
+#define Off_t_size 8 /* <offset> size */
/* Free_t:
* This variable contains the return type of free(). It is usually
@@ -3445,7 +3445,7 @@
* should be used when available.
*/
#ifndef USE_LARGE_FILES
-/*#define USE_LARGE_FILES /**/
+#define USE_LARGE_FILES /**/
#endif
/* USE_LONG_DOUBLE:
diff --git a/win32/config_H.vc b/win32/config_H.vc
index 8fcfb0fbfb..c4ba4a51cc 100644
--- a/win32/config_H.vc
+++ b/win32/config_H.vc
@@ -2950,9 +2950,9 @@
/* Off_t_size:
* This symbol holds the number of bytes used by the Off_t.
*/
-#define Off_t off_t /* <offset> type */
-#define LSEEKSIZE 4 /* <offset> size */
-#define Off_t_size 4 /* <offset> size */
+#define Off_t __int64 /* <offset> type */
+#define LSEEKSIZE 8 /* <offset> size */
+#define Off_t_size 8 /* <offset> size */
/* Free_t:
* This variable contains the return type of free(). It is usually
@@ -3445,7 +3445,7 @@
* should be used when available.
*/
#ifndef USE_LARGE_FILES
-/*#define USE_LARGE_FILES /**/
+#define USE_LARGE_FILES /**/
#endif
/* USE_LONG_DOUBLE:
diff --git a/win32/config_H.vc64 b/win32/config_H.vc64
index 5f1ff0fc8d..5572c2613c 100644
--- a/win32/config_H.vc64
+++ b/win32/config_H.vc64
@@ -3445,7 +3445,7 @@
* should be used when available.
*/
#ifndef USE_LARGE_FILES
-/*#define USE_LARGE_FILES /**/
+#define USE_LARGE_FILES /**/
#endif
/* USE_LONG_DOUBLE:
diff --git a/win32/config_sh.PL b/win32/config_sh.PL
index b31415d88a..3b76cd04ea 100644
--- a/win32/config_sh.PL
+++ b/win32/config_sh.PL
@@ -90,6 +90,11 @@ if (defined(&Win32::IsWin95) && Win32::IsWin95()) {
$opt{d_link} = 'undef';
}
+if ($opt{uselargefiles} ne 'define') {
+ $opt{lseeksize} = 4;
+ $opt{lseektype} = 'off_t';
+}
+
while (<>) {
s/~([\w_]+)~/$opt{$1}/g;
if (/^([\w_]+)=(.*)$/) {
diff --git a/win32/makefile.mk b/win32/makefile.mk
index 683cb420b8..723d5b2815 100644
--- a/win32/makefile.mk
+++ b/win32/makefile.mk
@@ -73,7 +73,13 @@ USE_IMP_SYS *= define
# then get a number of fails from make test i.e. bugs - complain to them not us ;-).
# You will also be unable to take full advantage of perl5.8's support for multiple
# encodings and may see lower IO performance. You have been warned.
-USE_PERLIO = define
+USE_PERLIO *= define
+
+#
+# Comment this out if you don't want to enable large file support for
+# some reason. Should normally only be changed to maintain compatibility
+# with an older release of perl.
+USE_LARGE_FILES *= define
#
# uncomment exactly one of the following
@@ -233,6 +239,7 @@ USE_MULTI *= undef
USE_ITHREADS *= undef
USE_IMP_SYS *= undef
USE_PERLIO *= undef
+USE_LARGE_FILES *= undef
USE_PERLCRT *= undef
.IF "$(USE_IMP_SYS)$(USE_MULTI)" == "defineundef"
@@ -813,7 +820,8 @@ CFG_VARS = \
useithreads=$(USE_ITHREADS) ~ \
usemultiplicity=$(USE_MULTI) ~ \
useperlio=$(USE_PERLIO) ~ \
- LINK_FLAGS=$(LINK_FLAGS:s/\/\\/) ~ \
+ uselargefiles=$(USE_LARGE_FILES) ~ \
+ LINK_FLAGS=$(LINK_FLAGS:s/\/\\/) ~ \
optimize=$(OPTIMIZE)
#
diff --git a/win32/perlhost.h b/win32/perlhost.h
index 7926142954..b68f5c771b 100644
--- a/win32/perlhost.h
+++ b/win32/perlhost.h
@@ -939,9 +939,9 @@ PerlLIOChown(struct IPerlLIO* piPerl, const char *filename, uid_t owner, gid_t g
}
int
-PerlLIOChsize(struct IPerlLIO* piPerl, int handle, long size)
+PerlLIOChsize(struct IPerlLIO* piPerl, int handle, Off_t size)
{
- return chsize(handle, size);
+ return win32_chsize(handle, size);
}
int
diff --git a/win32/win32.c b/win32/win32.c
index 633dbbdbcc..556d62145c 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -3073,6 +3073,55 @@ win32_setmode(int fd, int mode)
return setmode(fd, mode);
}
+DllExport int
+win32_chsize(int fd, Off_t size)
+{
+#if defined(WIN64) || defined(USE_LARGE_FILES)
+ int retval = 0;
+ Off_t cur, end, extend;
+
+ cur = win32_tell(fd);
+ if (cur < 0)
+ return -1;
+ end = win32_lseek(fd, 0, SEEK_END);
+ if (end < 0)
+ return -1;
+ extend = size - end;
+ if (extend == 0) {
+ /* do nothing */
+ }
+ else if (extend > 0) {
+ /* must grow the file, padding with nulls */
+ char b[4096];
+ int oldmode = win32_setmode(fd, O_BINARY);
+ size_t count;
+ memset(b, '\0', sizeof(b));
+ do {
+ count = extend >= sizeof(b) ? sizeof(b) : (size_t)extend;
+ count = win32_write(fd, b, count);
+ if (count < 0) {
+ retval = -1;
+ break;
+ }
+ } while ((extend -= count) > 0);
+ win32_setmode(fd, oldmode);
+ }
+ else {
+ /* shrink the file */
+ win32_lseek(fd, size, SEEK_SET);
+ if (!SetEndOfFile((HANDLE)_get_osfhandle(fd))) {
+ errno = EACCES;
+ retval = -1;
+ }
+ }
+finish:
+ win32_lseek(fd, cur, SEEK_SET);
+ return retval;
+#else
+ return chsize(fd, size);
+#endif
+}
+
DllExport Off_t
win32_lseek(int fd, Off_t offset, int origin)
{
diff --git a/win32/win32iop.h b/win32/win32iop.h
index 52c59b45b5..e835b2eea6 100644
--- a/win32/win32iop.h
+++ b/win32/win32iop.h
@@ -77,6 +77,7 @@ DllExport PerlIO* win32_popenlist(const char *mode, IV narg, SV **args);
DllExport int win32_pclose( PerlIO *pf);
DllExport int win32_rename( const char *oname, const char *newname);
DllExport int win32_setmode( int fd, int mode);
+DllExport int win32_chsize(int fd, Off_t size);
DllExport Off_t win32_lseek( int fd, Off_t offset, int origin);
DllExport Off_t win32_tell( int fd);
DllExport int win32_dup( int fd);
@@ -236,6 +237,7 @@ END_EXTERN_C
#define longpath(pth) win32_longpath(pth)
#define rename(old,new) win32_rename(old,new)
#define setmode(fd,mode) win32_setmode(fd,mode)
+#define chsize(fd,sz) win32_chsize(fd,sz)
#define lseek(fd,offset,orig) win32_lseek(fd,offset,orig)
#define tell(fd) win32_tell(fd)
#define dup(fd) win32_dup(fd)