Print this page
make: use the more modern wchar routines, not widec.h
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/bin/macro.cc
+++ new/usr/src/cmd/make/bin/macro.cc
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 /*
27 27 * macro.cc
28 28 *
29 29 * Handle expansion of make macros
30 30 */
31 31
32 32 /*
33 33 * Included files
34 34 */
35 35 #include <mk/defs.h>
36 36 #include <mksh/macro.h> /* getvar(), expand_value() */
37 37 #include <mksh/misc.h> /* getmem() */
38 38
39 39 /*
40 40 * Defined macros
41 41 */
42 42
43 43 /*
44 44 * typedefs & structs
45 45 */
46 46
47 47 /*
48 48 * Static variables
49 49 */
50 50
51 51 /*
52 52 * File table of contents
53 53 */
54 54
55 55 void
56 56 setvar_append(register Name name, register Name value)
57 57 {
58 58 register Property macro_apx = get_prop(name->prop, macro_append_prop);
59 59 register Property macro = get_prop(name->prop, macro_prop);
60 60 int length;
61 61 String_rec destination;
62 62 wchar_t buffer[STRING_BUFFER_LENGTH];
63 63 register Chain chain;
64 64 Name val = NULL;
65 65
66 66 if(macro_apx == NULL) {
67 67 macro_apx = append_prop(name, macro_append_prop);
68 68 if(macro != NULL) {
69 69 macro_apx->body.macro_appendix.value = macro->body.macro.value;
70 70 }
71 71 }
72 72
73 73 val = macro_apx->body.macro_appendix.value_to_append;
74 74
75 75 INIT_STRING_FROM_STACK(destination, buffer);
76 76 buffer[0] = 0;
77 77 if (val != NULL) {
78 78 APPEND_NAME(val,
79 79 &destination,
80 80 (int) val->hash.length);
81 81 if (value != NULL) {
82 82 MBTOWC(wcs_buffer, " ");
83 83 append_char(wcs_buffer[0], &destination);
84 84 }
85 85 }
86 86 if (value != NULL) {
87 87 APPEND_NAME(value,
88 88 &destination,
89 89 (int) value->hash.length);
90 90 }
91 91 value = GETNAME(destination.buffer.start, FIND_LENGTH);
92 92 if (destination.free_after_use) {
93 93 retmem(destination.buffer.start);
94 94 }
95 95 macro_apx->body.macro_appendix.value_to_append = value;
96 96
97 97 SETVAR(name, empty_name, true);
98 98 }
99 99
100 100 /*
101 101 * setvar_envvar()
102 102 *
103 103 * This function scans the list of environment variables that have
104 104 * dynamic values and sets them.
105 105 *
106 106 * Parameters:
107 107 *
108 108 * Global variables used:
109 109 * envvar A list of environment vars with $ in value
110 110 */
111 111 void
112 112 setvar_envvar(void)
113 113 {
114 114 wchar_t buffer[STRING_BUFFER_LENGTH];
115 115 int length;
116 116 register char *mbs, *tmp_mbs_buffer = NULL;
117 117 register char *env, *tmp_mbs_buffer2 = NULL;
↓ open down ↓ |
117 lines elided |
↑ open up ↑ |
118 118 Envvar p;
119 119 String_rec value;
120 120
121 121 for (p = envvar; p != NULL; p = p->next) {
122 122 if (p->already_put
123 123 ) {
124 124 continue;
125 125 }
126 126 INIT_STRING_FROM_STACK(value, buffer);
127 127 expand_value(p->value, &value, false);
128 - if ((length = wslen(value.buffer.start)) >= MAXPATHLEN) {
128 + if ((length = wcslen(value.buffer.start)) >= MAXPATHLEN) {
129 129 mbs = tmp_mbs_buffer = getmem((length + 1) * MB_LEN_MAX);
130 130 (void) wcstombs(mbs,
131 131 value.buffer.start,
132 132 (length + 1) * MB_LEN_MAX);
133 133 } else {
134 134 mbs = mbs_buffer;
135 135 WCSTOMBS(mbs, value.buffer.start);
136 136 }
137 137 length = 2 + strlen(p->name->string_mb) + strlen(mbs);
138 138 if (!p->already_put || length > (MAXPATHLEN * MB_LEN_MAX)) {
139 139 env = tmp_mbs_buffer2 = getmem(length);
140 140 } else {
141 141 env = mbs_buffer2;
142 142 }
143 143 (void) sprintf(env,
144 144 "%s=%s",
145 145 p->name->string_mb,
146 146 mbs);
147 147 if (!p->already_put) {
148 148 (void) putenv(env);
149 149 p->already_put = true;
150 150 if (p->env_string) {
151 151 retmem_mb(p->env_string);
152 152 }
153 153 p->env_string = env;
154 154 tmp_mbs_buffer2 = NULL; // We should not return this memory now
155 155 }
156 156 if (tmp_mbs_buffer2) {
157 157 retmem_mb(tmp_mbs_buffer2);
158 158 tmp_mbs_buffer2 = NULL;
159 159 }
160 160 if (tmp_mbs_buffer) {
161 161 retmem_mb(tmp_mbs_buffer);
162 162 tmp_mbs_buffer = NULL;
163 163 }
164 164 }
165 165 }
166 166
167 167
↓ open down ↓ |
29 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX