[haiku-commits] r35960 - haiku/trunk/src/add-ons/kernel/drivers/tty

  • From: revol@xxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 26 Mar 2010 20:47:23 +0100 (CET)

Author: mmu_man
Date: 2010-03-26 20:47:23 +0100 (Fri, 26 Mar 2010)
New Revision: 35960
Changeset: http://dev.haiku-os.org/changeset/35960/haiku

Modified:
   haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp
Log:
Implemented ioctl(FIONREAD) on tty devices. Untested.


Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp
===================================================================
--- haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp  2010-03-26 17:34:44 UTC 
(rev 35959)
+++ haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp  2010-03-26 19:47:23 UTC 
(rev 35960)
@@ -17,6 +17,7 @@
 #include <signal.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
@@ -1739,6 +1740,26 @@
                        return B_OK;
                }
 
+               case FIONREAD:
+               {
+                       int toRead = 0;
+
+                       // release the mutex and grab a read lock
+                       locker.Unlock();
+                       ReaderLocker readLocker(cookie);
+
+                       status_t status = readLocker.AcquireReader(0, 1);
+                       if (status >= B_OK)
+                               toRead = readLocker.AvailableBytes();
+                       else if(status != B_WOULD_BLOCK)
+                               return status;
+
+                       if (user_memcpy(buffer, &toRead, sizeof(int)) != B_OK)
+                               return B_BAD_ADDRESS;
+
+                       return B_OK;
+               }
+
                case TCWAITEVENT:               // BeOS (uint*)
                                                                // wait for 
event (timeout if !NULL)
                case TCVTIME:                   // BeOS (bigtime_t*) set 
highrez VTIME


Other related posts:

  • » [haiku-commits] r35960 - haiku/trunk/src/add-ons/kernel/drivers/tty - revol