File: np_read.C

package info (click to toggle)
peruser 4b33-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,952 kB
  • ctags: 1,064
  • sloc: cpp: 22,367; perl: 2,733; makefile: 345; sh: 335
file content (47 lines) | stat: -rw-r--r-- 818 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

#include "npserver.h"

int NP_Server::np_read( char *character )
{
   static int count = 0;
   static char buffer[ 16536 ], *pointer;

   while( count <= 0 )
   {
      if ( wait_for_activity( 0 ))
         return -1;

      if (( count = read( fd, buffer, sizeof buffer )) < 0 )
         if ( errno == EINTR )
            continue;
         else
         {
            snprintf( error_message, sizeof error_message, "NP_Server: "
                      "np_read(): read(): %s", strerror( errno ));
            return -1;
         }

      if ( !count )
         break;
      
      pointer = buffer;
   }
   
   if ( !count )
      return 1;

   *character = *pointer++;
   --count;

   return 0;
}