瀏覽代碼

Updated for Win32 64-bit. Fixes #24.

woollybah 6 年之前
父節點
當前提交
982e9da0bb
共有 2 個文件被更改,包括 36 次插入36 次删除
  1. 14 14
      freeprocess.mod/freeprocess.bmx
  2. 22 22
      freeprocess.mod/freeprocess.c

+ 14 - 14
freeprocess.mod/freeprocess.bmx

@@ -35,15 +35,15 @@ Import "freeprocess.c"
 'processhandle should be assumed to be invalid, and neither function should be called
 'processhandle should be assumed to be invalid, and neither function should be called
 'again.
 'again.
 Extern
 Extern
-Function fdClose(fd:Int)
-Function fdRead:Long(fd:Int,buffer:Byte Ptr,count:Long)
-Function fdWrite:Long(fd:Int,buffer:Byte Ptr,count:Long)
-Function fdFlush(fd:Int)
-Function fdAvail:Int(fd:Int)
-Function fdProcess:Int(exe$,in_fd:Int Ptr,out_fd:Int Ptr,err_fd:Int Ptr,flags:Int)="fdProcess"
-Function fdProcessStatus:Int(processhandle:Int)
-Function fdTerminateProcess:Int(processhandle:Int)
-Function fdKillProcess:Int(processhandle:Int)
+Function fdClose(fd:Size_T)
+Function fdRead:Long(fd:Size_T,buffer:Byte Ptr,count:Long)
+Function fdWrite:Long(fd:Size_T,buffer:Byte Ptr,count:Long)
+Function fdFlush(fd:Size_T)
+Function fdAvail:Int(fd:Size_T)
+Function fdProcess:Int(exe$,in_fd:Size_T Ptr,out_fd:Size_T Ptr,err_fd:Size_T Ptr,flags:Int)="fdProcess"
+Function fdProcessStatus:Int(processhandle:Size_T)
+Function fdTerminateProcess:Int(processhandle:Size_T)
+Function fdKillProcess:Int(processhandle:Size_T)
 End Extern
 End Extern
 
 
 Const HIDECONSOLE:Int=1
 Const HIDECONSOLE:Int=1
@@ -52,7 +52,7 @@ Type TPipeStream Extends TStream
 
 
 	Field	readbuffer:Byte[4096]
 	Field	readbuffer:Byte[4096]
 	Field	bufferpos:Long
 	Field	bufferpos:Long
-	Field	readhandle:Int,writehandle:Int
+	Field	readhandle:Size_T,writehandle:Size_T
 
 
 	Method Close()
 	Method Close()
 		If readhandle
 		If readhandle
@@ -82,7 +82,7 @@ Type TPipeStream Extends TStream
 	End Method
 	End Method
 
 
 	Method ReadPipe:Byte[]()
 	Method ReadPipe:Byte[]()
-		Local	bytes:Byte[],n:Int
+		Local bytes:Byte[],n:Int
 		n=ReadAvail()
 		n=ReadAvail()
 		If n
 		If n
 			bytes=New Byte[n]
 			bytes=New Byte[n]
@@ -117,7 +117,7 @@ Type TPipeStream Extends TStream
 		Next
 		Next
 	End Method
 	End Method
 
 
-	Function Create:TPipeStream( in:Int,out:Int )
+	Function Create:TPipeStream( in:Size_T,out:Size_T )
 		Local stream:TPipeStream=New TPipeStream
 		Local stream:TPipeStream=New TPipeStream
 		stream.readhandle=in
 		stream.readhandle=in
 		stream.writehandle=out
 		stream.writehandle=out
@@ -129,7 +129,7 @@ End Type
 Type TProcess
 Type TProcess
 	Global ProcessList:TList
 	Global ProcessList:TList
 	Field	name$
 	Field	name$
-	Field	handle:Int
+	Field	handle:Size_T
 	Field	pipe:TPipeStream
 	Field	pipe:TPipeStream
 	Field	err:TPipeStream
 	Field	err:TPipeStream
 	Field   detached:Int
 	Field   detached:Int
@@ -178,7 +178,7 @@ Type TProcess
 
 
 	Function Create:TProcess(name$,flags:Int)
 	Function Create:TProcess(name$,flags:Int)
 		Local	p:TProcess
 		Local	p:TProcess
-		Local	infd:Int,outfd:Int,errfd:Int
+		Local	infd:Size_T,outfd:Size_T,errfd:Size_T
 ?MacOS
 ?MacOS
 		If FileType(name)=2
 		If FileType(name)=2
 			Local a$=StripExt(StripDir(name))
 			Local a$=StripExt(StripDir(name))

+ 22 - 22
freeprocess.mod/freeprocess.c

@@ -13,15 +13,15 @@
 #include <sys/wait.h>
 #include <sys/wait.h>
 #include <signal.h>
 #include <signal.h>
 
 
-int fdClose(int fd) {return close(fd);}
-BBLONG fdRead(int fd,char *buffer,BBLONG count) {return read(fd,buffer,count);}
-BBLONG fdWrite(int fd,char *buffer,BBLONG count) {return write(fd,buffer,count);}
-int fdAvail(int fd) {int avail;if (ioctl(fd,FIONREAD,&avail)) avail=avail;return avail;}
-int fdFlush(int fd) {}//flush(fd);}
+int fdClose(size_t fd) {return close(fd);}
+BBLONG fdRead(size_t fd,char *buffer,BBLONG count) {return read(fd,buffer,count);}
+BBLONG fdWrite(size_t fd,char *buffer,BBLONG count) {return write(fd,buffer,count);}
+int fdAvail(size_t fd) {int avail;if (ioctl(fd,FIONREAD,&avail)) avail=avail;return avail;}
+int fdFlush(size_t fd) {}//flush(fd);}
 
 
 ///return 1 for running, 0 for finished
 ///return 1 for running, 0 for finished
 //
 //
-int fdProcessStatus( int pid ){
+int fdProcessStatus( size_t pid ){
 
 
 	int status=0;
 	int status=0;
 	return !waitpid( pid,&status,WNOHANG );
 	return !waitpid( pid,&status,WNOHANG );
@@ -29,7 +29,7 @@ int fdProcessStatus( int pid ){
 
 
 //returns 0 for success, -1 for error
 //returns 0 for success, -1 for error
 //
 //
-int fdTerminateProcess(int pid){
+int fdTerminateProcess(size_t pid){
 
 
 	if( !killpg( pid,SIGTERM ) ){
 	if( !killpg( pid,SIGTERM ) ){
 		int status=0;
 		int status=0;
@@ -42,7 +42,7 @@ int fdTerminateProcess(int pid){
 
 
 //returns 0 for success, -1 for error
 //returns 0 for success, -1 for error
 //
 //
-int fdKillProcess(int pid){
+int fdKillProcess(size_t pid){
 
 
 	if( !killpg( pid,SIGKILL ) ){
 	if( !killpg( pid,SIGKILL ) ){
 		int status=0;
 		int status=0;
@@ -101,7 +101,7 @@ static char **makeargv( const char *cmd ){
 
 
 static int in[2],out[2],errfd[2];
 static int in[2],out[2],errfd[2];
 
 
-int fdProcess( BBString *bbcmd,int *procin,int *procout,int *procerr,int flags)
+size_t fdProcess( BBString *bbcmd,size_t *procin,size_t *procout,size_t *procerr,int flags)
 {
 {
 	char 	*const*argv;
 	char 	*const*argv;
 	int   	procid;
 	int   	procid;
@@ -210,12 +210,12 @@ int KillProcessGroup(HANDLE prochandle,int procid)
 	return res;
 	return res;
 }
 }
 
 
-int fdClose(int fd)
+int fdClose(size_t fd)
 {
 {
 	return CloseHandle((HANDLE)fd);
 	return CloseHandle((HANDLE)fd);
 }
 }
 
 
-BBLONG fdRead(int fd,char *buffer,BBLONG bytes)
+BBLONG fdRead(size_t fd,char *buffer,BBLONG bytes)
 {
 {
 	int		res;
 	int		res;
 	long	count;
 	long	count;
@@ -224,7 +224,7 @@ BBLONG fdRead(int fd,char *buffer,BBLONG bytes)
 	return 0;
 	return 0;
 }
 }
 
 
-BBLONG fdWrite(int fd,char *buffer,BBLONG bytes)
+BBLONG fdWrite(size_t fd,char *buffer,BBLONG bytes)
 {
 {
 	int		res;
 	int		res;
 	long	count;
 	long	count;
@@ -233,14 +233,14 @@ BBLONG fdWrite(int fd,char *buffer,BBLONG bytes)
 	return 0;
 	return 0;
 }
 }
 
 
-int fdFlush(int fd)
+int fdFlush(size_t fd)
 {
 {
 	int		res;
 	int		res;
 	res=FlushFileBuffers((HANDLE)fd);
 	res=FlushFileBuffers((HANDLE)fd);
 	return res;
 	return res;
 }
 }
 
 
-int fdAvail(int fd)
+int fdAvail(size_t fd)
 {
 {
 	int		res;
 	int		res;
 	long	avail;
 	long	avail;
@@ -250,7 +250,7 @@ int fdAvail(int fd)
 }
 }
 
 
 //returns 1 for running, 0 for finished
 //returns 1 for running, 0 for finished
-int fdProcessStatus( int pid ){
+int fdProcessStatus( size_t pid ){
 
 
 	PROCESS_INFORMATION *pi=(PROCESS_INFORMATION *)pid;
 	PROCESS_INFORMATION *pi=(PROCESS_INFORMATION *)pid;
 
 
@@ -267,7 +267,7 @@ int fdProcessStatus( int pid ){
 }
 }
 
 
 //returns 0 for success
 //returns 0 for success
-int fdTerminateProcess( int pid ){
+int fdTerminateProcess( size_t pid ){
 
 
 	PROCESS_INFORMATION *pi=(PROCESS_INFORMATION *)pid;
 	PROCESS_INFORMATION *pi=(PROCESS_INFORMATION *)pid;
 
 
@@ -280,7 +280,7 @@ int fdTerminateProcess( int pid ){
 }
 }
 
 
 //returns 0 for success
 //returns 0 for success
-int fdKillProcess( int pid ){
+int fdKillProcess( size_t pid ){
 	PROCESS_INFORMATION *pi=(PROCESS_INFORMATION *)pid;
 	PROCESS_INFORMATION *pi=(PROCESS_INFORMATION *)pid;
 
 
 	int res=KillProcessGroup( pi->hProcess,pi->dwProcessId );
 	int res=KillProcessGroup( pi->hProcess,pi->dwProcessId );
@@ -291,7 +291,7 @@ int fdKillProcess( int pid ){
 	return res;
 	return res;
 }
 }
 
 
-int fdProcess( BBString *cmd,int *procin,int *procout,int *procerr,int flags)
+size_t fdProcess( BBString *cmd,size_t *procin,size_t *procout,size_t *procerr,int flags)
 {
 {
 	int res;
 	int res;
 	int pflags=CREATE_NEW_PROCESS_GROUP;
 	int pflags=CREATE_NEW_PROCESS_GROUP;
@@ -370,15 +370,15 @@ int fdProcess( BBString *cmd,int *procin,int *procout,int *procerr,int flags)
 
 
 	CloseHandle( pi->hThread );
 	CloseHandle( pi->hThread );
 
 
-	*procin=(int)istr;
-	*procout=(int)ostr;
-	*procerr=(int)estr;
+	*procin=(size_t)istr;
+	*procout=(size_t)ostr;
+	*procerr=(size_t)estr;
 
 
 	CloseHandle( p_istr );
 	CloseHandle( p_istr );
 	CloseHandle( p_ostr );
 	CloseHandle( p_ostr );
 	CloseHandle( p_estr );
 	CloseHandle( p_estr );
 
 
-	return (int)pi;
+	return (size_t)pi;
 }
 }
 
 
 #endif
 #endif