      subroutine csub.poll(InFds, InEvents, OutEvents, timeout, res)
*
*
*
*
*
*
*
*
*
$catalog local
*
$include ccall.common
*
      equate libname to 'libc.so.6'
      equate fnname  to 'poll'
*
      $include ccall.getfn.include

      ufds = ''
      n.fds = dcount(InFds<1>,@vm)
      for i = 1 to n.fds
         event = 0
         if index(downcase(InEvents<1,i>),'r',1) then event += 1
         if index(downcase(InEvents<1,i>),'u',1) then event += 2
         if index(downcase(InEvents<1,i>),'w',1) then event += 4
         if index(downcase(InEvents<1,i>),'e',1) then event += 8
         if index(downcase(InEvents<1,i>),'h',1) then event += 16
         v1 = int2bin(InFds<1,i>,4)
         v2 = int2bin(event,2)
         ufds := ufds : v1 : v2 : CC$NUL : CC$NUL
      next i
      
*
      s1 = cc$nul4 : ufds

      v1 = int2bin(dcount(InFds<1>,@vm),4)
      v2 = int2bin(timeout,4)

      s2 = CC$FN.PUSHOFF : cc$4 :      ~
           CC$FN.PUSHVAL : v1 :        ~
           CC$FN.PUSHVAL : v2 :        ~
           CC$FN.CALLFN  : fn.handle : ~
           CC$FN.RTN32   : cc$0 :      ~
           CC$FN.EXIT
      s = ccall(s1,s2)

      ufds = s[5,999999]
      res = bin2int(s[1,4])

      call csub.errno

      OutEvents = ''
      for i = 1 to dcount(InFds<1>,@vm)
         revent = bin2int(ufds[(i-1)*8+1+6,2])
         if mod(revent,2) then OutEvents<1,i> := 'r'
         revent = int(revent/2)
         if mod(revent,2) then OutEvents<1,i> := 'u'
         revent = int(revent/2)
         if mod(revent,2) then OutEvents<1,i> := 'w'
         revent = int(revent/2)
         if mod(revent,2) then OutEvents<1,i> := 'e'
         revent = int(revent/2)
         if mod(revent,2) then OutEvents<1,i> := 'h'
         revent = int(revent/2)
         if mod(revent,2) then OutEvents<1,i> := 'i'
      next i
 
      return
   end
