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.21 by greg, Fri Jul 5 03:04:22 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 +                if (putc(*s++, fp) == EOF)
79 +                        return((elsiz*nel - nbytes)/elsiz);
80 +
81 +        return(nel);
82 + }
83 +
84 +
85   char *
86   getstr(                         /* get null-terminated string */
87          char  *s,
# Line 124 | Line 139 | getflt(                                /* get a floating point number */
139          }
140          d = (l + (l > 0 ? .5 : -.5)) * (1./0x7fffffff);
141          return(ldexp(d, (int)getint(1, fp)));
142 + }
143 +
144 +
145 + int
146 + getbinary(                      /* fread() replacement for small objects */
147 +        void *p,
148 +        int elsiz,
149 +        int nel,
150 +        FILE *fp)
151 + {
152 +        char    *s = (char *)p;
153 +        int     nbytes = elsiz*nel;
154 +        int     c;
155 +
156 +        if (nbytes > 256)
157 +                return(fread(p, elsiz, nel, fp));
158 +        
159 +        while (nbytes-- > 0) {
160 +                if ((c = getc(fp)) == EOF)
161 +                        return((elsiz*nel - nbytes)/elsiz);
162 +                *s++ = c;
163 +        }
164 +        return(nel);
165   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines