Skip to content

Commit 795a6aa

Browse files
committed
Added clearenv polyfill
1 parent d4056f9 commit 795a6aa

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

osfixes.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
11
#include "osfixes.h"
2+
#define _CRTIMP
23
#define WIN32_LEAN_AND_MEAN
34
#define _GL_CTYPE_H
45
#define _GL_CONFIG_H_INCLUDED 1
56
#include <windows.h>
67
#ifdef WLB_INCL_WLB_DEBUG_H
78
#include "wlb_debug.h"
89
#endif
10+
#ifndef MAX_LONG_PATH
11+
#define MAX_LONG_PATH 32768
12+
#endif // !MAX_LONG_PATH
13+
914

1015
// #include "term.h"
1116
// #include "general.h"
12-
17+
#include <../ucrt/stdlib.h>
1318
#include <../ucrt/stdio.h>
1419
#ifndef TRUE
1520
#define FALSE 0
1621
#define TRUE 1
1722
#endif // !FALSE
1823

24+
int clearenv(void)
25+
{
26+
char* envp, * s;
27+
char name[MAX_LONG_PATH];
28+
29+
30+
while (environ && (envp = *environ)) {
31+
if ((s = strchr(envp, '=')) != NULL) {
32+
strncpy(name, envp, s - envp + 1);
33+
strncpy_s(name, sizeof(name), envp, s - envp+1);
34+
name[s - envp + 1+1] = 0;
35+
36+
if (_putenv(name) == -1) {
37+
return -1;
38+
}
39+
}
40+
else {
41+
return -1;
42+
}
43+
}
44+
return 0;
45+
}
1946
#if defined (WLB_DISABLE_DEBUG_ASSERT_POPUP_AT_EXIT) || defined(WLB_DISABLE_DEBUG_ASSERT_POPUP_AT_LAUNCH)
2047
#if !defined(DisableDebugAssertPopup)
2148

osfixes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define WLB_DISABLE_DEBUG_ASSERT_POPUP_AT_LAUNCH
1616
#define WLB_CONSTRUCTOR_SUPPORT
1717
*/
18+
int clearenv(void);
1819
extern void DisableDebugAssertAtExit();
1920
#if (defined(WLB_DISABLE_DEBUG_ASSERT_POPUP_AT_LAUNCH) || defined(WLB_DISABLE_DEBUG_ASSERT_POPUP_AT_EXIT)) && ! defined(WLB_CONSTRUCTOR_SUPPORT)
2021
#define WLB_CONSTRUCTOR_SUPPORT

0 commit comments

Comments
 (0)