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.15 by greg, Fri Oct 19 01:40:33 2012 UTC vs.
Revision 2.18 by greg, Tue Mar 15 13:57:09 2016 UTC

# Line 13 | Line 13 | static const char      RCSid[] = "$Id$";
13  
14   #include <math.h>
15  
16 #ifdef getc_unlocked            /* avoid horrendous overhead of flockfile */
17 #undef getc
18 #undef putc
19 #define getc    getc_unlocked
20 #define putc    putc_unlocked
21 #endif
16  
23
17   void
18   putstr(                         /* write null-terminated string to fp */
19          char  *s,
# Line 40 | Line 33 | putint(                                /* write a siz-byte integer to fp */
33          FILE  *fp
34   )
35   {
36 <        while (siz--)
37 <                putc((int)(i>>(siz<<3) & 0xff), fp);
36 >        siz <<= 3;
37 >        while ((siz -= 8) >= 0)
38 >                putc((int)(i>>siz & 0xff), fp);
39   }
40  
41  
# Line 67 | Line 61 | putflt(                                /* put out floating point number */
61   }
62  
63  
64 + int
65 + putbinary(                      /* fwrite() replacement for small objects */
66 +        char *s,
67 +        int elsiz,
68 +        int nel,
69 +        FILE *fp)
70 + {
71 +        int     nbytes = elsiz*nel;
72 +
73 +        if (nbytes > 512)
74 +                return(fwrite(s, elsiz, nel, fp));
75 +        
76 +        while (nbytes-- > 0)
77 +                putc(*s++, fp);
78 +
79 +        return(nel);
80 + }
81 +
82 +
83   char *
84   getstr(                         /* get null-terminated string */
85          char  *s,
# Line 124 | Line 137 | getflt(                                /* get a floating point number */
137          }
138          d = (l + (l > 0 ? .5 : -.5)) * (1./0x7fffffff);
139          return(ldexp(d, (int)getint(1, fp)));
140 + }
141 +
142 +
143 + int
144 + getbinary(                      /* fread() replacement for small objects */
145 +        char *s,
146 +        int elsiz,
147 +        int nel,
148 +        FILE *fp)
149 + {
150 +        int     nbytes = elsiz*nel;
151 +        int     c;
152 +
153 +        if (nbytes > 512)
154 +                return(fread(s, elsiz, nel, fp));
155 +        
156 +        while (nbytes-- > 0) {
157 +                if ((c = getc(fp)) == EOF)
158 +                        return((elsiz*nel - nbytes)/elsiz);
159 +                *s++ = c;
160 +        }
161 +        return(nel);
162   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines