summaryrefslogtreecommitdiff
path: root/games/gnomoku/files/patch-fdstream.cc
blob: 9157b5bdbcd7b99207d4a6d0d3af7c5abeca811b (plain) (blame)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
$FreeBSD$

--- fdstream.cc	2002/02/05 13:27:38	1.1
+++ fdstream.cc	2002/02/05 13:35:40
@@ -19,6 +19,8 @@
 #include "fdstream.h"
 
 #include <sys/types.h>
+#include <errno.h>
+#include <string.h>
 #include <unistd.h>
 
 namespace {
@@ -96,7 +98,7 @@
     return (num_written == count) ? 0 : -1;
 }
 
-fdstreambuf::int_type fdstreambuf::underflow()
+int fdstreambuf::underflow()
 {
     // Is the buffer already empty yet?
     char *tmp_gptr = gptr();
@@ -104,7 +106,8 @@
 
         char *tmp_eback = eback();
         const std::size_t num_putback =
-            std::min <std::size_t> (tmp_gptr - tmp_eback, pback_end_ - buf);
+            (tmp_gptr - tmp_eback >  pback_end_ - buf) ? pback_end_ - buf :
+	    tmp_gptr - tmp_eback;
 
         // Fill putback area.
         tmp_eback = pback_end_ - num_putback;
@@ -132,7 +135,7 @@
 
     // First, empty the current buffer.
     const std::size_t buf_avail = tmp_egptr - tmp_gptr;
-    std::streamsize   idx       = std::min <std::size_t> (buf_avail, count);
+    std::streamsize   idx       = (buf_avail > count) ? count : buf_avail;
 
     std::memcpy (dest, tmp_gptr, idx);
 
@@ -149,7 +152,7 @@
     if (tmp_gptr >= pback_end_) {
 
         const std::size_t num_putback =
-	    std::min <std::size_t> (idx, pback_end_ - buf);
+	    (idx > pback_end_ - buf) ? pback_end_ - buf : idx;
 
         tmp_eback = pback_end_ - num_putback;
         std::memcpy (tmp_eback, dest + idx - num_putback, num_putback);
@@ -185,7 +188,7 @@
     return (fd >= 0) ? flush() : -1;
 }
 
-fdstreambuf::int_type fdstreambuf::overflow (fdstreambuf::int_type c)
+int fdstreambuf::overflow (int c)
 {
     if (c != EOF) {
         *pptr() = int_to_char (c);