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.20 by greg, Thu Jul 4 02:06:32 2019 UTC vs.
Revision 2.23 by greg, Fri Jan 15 18:31:38 2021 UTC

# Line 34 | Line 34 | putint(                                /* write a siz-byte integer to fp */
34   )
35   {
36          siz <<= 3;
37 <        while ((siz -= 8) >= 0)
37 >        while ((siz -= 8) > 0)
38                  putc((int)(i>>siz & 0xff), fp);
39 +        putc((int)(i & 0xff), fp);
40   }
41  
42  
# Line 57 | Line 58 | putflt(                                /* put out floating point number */
58                  e = 0;
59          }
60          putint(m, 4, fp);
61 <        putint((long)e, 1, fp);
61 >        putint(e, 1, fp);
62   }
63  
64  
65 < int
65 > size_t
66   putbinary(                      /* fwrite() replacement for small objects */
67          const void *p,
68 <        int elsiz,
69 <        int nel,
68 >        size_t elsiz,
69 >        size_t nel,
70          FILE *fp)
71   {
72          const char      *s = (const char *)p;
73 <        int             nbytes = elsiz*nel;
73 >        size_t          nbytes = elsiz*nel;
74  
75 <        if (nbytes > 256)
75 >        if (nbytes > 128)
76                  return(fwrite(p, elsiz, nel, fp));
77          
78          while (nbytes-- > 0)
79 <                putc(*s++, fp);
79 >                if (putc(*s++, fp) == EOF)
80 >                        return((elsiz*nel - nbytes)/elsiz);
81  
82          return(nel);
83   }
# Line 141 | Line 143 | getflt(                                /* get a floating point number */
143   }
144  
145  
146 < int
146 > size_t
147   getbinary(                      /* fread() replacement for small objects */
148          void *p,
149 <        int elsiz,
150 <        int nel,
149 >        size_t elsiz,
150 >        size_t nel,
151          FILE *fp)
152   {
153          char    *s = (char *)p;
154 <        int     nbytes = elsiz*nel;
154 >        size_t  nbytes = elsiz*nel;
155          int     c;
156  
157 <        if (nbytes > 256)
157 >        if (nbytes > 128)
158                  return(fread(p, elsiz, nel, fp));
159          
160          while (nbytes-- > 0) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines