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.20 by greg, Thu Jul 4 02:06:32 2019 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 +        const void *p,
67 +        int elsiz,
68 +        int nel,
69 +        FILE *fp)
70 + {
71 +        const char      *s = (const char *)p;
72 +        int             nbytes = elsiz*nel;
73 +
74 +        if (nbytes > 256)
75 +                return(fwrite(p, elsiz, nel, fp));
76 +        
77 +        while (nbytes-- > 0)
78 +                putc(*s++, fp);
79 +
80 +        return(nel);
81 + }
82 +
83 +
84   char *
85   getstr(                         /* get null-terminated string */
86          char  *s,
# Line 124 | Line 138 | getflt(                                /* get a floating point number */
138          }
139          d = (l + (l > 0 ? .5 : -.5)) * (1./0x7fffffff);
140          return(ldexp(d, (int)getint(1, fp)));
141 + }
142 +
143 +
144 + int
145 + getbinary(                      /* fread() replacement for small objects */
146 +        void *p,
147 +        int elsiz,
148 +        int nel,
149 +        FILE *fp)
150 + {
151 +        char    *s = (char *)p;
152 +        int     nbytes = elsiz*nel;
153 +        int     c;
154 +
155 +        if (nbytes > 256)
156 +                return(fread(p, elsiz, nel, fp));
157 +        
158 +        while (nbytes-- > 0) {
159 +                if ((c = getc(fp)) == EOF)
160 +                        return((elsiz*nel - nbytes)/elsiz);
161 +                *s++ = c;
162 +        }
163 +        return(nel);
164   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines