]>
Commit | Line | Data |
---|---|---|
bac41a7b A |
1 | /* |
2 | * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved. | |
3 | * | |
4 | * The contents of this file constitute Original Code as defined in and are | |
5 | * subject to the Apple Public Source License Version 1.2 (the 'License'). | |
6 | * You may not use this file except in compliance with the License. Please obtain | |
7 | * a copy of the License at http://www.apple.com/publicsource and read it before | |
8 | * using this file. | |
9 | * | |
10 | * This Original Code and all software distributed under the License are | |
11 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS | |
12 | * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT | |
13 | * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | |
14 | * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the | |
15 | * specific language governing rights and limitations under the License. | |
16 | */ | |
17 | ||
18 | ||
19 | // file: .../c++-lib/src/str-stk.C | |
20 | // | |
21 | // MS 92/07/06 | |
22 | // Copyright (C) 1992 Michael Sample and the University of British Columbia | |
23 | // | |
24 | // This library is free software; you can redistribute it and/or | |
25 | // modify it provided that this copyright/license information is retained | |
26 | // in original form. | |
27 | // | |
28 | // If you modify this file, you must clearly indicate your changes. | |
29 | // | |
30 | // This source code is distributed in the hope that it will be | |
31 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty | |
32 | // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
33 | // | |
5a719ac8 | 34 | // $Header: /cvs/Darwin/src/live/Security/SecuritySNACCRuntime/c++-lib/c++/str-stk.cpp,v 1.2 2002/02/07 04:30:04 mb Exp $ |
bac41a7b | 35 | // $Log: str-stk.cpp,v $ |
29654253 A |
36 | // Revision 1.2 2002/02/07 04:30:04 mb |
37 | // Fixes required to build with gcc3. | |
38 | // Merged from branch PR-2848996 | |
39 | // Bug #: 2848996 | |
40 | // Submitted by: | |
41 | // Reviewed by: Turly O'Connor <turly@apple.com> | |
42 | // | |
43 | // Revision 1.1.1.1.12.1 2002/02/06 23:45:03 mb | |
44 | // Changes to allow building with gcc3 | |
45 | // | |
bac41a7b A |
46 | // Revision 1.1.1.1 2001/05/18 23:14:06 mb |
47 | // Move from private repository to open source repository | |
48 | // | |
49 | // Revision 1.3 2001/05/05 00:59:17 rmurphy | |
50 | // Adding darwin license headers | |
51 | // | |
52 | // Revision 1.2 2000/12/07 22:16:57 dmitch | |
53 | // Thread-safe mods: removed global StrStk strStkG. | |
54 | // | |
55 | // | |
56 | // 2000/12/7 dmitch | |
57 | // #ifdef'd out strStkG for thread safety | |
58 | // | |
59 | // Revision 1.1 2000/06/15 18:44:58 dmitch | |
60 | // These snacc-generated source files are now checked in to allow cross-platform build. | |
61 | // | |
62 | // Revision 1.2 2000/06/08 20:05:37 dmitch | |
63 | // Mods for X port. These files are actually machine generated and probably don't need to be in CVS.... | |
64 | // | |
65 | // Revision 1.1.1.1 2000/03/09 01:00:06 rmurphy | |
66 | // Base Fortissimo Tree | |
67 | // | |
68 | // Revision 1.2 1999/06/04 21:43:21 mb | |
69 | // Fixed several memory leaks. | |
70 | // | |
71 | // Revision 1.1 1999/02/25 05:21:57 mb | |
72 | // Added snacc c++ library | |
73 | // | |
74 | // Revision 1.5 1997/02/16 20:26:11 rj | |
75 | // check-in of a few cosmetic changes | |
76 | // | |
77 | // Revision 1.4 1995/07/24 20:34:57 rj | |
78 | // changed `_' to `-' in file names. | |
79 | // | |
80 | // Revision 1.3 1994/10/08 04:15:22 rj | |
81 | // fixed both Copy()'s name and implementation to CopyOut() that always returns the number of bytes copied out instead of 0 in case less than the requested amount is available. | |
82 | // | |
83 | // several `unsigned long int' turned into `size_t'. | |
84 | // | |
85 | // Revision 1.2 1994/08/28 10:01:24 rj | |
86 | // comment leader fixed. | |
87 | // | |
88 | // Revision 1.1 1994/08/28 09:21:13 rj | |
89 | // first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog. | |
90 | ||
91 | #include "asn-config.h" | |
92 | #include "str-stk.h" | |
93 | ||
94 | #ifndef __APPLE__ | |
95 | /* clients each have their own for OS X */ | |
96 | // global for use by AsnBits and AsnOcts | |
97 | ||
98 | StrStk strStkG (128, 64); | |
99 | #endif /* 0 */ | |
100 | ||
101 | StrStk::StrStk (int stkSize, int growIncrement) | |
102 | { | |
103 | stk = new struct Elmt[stkSize]; | |
104 | size = stkSize; | |
105 | growSize = growIncrement; | |
106 | } | |
107 | ||
108 | StrStk::~StrStk () | |
109 | { | |
110 | delete stk; | |
111 | } | |
112 | ||
113 | void StrStk::Reset() | |
114 | { | |
115 | nextFreeElmt = 0; | |
116 | totalByteLen = 0; | |
117 | } | |
118 | ||
119 | void StrStk::Push (char *str, size_t strLen) | |
120 | { | |
121 | if (nextFreeElmt >= size) | |
122 | { | |
123 | struct Elmt *tmpStk; | |
124 | // alloc bigger stack and copy old elmts to it | |
125 | tmpStk = new struct Elmt[size + growSize]; | |
29654253 | 126 | for (size_t i = 0; i < size; i++) |
bac41a7b A |
127 | tmpStk[i] = stk[i]; |
128 | delete stk; | |
129 | stk = tmpStk; | |
130 | size += growSize; | |
131 | } | |
132 | totalByteLen += strLen; | |
133 | stk[nextFreeElmt].str = str; | |
134 | stk[nextFreeElmt++].len = strLen; | |
135 | } | |
136 | ||
137 | /* | |
138 | * copy string pieces (buffer refs) into single block. | |
139 | * assumes that the buf is at least totalByteLen byte long. | |
140 | */ | |
141 | void StrStk::CopyOut (char *buf) | |
142 | { | |
143 | unsigned long int curr; | |
144 | char *bufCurr; | |
145 | ||
146 | bufCurr = buf; | |
147 | for (curr = 0; curr < nextFreeElmt; curr++) | |
148 | { | |
149 | memcpy (bufCurr, stk[curr].str, stk[curr].len); | |
150 | bufCurr += stk[curr].len; | |
151 | } | |
152 | } |