From: Gurusamy Sarathy Date: Mon, 10 May 1999 08:22:07 +0000 (+0000) Subject: provide File::Copy::syscopy() via Win32::CopyFile() on win32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7509b6572737d9774c4d9688c4edf46238aa95f2;p=p5sagit%2Fp5-mst-13.2.git provide File::Copy::syscopy() via Win32::CopyFile() on win32 p4raw-id: //depot/perl@3362 --- diff --git a/lib/File/Copy.pm b/lib/File/Copy.pm index e1da6b6..fd812bc 100644 --- a/lib/File/Copy.pm +++ b/lib/File/Copy.pm @@ -64,6 +64,7 @@ sub copy { && !$to_a_handle && !($from_a_handle && $^O eq 'os2' ) # OS/2 cannot handle handles && !($from_a_handle && $^O eq 'mpeix') # and neither can MPE/iX. + && !($from_a_handle && $^O eq 'MSWin32') ) { return syscopy($from, $to); @@ -186,6 +187,11 @@ unless (defined &syscopy) { # preserve MPE file attributes. return system('/bin/cp', '-f', $_[0], $_[1]) == 0; }; + } elsif ($^O eq 'MSWin32') { + *syscopy = sub { + return 0 unless @_ == 2; + return Win32::CopyFile(@_, 1); + }; } else { *syscopy = \© } @@ -272,9 +278,9 @@ second parameter, preserving OS-specific attributes and file structure. For Unix systems, this is equivalent to the simple C routine. For VMS systems, this calls the C routine (see below). For OS/2 systems, this calls the C -XSUB directly. +XSUB directly. For Win32 systems, this calls C. -=head2 Special behaviour if C is defined (VMS and OS/2) +=head2 Special behaviour if C is defined (OS/2, VMS and Win32) If both arguments to C are not file handles, then C will perform a "system copy" of diff --git a/win32/win32.c b/win32/win32.c index 1e4e4c5..414e4c5 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -2961,6 +2961,17 @@ XS(w32_Sleep) XSRETURN_YES; } +static +XS(w32_CopyFile) +{ + dXSARGS; + if (items != 3) + croak("usage: Win32::CopyFile($from, $to, $overwrite)"); + if (CopyFile(SvPV_nolen(ST(0)), SvPV_nolen(ST(1)), !SvTRUE(ST(2)))) + XSRETURN_YES; + XSRETURN_NO; +} + void Perl_init_os_extras() { @@ -2992,6 +3003,7 @@ Perl_init_os_extras() newXS("Win32::GetShortPathName", w32_GetShortPathName, file); newXS("Win32::GetFullPathName", w32_GetFullPathName, file); newXS("Win32::GetLongPathName", w32_GetLongPathName, file); + newXS("Win32::CopyFile", w32_CopyFile, file); newXS("Win32::Sleep", w32_Sleep, file); /* XXX Bloat Alert! The following Activeware preloads really