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

Comparing ray/src/common/savqstr.c (file contents):
Revision 2.2 by greg, Wed Jan 27 20:23:49 1993 UTC vs.
Revision 2.11 by greg, Tue Feb 1 18:43:26 2022 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1993 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
4 + /*
5 + *  Save unshared strings.
6 + *
7 + *  External symbols declared in standard.h
8 + */
9  
10 + #include "copyright.h"
11 +
12 + #include <stdlib.h>
13 +
14 + #include "rtio.h"
15 + #include "rterror.h"
16 +
17 +
18 + #if 1
19 +
20 + char *
21 + savqstr(char *s)                        /* save a private string */
22 + {
23 +        char  *cp;
24 +        char  *newp;
25 +
26 +        if (s == NULL)
27 +                return(NULL);
28 +        if (!*s)
29 +                return("");
30 +        for (cp = s; *cp++; )                   /* compute strlen()+1 */
31 +                ;
32 +        newp = (char *)malloc(cp-s);
33 +        if (newp == NULL) {
34 +                eputs("out of memory in savqstr");
35 +                quit(1);
36 +        }
37 +        for (cp = newp; (*cp++ = *s++); )       /* inline strcpy() */
38 +                ;
39 +        return(newp);                           /* return new location */
40 + }
41 +
42 +
43 + void
44 + freeqstr(char *s)                       /* free a private string */
45 + {
46 +        if (s != NULL && *s)
47 +                free(s);
48 + }
49 +
50 + #else
51 +
52   /*
53   *  Save unshared strings, packing them together into
54   *  large blocks to optimize paging in VM environments.
55   */
56  
57 < #define  NULL           0
57 > #include "rtmisc.h"
58  
59 < #ifdef  BIGMEM
59 > #ifdef  SMLMEM
60   #ifndef  MINBLOCK
61 < #define  MINBLOCK       (1<<12)         /* minimum allocation block size */
61 > #define  MINBLOCK       (1<<10)         /* minimum allocation block size */
62   #endif
63   #ifndef  MAXBLOCK
64 < #define  MAXBLOCK       (1<<16)         /* maximum allocation block size */
64 > #define  MAXBLOCK       (1<<14)         /* maximum allocation block size */
65   #endif
66   #else
67   #ifndef  MINBLOCK
68 < #define  MINBLOCK       (1<<10)         /* minimum allocation block size */
68 > #define  MINBLOCK       (1<<12)         /* minimum allocation block size */
69   #endif
70   #ifndef  MAXBLOCK
71 < #define  MAXBLOCK       (1<<14)         /* maximum allocation block size */
71 > #define  MAXBLOCK       (1<<16)         /* maximum allocation block size */
72   #endif
73   #endif
74  
30 extern char  *bmalloc();
75  
32
76   char *
77 < savqstr(s)                      /* save a private string */
35 < register char  *s;
77 > savqstr(char *s)                        /* save a private string */
78   {
79          static char  *curp = NULL;              /* allocated memory pointer */
80          static unsigned  nrem = 0;              /* bytes remaining in block */
81          static unsigned  nextalloc = MINBLOCK;  /* next block size */
82 <        register char  *cp;
83 <        register unsigned  n;
82 >        char  *cp;
83 >        unsigned  n;
84  
85 +        if (s == NULL)
86 +                return(NULL);
87 +        if (!*s)
88 +                return("");
89          for (cp = s; *cp++; )                   /* compute strlen()+1 */
90                  ;
91          if ((n = cp-s) > nrem) {                /* do we need more core? */
92                  bfree(curp, nrem);                      /* free remnant */
93                  while (n > nextalloc)
94                          nextalloc <<= 1;
95 <                if ((curp = bmalloc(nrem=nextalloc)) == NULL) {
95 >                if ((curp = (char *)bmalloc(nrem=nextalloc)) == NULL) {
96                          eputs("out of memory in savqstr");
97                          quit(1);
98                  }
# Line 62 | Line 108 | register char  *s;
108   }
109  
110  
111 < freeqstr(s)                     /* free a private string (not recommended) */
112 < char  *s;
111 > void
112 > freeqstr(char *s)               /* free a private string (not recommended) */
113   {
114 <        bfree(s, strlen(s)+1);
114 >        if (s != NULL && *s)
115 >                bfree(s, strlen(s)+1);
116   }
117 +
118 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines