Partial PeekNamedPipe Implementation

Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Sun Jul 21 15:53:06 CDT 2002


Hallo,

appended patch implements returning the number of bytes available for
reading in PeekNamedPipe. With this functionality, Xilinx Webpack can detect
the result of spawned subprocesses.

Changelog:
	wine/server/pipe.c,wine/server/named_pipe.c: xxx_get_info
	Return the number of bytes available for reading
	wine/dlls/kernel/sync.c: PeekNamedPipe
	Use get_file_info to get the number of bytes available for reading

Bye
-- 
Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Free Software: If you contribute nothing, expect nothing
--
Index: wine/server/pipe.c
===================================================================
RCS file: /home/wine/wine/server/pipe.c,v
retrieving revision 1.24
diff -u -r1.24 pipe.c
--- wine/server/pipe.c	30 May 2002 20:12:58 -0000	1.24
+++ wine/server/pipe.c	21 Jul 2002 20:49:10 -0000
@@ -30,6 +30,7 @@
 #endif
 #include <sys/time.h>
 #include <sys/types.h>
+#include <sys/ioctl.h>
 #include <time.h>
 #include <unistd.h>
 
@@ -141,6 +142,21 @@
 
 static int pipe_get_info( struct object *obj, struct get_file_info_reply *reply, int *flags )
 {
+    
+    int avail=0, fd;
+    assert( obj->ops == &pipe_ops );
+    /* On Linux fstat on a file descriptor always returns 0 
+       Use FIONREAD instead*/
+    fd = obj->ops->get_fd( obj );
+    if (fd == -1)
+      {
+	if (get_error() != STATUS_PIPE_BROKEN )
+	  fprintf(stderr, "cant get file descriptor for reason %d\n",get_error() );
+      }
+    else if (ioctl(fd,FIONREAD, &avail ) != 0)
+      {
+	fprintf(stderr, "can't get size for fd %08x %s\n",fd, strerror(errno));
+      }
     if (reply)
     {
         reply->type        = FILE_TYPE_PIPE;
@@ -148,7 +164,7 @@
         reply->access_time = 0;
         reply->write_time  = 0;
         reply->size_high   = 0;
-        reply->size_low    = 0;
+        reply->size_low    = avail;
         reply->links       = 0;
         reply->index_high  = 0;
         reply->index_low   = 0;
Index: wine/server/named_pipe.c
===================================================================
RCS file: /home/wine/wine/server/named_pipe.c,v
retrieving revision 1.14
diff -u -r1.14 named_pipe.c
--- wine/server/named_pipe.c	31 May 2002 23:06:53 -0000	1.14
+++ wine/server/named_pipe.c	21 Jul 2002 20:49:11 -0000
@@ -201,6 +201,22 @@
 
 static int pipe_user_get_info( struct object *obj, struct get_file_info_reply *reply, int *flags )
 {
+{
+    
+    int avail=0, fd;
+    assert( obj->ops == &pipe_ops );
+    /* On Linux fstat on a file descriptor always returns 0 
+       Use FIONREAD instead*/
+    fd = obj->ops->get_fd( obj );
+    if (fd == -1)
+      {
+	if (get_error() != STATUS_PIPE_BROKEN )
+	  fprintf(stderr, "cant get file descriptor for reason %d\n",get_error() );
+      }
+    else if (ioctl(fd,FIONREAD, &avail ) != 0)
+      {
+	fprintf(stderr, "can't get size for fd %08x %s\n",fd, strerror(errno));
+      }
     if (reply)
     {
         reply->type        = FILE_TYPE_PIPE;
@@ -208,7 +224,7 @@
         reply->access_time = 0;
         reply->write_time  = 0;
         reply->size_high   = 0;
-        reply->size_low    = 0;
+        reply->size_low    = avail;
         reply->links       = 0;
         reply->index_high  = 0;
         reply->index_low   = 0;
Index: wine/dlls/kernel/sync.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/sync.c,v
retrieving revision 1.20
diff -u -r1.20 sync.c
--- wine/dlls/kernel/sync.c	31 May 2002 23:25:48 -0000	1.20
+++ wine/dlls/kernel/sync.c	21 Jul 2002 20:49:11 -0000
@@ -25,6 +25,7 @@
 #include "winbase.h"
 #include "winerror.h"
 #include "winnls.h"
+#include <errno.h>
 
 #include "wine/server.h"
 #include "wine/unicode.h"
@@ -530,8 +531,32 @@
 BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer,
                            LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage )
 {
-    FIXME("(%08x, %p, %08lx, %p, %p, %p): stub\n",
+    INT avail;
+    unsigned int err;
+
+    TRACE("(%08x, %p, %08lx, %p, %p, %p): stub\n",
           hPipe, lpvBuffer, cbBuffer, lpcbRead, lpcbAvail, lpcbMessage);
+ 
+    SERVER_START_REQ( get_file_info )
+      {
+	req->handle = hPipe;
+	if (!(err =wine_server_call( req )))
+	  avail = reply->size_low;
+      }
+    SERVER_END_REQ;
+    if (err)
+      {
+	SetLastError( RtlNtStatusToDosError(err) );
+	TRACE("BON: returning error %ld \n", GetLastError());
+	return FALSE;
+      }
+    TRACE("BON: %08x bytes available\n", avail);
+    if (!lpvBuffer && lpcbAvail) /* only number of bytes available requested */
+      {
+	*lpcbAvail= avail;
+	return TRUE;
+      }
+    FIXME("function not implemented\n");
     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
     return FALSE;
 }



More information about the wine-patches mailing list