Updated from libc
[make.git] / variable.c
blob3bdf65bee01d55a799d726a79e33a41ffc33130f
1 /* Internals of variables for GNU Make.
2 Copyright (C) 1988, 89, 90, 91, 92, 93, 94, 96 Free Software Foundation, Inc.
3 This file is part of GNU Make.
5 GNU Make is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 GNU Make is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19 #include "make.h"
20 #include "dep.h"
21 #include "filedef.h"
22 #include "job.h"
23 #include "commands.h"
24 #include "variable.h"
25 #ifdef WIN32
26 #include "pathstuff.h"
27 #endif
29 /* Hash table of all global variable definitions. */
31 #ifndef VARIABLE_BUCKETS
32 #define VARIABLE_BUCKETS 523
33 #endif
34 #ifndef PERFILE_VARIABLE_BUCKETS
35 #define PERFILE_VARIABLE_BUCKETS 23
36 #endif
37 #ifndef SMALL_SCOPE_VARIABLE_BUCKETS
38 #define SMALL_SCOPE_VARIABLE_BUCKETS 13
39 #endif
40 static struct variable *variable_table[VARIABLE_BUCKETS];
41 static struct variable_set global_variable_set
42 = { variable_table, VARIABLE_BUCKETS };
43 static struct variable_set_list global_setlist
44 = { 0, &global_variable_set };
45 struct variable_set_list *current_variable_set_list = &global_setlist;
47 static struct variable *define_variable_in_set PARAMS ((char *name, unsigned int length,
48 char *value, enum variable_origin origin,
49 int recursive, struct variable_set *set));
52 /* Implement variables. */
54 /* Define variable named NAME with value VALUE in SET. VALUE is copied.
55 LENGTH is the length of NAME, which does not need to be null-terminated.
56 ORIGIN specifies the origin of the variable (makefile, command line
57 or environment).
58 If RECURSIVE is nonzero a flag is set in the variable saying
59 that it should be recursively re-expanded. */
61 static struct variable *
62 define_variable_in_set (name, length, value, origin, recursive, set)
63 char *name;
64 unsigned int length;
65 char *value;
66 enum variable_origin origin;
67 int recursive;
68 struct variable_set *set;
70 register unsigned int i;
71 register unsigned int hashval;
72 register struct variable *v;
74 hashval = 0;
75 for (i = 0; i < length; ++i)
76 HASH (hashval, name[i]);
77 hashval %= set->buckets;
79 for (v = set->table[hashval]; v != 0; v = v->next)
80 if (*v->name == *name
81 && !strncmp (v->name + 1, name + 1, length - 1)
82 && v->name[length] == '\0')
83 break;
85 if (env_overrides && origin == o_env)
86 origin = o_env_override;
88 if (v != 0)
90 if (env_overrides && v->origin == o_env)
91 /* V came from in the environment. Since it was defined
92 before the switches were parsed, it wasn't affected by -e. */
93 v->origin = o_env_override;
95 /* A variable of this name is already defined.
96 If the old definition is from a stronger source
97 than this one, don't redefine it. */
98 if ((int) origin >= (int) v->origin)
100 if (v->value != 0)
101 free (v->value);
102 v->value = savestring (value, strlen (value));
103 v->origin = origin;
104 v->recursive = recursive;
106 return v;
109 /* Create a new variable definition and add it to the hash table. */
111 v = (struct variable *) xmalloc (sizeof (struct variable));
112 v->name = savestring (name, length);
113 v->value = savestring (value, strlen (value));
114 v->origin = origin;
115 v->recursive = recursive;
116 v->expanding = 0;
117 v->export = v_default;
118 v->next = set->table[hashval];
119 set->table[hashval] = v;
120 return v;
123 /* Define a variable in the current variable set. */
125 struct variable *
126 define_variable (name, length, value, origin, recursive)
127 char *name;
128 unsigned int length;
129 char *value;
130 enum variable_origin origin;
131 int recursive;
133 return define_variable_in_set (name, length, value, origin, recursive,
134 current_variable_set_list->set);
137 /* Define a variable in FILE's variable set. */
139 struct variable *
140 define_variable_for_file (name, length, value, origin, recursive, file)
141 char *name;
142 unsigned int length;
143 char *value;
144 enum variable_origin origin;
145 int recursive;
146 struct file *file;
148 return define_variable_in_set (name, length, value, origin, recursive,
149 file->variables->set);
152 /* Lookup a variable whose name is a string starting at NAME
153 and with LENGTH chars. NAME need not be null-terminated.
154 Returns address of the `struct variable' containing all info
155 on the variable, or nil if no such variable is defined. */
157 struct variable *
158 lookup_variable (name, length)
159 char *name;
160 unsigned int length;
162 register struct variable_set_list *setlist;
164 register unsigned int i;
165 register unsigned int rawhash = 0;
167 for (i = 0; i < length; ++i)
168 HASH (rawhash, name[i]);
170 for (setlist = current_variable_set_list;
171 setlist != 0; setlist = setlist->next)
173 register struct variable_set *set = setlist->set;
174 register unsigned int hashval = rawhash % set->buckets;
175 register struct variable *v;
177 for (v = set->table[hashval]; v != 0; v = v->next)
178 if (*v->name == *name
179 && !strncmp (v->name + 1, name + 1, length - 1)
180 && v->name[length] == 0)
181 return v;
184 return 0;
187 /* Initialize FILE's variable set list. If FILE already has a variable set
188 list, the topmost variable set is left intact, but the the rest of the
189 chain is replaced with FILE->parent's setlist. */
191 void
192 initialize_file_variables (file)
193 struct file *file;
195 register struct variable_set_list *l = file->variables;
196 if (l == 0)
198 l = (struct variable_set_list *)
199 xmalloc (sizeof (struct variable_set_list));
200 l->set = (struct variable_set *) xmalloc (sizeof (struct variable_set));
201 l->set->buckets = PERFILE_VARIABLE_BUCKETS;
202 l->set->table = (struct variable **)
203 xmalloc (l->set->buckets * sizeof (struct variable *));
204 bzero ((char *) l->set->table,
205 l->set->buckets * sizeof (struct variable *));
206 file->variables = l;
209 if (file->parent == 0)
210 l->next = &global_setlist;
211 else
213 if (file->parent->variables == 0)
214 initialize_file_variables (file->parent);
215 l->next = file->parent->variables;
219 /* Pop the top set off the current variable set list,
220 and free all its storage. */
222 void
223 pop_variable_scope ()
225 register struct variable_set_list *setlist = current_variable_set_list;
226 register struct variable_set *set = setlist->set;
227 register unsigned int i;
229 current_variable_set_list = setlist->next;
230 free ((char *) setlist);
232 for (i = 0; i < set->buckets; ++i)
234 register struct variable *next = set->table[i];
235 while (next != 0)
237 register struct variable *v = next;
238 next = v->next;
240 free (v->name);
241 free ((char *) v);
244 free ((char *) set->table);
245 free ((char *) set);
248 /* Create a new variable set and push it on the current setlist. */
250 void
251 push_new_variable_scope ()
253 register struct variable_set_list *setlist;
254 register struct variable_set *set;
256 set = (struct variable_set *) xmalloc (sizeof (struct variable_set));
257 set->buckets = SMALL_SCOPE_VARIABLE_BUCKETS;
258 set->table = (struct variable **)
259 xmalloc (set->buckets * sizeof (struct variable *));
260 bzero ((char *) set->table, set->buckets * sizeof (struct variable *));
262 setlist = (struct variable_set_list *)
263 xmalloc (sizeof (struct variable_set_list));
264 setlist->set = set;
265 setlist->next = current_variable_set_list;
266 current_variable_set_list = setlist;
269 /* Merge SET1 into SET0, freeing unused storage in SET1. */
271 static void
272 merge_variable_sets (set0, set1)
273 struct variable_set *set0, *set1;
275 register unsigned int bucket1;
277 for (bucket1 = 0; bucket1 < set1->buckets; ++bucket1)
279 register struct variable *v1 = set1->table[bucket1];
280 while (v1 != 0)
282 struct variable *next = v1->next;
283 unsigned int bucket0;
284 register struct variable *v0;
286 if (set1->buckets >= set0->buckets)
287 bucket0 = bucket1;
288 else
290 register char *n;
291 bucket0 = 0;
292 for (n = v1->name; *n != '\0'; ++n)
293 HASH (bucket0, *n);
295 bucket0 %= set0->buckets;
297 for (v0 = set0->table[bucket0]; v0 != 0; v0 = v0->next)
298 if (streq (v0->name, v1->name))
299 break;
301 if (v0 == 0)
303 /* There is no variable in SET0 with the same name. */
304 v1->next = set0->table[bucket0];
305 set0->table[bucket0] = v1;
307 else
309 /* The same variable exists in both sets.
310 SET0 takes precedence. */
311 free (v1->value);
312 free ((char *) v1);
315 v1 = next;
320 /* Merge SETLIST1 into SETLIST0, freeing unused storage in SETLIST1. */
322 void
323 merge_variable_set_lists (setlist0, setlist1)
324 struct variable_set_list **setlist0, *setlist1;
326 register struct variable_set_list *list0 = *setlist0;
327 struct variable_set_list *last0 = 0;
329 while (setlist1 != 0 && list0 != 0)
331 struct variable_set_list *next = setlist1;
332 setlist1 = setlist1->next;
334 merge_variable_sets (list0->set, next->set);
336 free ((char *) next);
338 last0 = list0;
339 list0 = list0->next;
342 if (setlist1 != 0)
344 if (last0 == 0)
345 *setlist0 = setlist1;
346 else
347 last0->next = setlist1;
351 /* Define the automatic variables, and record the addresses
352 of their structures so we can change their values quickly. */
354 void
355 define_automatic_variables ()
357 #ifdef WIN32
358 extern char* default_shell;
359 #else
360 extern char default_shell[];
361 #endif
362 register struct variable *v;
363 char buf[200];
365 sprintf (buf, "%u", makelevel);
366 (void) define_variable ("MAKELEVEL", 9, buf, o_env, 0);
368 sprintf (buf, "%s%s%s",
369 version_string,
370 (remote_description == 0 || remote_description[0] == '\0')
371 ? "" : "-",
372 (remote_description == 0 || remote_description[0] == '\0')
373 ? "" : remote_description);
374 (void) define_variable ("MAKE_VERSION", 12, buf, o_default, 0);
377 /* This won't override any definition, but it
378 will provide one if there isn't one there. */
379 v = define_variable ("SHELL", 5, default_shell, o_default, 0);
380 v->export = v_export; /* Always export SHELL. */
382 /* Don't let SHELL come from the environment. */
383 if (*v->value == '\0' || v->origin == o_env || v->origin == o_env_override)
385 free (v->value);
386 v->origin = o_file;
387 v->value = savestring (default_shell, strlen (default_shell));
390 /* Make sure MAKEFILES gets exported if it is set. */
391 v = define_variable ("MAKEFILES", 9, "", o_default, 0);
392 v->export = v_ifset;
394 /* Define the magic D and F variables in terms of
395 the automatic variables they are variations of. */
397 define_variable ("@D", 2, "$(patsubst %/,%,$(dir $@))", o_automatic, 1);
398 define_variable ("%D", 2, "$(patsubst %/,%,$(dir $%))", o_automatic, 1);
399 define_variable ("*D", 2, "$(patsubst %/,%,$(dir $*))", o_automatic, 1);
400 define_variable ("<D", 2, "$(patsubst %/,%,$(dir $<))", o_automatic, 1);
401 define_variable ("?D", 2, "$(patsubst %/,%,$(dir $?))", o_automatic, 1);
402 define_variable ("^D", 2, "$(patsubst %/,%,$(dir $^))", o_automatic, 1);
403 define_variable ("+D", 2, "$(patsubst %/,%,$(dir $+))", o_automatic, 1);
404 define_variable ("@F", 2, "$(notdir $@)", o_automatic, 1);
405 define_variable ("%F", 2, "$(notdir $%)", o_automatic, 1);
406 define_variable ("*F", 2, "$(notdir $*)", o_automatic, 1);
407 define_variable ("<F", 2, "$(notdir $<)", o_automatic, 1);
408 define_variable ("?F", 2, "$(notdir $?)", o_automatic, 1);
409 define_variable ("^F", 2, "$(notdir $^)", o_automatic, 1);
410 define_variable ("+F", 2, "$(notdir $+)", o_automatic, 1);
413 int export_all_variables;
415 /* Create a new environment for FILE's commands.
416 If FILE is nil, this is for the `shell' function.
417 The child's MAKELEVEL variable is incremented. */
419 char **
420 target_environment (file)
421 struct file *file;
423 struct variable_set_list *set_list;
424 register struct variable_set_list *s;
425 struct variable_bucket
427 struct variable_bucket *next;
428 struct variable *variable;
430 struct variable_bucket **table;
431 unsigned int buckets;
432 register unsigned int i;
433 register unsigned nvariables;
434 char **result;
435 unsigned int mklev_hash;
437 if (file == 0)
438 set_list = current_variable_set_list;
439 else
440 set_list = file->variables;
442 /* Find the lowest number of buckets in any set in the list. */
443 s = set_list;
444 buckets = s->set->buckets;
445 for (s = s->next; s != 0; s = s->next)
446 if (s->set->buckets < buckets)
447 buckets = s->set->buckets;
449 /* Find the hash value of the bucket `MAKELEVEL' will fall into. */
451 char *p = "MAKELEVEL";
452 mklev_hash = 0;
453 while (*p != '\0')
454 HASH (mklev_hash, *p++);
457 /* Temporarily allocate a table with that many buckets. */
458 table = (struct variable_bucket **)
459 alloca (buckets * sizeof (struct variable_bucket *));
460 bzero ((char *) table, buckets * sizeof (struct variable_bucket *));
462 /* Run through all the variable sets in the list,
463 accumulating variables in TABLE. */
464 nvariables = 0;
465 for (s = set_list; s != 0; s = s->next)
467 register struct variable_set *set = s->set;
468 for (i = 0; i < set->buckets; ++i)
470 register struct variable *v;
471 for (v = set->table[i]; v != 0; v = v->next)
473 unsigned int j = i % buckets;
474 register struct variable_bucket *ov;
475 register char *p = v->name;
477 if (i == mklev_hash % set->buckets
478 && streq (v->name, "MAKELEVEL"))
479 /* Don't include MAKELEVEL because it will be
480 added specially at the end. */
481 continue;
483 switch (v->export)
485 case v_default:
486 if (v->origin == o_default || v->origin == o_automatic)
487 /* Only export default variables by explicit request. */
488 continue;
490 if (! export_all_variables
491 && v->origin != o_command
492 && v->origin != o_env && v->origin != o_env_override)
493 continue;
495 if (*p != '_' && (*p < 'A' || *p > 'Z')
496 && (*p < 'a' || *p > 'z'))
497 continue;
498 for (++p; *p != '\0'; ++p)
499 if (*p != '_' && (*p < 'a' || *p > 'z')
500 && (*p < 'A' || *p > 'Z') && (*p < '0' || *p > '9'))
501 break;
502 if (*p != '\0')
503 continue;
505 case v_export:
506 break;
508 case v_noexport:
509 continue;
511 case v_ifset:
512 if (v->origin == o_default)
513 continue;
514 break;
517 for (ov = table[j]; ov != 0; ov = ov->next)
518 if (streq (v->name, ov->variable->name))
519 break;
520 if (ov == 0)
522 register struct variable_bucket *entry;
523 entry = (struct variable_bucket *)
524 alloca (sizeof (struct variable_bucket));
525 entry->next = table[j];
526 entry->variable = v;
527 table[j] = entry;
528 ++nvariables;
534 result = (char **) xmalloc ((nvariables + 2) * sizeof (char *));
535 nvariables = 0;
536 for (i = 0; i < buckets; ++i)
538 register struct variable_bucket *b;
539 for (b = table[i]; b != 0; b = b->next)
541 register struct variable *v = b->variable;
542 /* If V is recursively expanded and didn't come from the environment,
543 expand its value. If it came from the environment, it should
544 go back into the environment unchanged. */
545 if (v->recursive
546 && v->origin != o_env && v->origin != o_env_override)
548 char *value = recursively_expand (v);
549 #ifdef WIN32
550 if (strcmp(v->name, "Path") == 0 ||
551 strcmp(v->name, "PATH") == 0)
552 convert_Path_to_win32(value, ';');
553 #endif
554 result[nvariables++] = concat (v->name, "=", value);
555 free (value);
557 else
558 #ifdef WIN32
560 if (strcmp(v->name, "Path") == 0 ||
561 strcmp(v->name, "PATH") == 0)
562 convert_Path_to_win32(v->value, ';');
563 result[nvariables++] = concat (v->name, "=", v->value);
565 #else
566 result[nvariables++] = concat (v->name, "=", v->value);
567 #endif
570 result[nvariables] = (char *) xmalloc (100);
571 (void) sprintf (result[nvariables], "MAKELEVEL=%u", makelevel + 1);
572 result[++nvariables] = 0;
574 return result;
577 /* Try to interpret LINE (a null-terminated string) as a variable definition.
579 ORIGIN may be o_file, o_override, o_env, o_env_override,
580 or o_command specifying that the variable definition comes
581 from a makefile, an override directive, the environment with
582 or without the -e switch, or the command line.
584 A variable definition has the form "name = value" or "name := value".
585 Any whitespace around the "=" or ":=" is removed. The first form
586 defines a variable that is recursively re-evaluated. The second form
587 defines a variable whose value is variable-expanded at the time of
588 definition and then is evaluated only once at the time of expansion.
590 If a variable was defined, a pointer to its `struct variable' is returned.
591 If not, NULL is returned. */
593 struct variable *
594 try_variable_definition (filename, lineno, line, origin)
595 char *filename;
596 unsigned int lineno;
597 char *line;
598 enum variable_origin origin;
600 register int c;
601 register char *p = line;
602 register char *beg;
603 register char *end;
604 enum { bogus, simple, recursive, append } flavor = bogus;
605 char *name, *expanded_name, *value;
606 struct variable *v;
608 while (1)
610 c = *p++;
611 if (c == '\0' || c == '#')
612 return 0;
613 if (c == '=')
615 end = p - 1;
616 flavor = recursive;
617 break;
619 else if (c == ':')
620 if (*p == '=')
622 end = p++ - 1;
623 flavor = simple;
624 break;
626 else
627 /* A colon other than := is a rule line, not a variable defn. */
628 return 0;
629 else if (c == '+' && *p == '=')
631 end = p++ - 1;
632 flavor = append;
633 break;
635 else if (c == '$')
637 /* This might begin a variable expansion reference. Make sure we
638 don't misrecognize chars inside the reference as =, := or +=. */
639 char closeparen;
640 int count;
641 c = *p++;
642 if (c == '(')
643 closeparen = ')';
644 else if (c == '{')
645 closeparen = '}';
646 else
647 continue; /* Nope. */
649 /* P now points past the opening paren or brace.
650 Count parens or braces until it is matched. */
651 count = 0;
652 for (; *p != '\0'; ++p)
654 if (*p == c)
655 ++count;
656 else if (*p == closeparen && --count < 0)
658 ++p;
659 break;
665 beg = next_token (line);
666 while (end > beg && isblank (end[-1]))
667 --end;
668 p = next_token (p);
670 /* Expand the name, so "$(foo)bar = baz" works. */
671 name = (char *) alloca (end - beg + 1);
672 bcopy (beg, name, end - beg);
673 name[end - beg] = '\0';
674 expanded_name = allocated_variable_expand (name);
676 if (expanded_name[0] == '\0')
678 if (filename == 0)
679 fatal ("empty variable name");
680 else
681 makefile_fatal (filename, lineno, "empty variable name");
684 /* Calculate the variable's new value in VALUE. */
686 switch (flavor)
688 case bogus:
689 /* Should not be possible. */
690 abort ();
691 return 0;
692 case simple:
693 /* A simple variable definition "var := value". Expand the value. */
694 value = variable_expand (p);
695 break;
696 case recursive:
697 /* A recursive variable definition "var = value".
698 The value is used verbatim. */
699 value = p;
700 break;
701 case append:
702 /* An appending variable definition "var += value".
703 Extract the old value and append the new one. */
704 v = lookup_variable (expanded_name, strlen (expanded_name));
705 if (v == 0)
707 /* There was no old value.
708 This becomes a normal recursive definition. */
709 value = p;
710 flavor = recursive;
712 else
714 /* Paste the old and new values together in VALUE. */
716 unsigned int oldlen, newlen;
718 if (v->recursive)
719 /* The previous definition of the variable was recursive.
720 The new value comes from the unexpanded old and new values. */
721 flavor = recursive;
722 else
723 /* The previous definition of the variable was simple.
724 The new value comes from the old value, which was expanded
725 when it was set; and from the expanded new value. */
726 p = variable_expand (p);
728 oldlen = strlen (v->value);
729 newlen = strlen (p);
730 value = (char *) alloca (oldlen + 1 + newlen + 1);
731 bcopy (v->value, value, oldlen);
732 value[oldlen] = ' ';
733 bcopy (p, &value[oldlen + 1], newlen + 1);
737 v = define_variable (expanded_name, strlen (expanded_name),
738 value, origin, flavor == recursive);
740 free (expanded_name);
742 return v;
745 /* Print information for variable V, prefixing it with PREFIX. */
747 static void
748 print_variable (v, prefix)
749 register struct variable *v;
750 char *prefix;
752 char *origin;
754 switch (v->origin)
756 case o_default:
757 origin = "default";
758 break;
759 case o_env:
760 origin = "environment";
761 break;
762 case o_file:
763 origin = "makefile";
764 break;
765 case o_env_override:
766 origin = "environment under -e";
767 break;
768 case o_command:
769 origin = "command line";
770 break;
771 case o_override:
772 origin = "`override' directive";
773 break;
774 case o_automatic:
775 origin = "automatic";
776 break;
777 case o_invalid:
778 default:
779 abort ();
780 break;
782 printf ("# %s\n", origin);
784 fputs (prefix, stdout);
786 /* Is this a `define'? */
787 if (v->recursive && index (v->value, '\n') != 0)
788 printf ("define %s\n%s\nendef\n", v->name, v->value);
789 else
791 register char *p;
793 printf ("%s %s= ", v->name, v->recursive ? "" : ":");
795 /* Check if the value is just whitespace. */
796 p = next_token (v->value);
797 if (p != v->value && *p == '\0')
798 /* All whitespace. */
799 printf ("$(subst ,,%s)", v->value);
800 else if (v->recursive)
801 fputs (v->value, stdout);
802 else
803 /* Double up dollar signs. */
804 for (p = v->value; *p != '\0'; ++p)
806 if (*p == '$')
807 putchar ('$');
808 putchar (*p);
810 putchar ('\n');
815 /* Print all the variables in SET. PREFIX is printed before
816 the actual variable definitions (everything else is comments). */
818 static void
819 print_variable_set (set, prefix)
820 register struct variable_set *set;
821 char *prefix;
823 register unsigned int i, nvariables, per_bucket;
824 register struct variable *v;
826 per_bucket = nvariables = 0;
827 for (i = 0; i < set->buckets; ++i)
829 register unsigned int this_bucket = 0;
831 for (v = set->table[i]; v != 0; v = v->next)
833 ++this_bucket;
834 print_variable (v, prefix);
837 nvariables += this_bucket;
838 if (this_bucket > per_bucket)
839 per_bucket = this_bucket;
842 if (nvariables == 0)
843 puts ("# No variables.");
844 else
846 printf ("# %u variables in %u hash buckets.\n",
847 nvariables, set->buckets);
848 #ifndef NO_FLOAT
849 printf ("# average of %.1f variables per bucket, \
850 max %u in one bucket.\n",
851 (double) nvariables / (double) set->buckets,
852 per_bucket);
853 #else
855 int f = (nvariables * 1000 + 5) / set->buckets;
856 printf ("# average of %d.%d variables per bucket, \
857 max %u in one bucket.\n",
858 f/10, f%10,
859 per_bucket);
861 #endif
866 /* Print the data base of variables. */
868 void
869 print_variable_data_base ()
871 puts ("\n# Variables\n");
873 print_variable_set (&global_variable_set, "");
877 /* Print all the local variables of FILE. */
879 void
880 print_file_variables (file)
881 struct file *file;
883 if (file->variables != 0)
884 print_variable_set (file->variables->set, "# ");
887 #ifdef WIN32
888 void
889 sync_Path_environment(void)
891 char* path = allocated_variable_expand("$(Path)");
892 static char* environ_path = NULL;
894 if (!path)
895 return;
898 * If done this before, don't leak memory unnecessarily.
899 * Free the previous entry before allocating new one.
901 if (environ_path)
902 free(environ_path);
905 * Create something WIN32 world can grok
907 convert_Path_to_win32(path, ';');
908 environ_path = concat("Path", "=", path);
909 putenv(environ_path);
910 free(path);
912 #endif