@@ -708,6 +708,59 @@ do_local_cmd(arglist *a)
708708 #endif
709709}
710710
711+ static int pipe_counter = 1 ;
712+ /* create overlapped supported pipe */
713+ BOOL CreateOverlappedPipe (PHANDLE hReadPipe , PHANDLE hWritePipe , LPSECURITY_ATTRIBUTES sa , DWORD size ) {
714+ HANDLE read_handle = INVALID_HANDLE_VALUE , write_handle = INVALID_HANDLE_VALUE ;
715+ char pipe_name [MAX_PATH ];
716+
717+ /* create name for named pipe */
718+ if (-1 == sprintf_s (pipe_name , MAX_PATH , "\\\\.\\Pipe\\W32SCPPipe.%08x.%08x" ,
719+ GetCurrentProcessId (), pipe_counter ++ )) {
720+ debug ("pipe - ERROR sprintf_s %d" , errno );
721+ goto error ;
722+ }
723+
724+ read_handle = CreateNamedPipeA (pipe_name ,
725+ PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED ,
726+ PIPE_TYPE_BYTE | PIPE_WAIT ,
727+ 1 ,
728+ 4096 ,
729+ 4096 ,
730+ 0 ,
731+ sa );
732+ if (read_handle == INVALID_HANDLE_VALUE ) {
733+ debug ("pipe - CreateNamedPipe() ERROR:%d" , errno );
734+ goto error ;
735+ }
736+
737+ /* connect to named pipe */
738+ write_handle = CreateFileA (pipe_name ,
739+ GENERIC_WRITE ,
740+ 0 ,
741+ sa ,
742+ OPEN_EXISTING ,
743+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED ,
744+ NULL );
745+ if (write_handle == INVALID_HANDLE_VALUE ) {
746+ debug ("pipe - ERROR CreateFile() :%d" , errno );
747+ goto error ;
748+ }
749+
750+ * hReadPipe = read_handle ;
751+ * hWritePipe = write_handle ;
752+ return TRUE;
753+
754+ error :
755+ if (read_handle )
756+ CloseHandle (read_handle );
757+ if (write_handle )
758+ CloseHandle (write_handle );
759+
760+ return FALSE;
761+
762+ }
763+
711764/*
712765 * This function executes the given command as the specified user on the
713766 * given host. This returns < 0 if execution fails, and >= 0 otherwise. This
@@ -814,7 +867,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
814867 sa .lpSecurityDescriptor = NULL ;
815868 /* command processor output redirected to a nameless pipe */
816869
817- rc = CreatePipe ( & hstdout [0 ], & hstdout [1 ], & sa , 0 ) ;
870+ rc = CreateOverlappedPipe ( & hstdout [0 ], & hstdout [1 ], & sa , 0 ) ;
818871 /* read from this fd to get data from ssh.exe*/
819872
820873 // make scp's pipe read handle not inheritable by ssh
@@ -830,7 +883,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
830883 * fdin = _open_osfhandle ((intptr_t )hstdout [0 ],0 );
831884 _setmode (* fdin , O_BINARY ); // set this file handle for binary I/O
832885
833- rc = CreatePipe ( & hstdin [0 ], & hstdin [1 ], & sa , 0 ) ;
886+ rc = CreateOverlappedPipe ( & hstdin [0 ], & hstdin [1 ], & sa , 0 ) ;
834887 /* write to this fd to get data into ssh.exe*/
835888
836889 // make scp's pipe write handle not inheritable by ssh
@@ -1033,11 +1086,7 @@ int pflag, iamremote, iamrecursive, targetshouldbedirectory;
10331086char cmd [CMDNEEDS ]; /* must hold "rcp -r -p -d\0" */
10341087
10351088int response (void );
1036- #ifdef WIN32_FIXME
1037- void rsource (char * , struct _stati64 * );
1038- #else
10391089void rsource (char * , struct stat * );
1040- #endif
10411090
10421091void sink (int , char * []);
10431092void source (int , char * []);
@@ -1439,7 +1488,7 @@ tolocal(int argc, char **argv)
14391488void
14401489source (int argc , char * argv [])
14411490{
1442- struct _stati64 stb ;
1491+ struct stat stb ;
14431492 static BUF buffer ;
14441493 BUF * bp ;
14451494 off_t i ;
@@ -1520,7 +1569,7 @@ source(int argc, char *argv[])
15201569
15211570 if (_sopen_s (& fd , name , O_RDONLY | O_BINARY , _SH_DENYNO , 0 ) != 0 ) {
15221571 // in NT, we have to check if it is a directory
1523- if (_stati64 (name , & stb ) >= 0 ) {
1572+ if (stat (name , & stb ) >= 0 ) {
15241573 goto switchpoint ;
15251574 }
15261575 else
@@ -1692,7 +1741,7 @@ next: if (fd != -1) (void)_close(fd);
16921741 free (filenames [ii ]);
16931742}
16941743
1695- void rsource (char * name , struct _stati64 * statp )
1744+ void rsource (char * name , struct stat * statp )
16961745{
16971746 SCPDIR * dirp ;
16981747 struct scp_dirent * dp ;
@@ -1754,7 +1803,7 @@ void sink(int argc, char *argv[])
17541803{
17551804// DWORD dwread;
17561805 static BUF buffer ;
1757- struct _stati64 stb ;
1806+ struct stat stb ;
17581807 enum { YES , NO , DISPLAYED } wrerr ;
17591808 BUF * bp ;
17601809 size_t i , j , size ;
@@ -1812,7 +1861,7 @@ void sink(int argc, char *argv[])
18121861
18131862 (void )_write (remout , "" , 1 );
18141863
1815- if (_stati64 (targ , & stb ) == 0 && S_ISDIR (stb .st_mode ))
1864+ if (stat (targ , & stb ) == 0 && S_ISDIR (stb .st_mode ))
18161865 targisdir = 1 ;
18171866
18181867 for (first = 1 ;; first = 0 ) {
@@ -1912,7 +1961,7 @@ void sink(int argc, char *argv[])
19121961 np = namebuf ;
19131962 } else
19141963 np = targ ;
1915- exists = _stati64 (np , & stb ) == 0 ;
1964+ exists = stat (np , & stb ) == 0 ;
19161965 if (buf [0 ] == 'D' ) {
19171966 int mod_flag = pflag ;
19181967 if (exists ) {
@@ -2807,9 +2856,9 @@ char *win32colon(char *cp)
28072856
28082857void verifydir (char * cp )
28092858{
2810- struct _stati64 stb ;
2859+ struct stat stb ;
28112860
2812- if (!_stati64 (cp , & stb )) {
2861+ if (!stat (cp , & stb )) {
28132862 if (S_ISDIR (stb .st_mode ))
28142863 return ;
28152864 errno = ENOTDIR ;
0 commit comments