ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/portio.c
(Generate patch)

Comparing ray/src/common/portio.c (file contents):
Revision 2.23 by greg, Fri Jan 15 18:31:38 2021 UTC vs.
Revision 2.25 by greg, Fri Feb 19 16:15:23 2021 UTC

# Line 14 | Line 14 | static const char      RCSid[] = "$Id$";
14   #include <math.h>
15  
16  
17 < void
17 > int
18   putstr(                         /* write null-terminated string to fp */
19          char  *s,
20          FILE  *fp
# Line 22 | Line 22 | putstr(                                /* write null-terminated string to fp */
22   {
23          do
24                  putc(*s, fp);
25 <        while (*s++);
25 >        while (*++s);
26 >
27 >        return(putc(0, fp));    /* terminator */
28   }
29  
30  
31 < void
31 > int
32   putint(                         /* write a siz-byte integer to fp */
33          long  i,
34          int  siz,
35          FILE  *fp
36   )
37   {
38 +        while (siz > sizeof(long)) {
39 +                putc((i<0)*0xff, fp);
40 +                siz--;
41 +        }
42          siz <<= 3;
43          while ((siz -= 8) > 0)
44                  putc((int)(i>>siz & 0xff), fp);
45 <        putc((int)(i & 0xff), fp);
45 >
46 >        return(putc((int)(i & 0xff), fp) == EOF ? EOF : 0);
47   }
48  
49  
50 < void
50 > int
51   putflt(                         /* put out floating point number */
52          double  f,
53          FILE  *fp
# Line 58 | Line 65 | putflt(                                /* put out floating point number */
65                  e = 0;
66          }
67          putint(m, 4, fp);
68 <        putint(e, 1, fp);
68 >        return(putint(e, 1, fp));
69   }
70  
71  
# Line 112 | Line 119 | getint(                                /* get a siz-byte integer */
119  
120          if ((c = getc(fp)) == EOF)
121                  return(EOF);
122 <        r = 0x80&c ? -1<<8|c : c;               /* sign extend */
122 >        r = c;
123 >        if (c & 0x80)           /* sign extend? */
124 >                r |= -256L;
125          while (--siz > 0) {
126                  if ((c = getc(fp)) == EOF)
127                          return(EOF);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines