mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-11-11 02:01:36 +03:00
Handle overwrite on windows
Expand test to test overwrite
This commit is contained in:
parent
8633dde240
commit
8540728202
@ -77,7 +77,7 @@ char* idris2_getEnvPair(int i) {
|
||||
|
||||
int idris2_setenv(const char *name, const char *value, int overwrite) {
|
||||
#ifdef _WIN32
|
||||
return win32_modenv(name, value);
|
||||
return win32_modenv(name, value, overwrite);
|
||||
#else
|
||||
return setenv(name, value, overwrite);
|
||||
#endif
|
||||
@ -85,7 +85,7 @@ int idris2_setenv(const char *name, const char *value, int overwrite) {
|
||||
|
||||
int idris2_unsetenv(const char *name) {
|
||||
#ifdef _WIN32
|
||||
return win32_modenv(name, "");
|
||||
return win32_modenv(name, "", 1);
|
||||
#else
|
||||
return unsetenv(name);
|
||||
#endif
|
||||
|
@ -74,8 +74,9 @@ void win32_sleep(int ms) {
|
||||
Sleep(ms);
|
||||
}
|
||||
|
||||
int win32_modenv(const char* name, const char* value) {
|
||||
int win32_modenv(const char* name, const char* value, int overwrite) {
|
||||
char buffer[2000];
|
||||
if (!overwrite && getenv(name)) return -1;
|
||||
if (strlen(name) + strlen(value) > 1998) return -1;
|
||||
sprintf(buffer, "%s=%s", name, value);
|
||||
return putenv(buffer);
|
||||
|
@ -8,4 +8,4 @@ FILE *win32_u8fopen(const char *path, const char *mode);
|
||||
FILE *win32_u8popen(const char *path, const char *mode);
|
||||
void win32_gettime(int64_t* sec, int64_t* nsec);
|
||||
void win32_sleep(int ms);
|
||||
int win32_modenv(const char* name, const char* value);
|
||||
int win32_modenv(const char* name, const char* value, int overwrite);
|
||||
|
@ -4,11 +4,15 @@ import System
|
||||
|
||||
main : IO ()
|
||||
main = do
|
||||
ok <- setEnv "HELLO" "HI" True
|
||||
ok <- setEnv "HELLO" "HI" False
|
||||
printLn ok
|
||||
Just str <- getEnv "HELLO"
|
||||
| Nothing => pure ()
|
||||
putStrLn str
|
||||
ok <- setEnv "HELLO" "HO" False
|
||||
printLn ok
|
||||
ok <- setEnv "HELLO" "EH" True
|
||||
printLn ok
|
||||
ok <- unsetEnv "HELLO"
|
||||
printLn ok
|
||||
Just str <- getEnv "HELLO"
|
||||
|
@ -1,5 +1,7 @@
|
||||
True
|
||||
HI
|
||||
False
|
||||
True
|
||||
True
|
||||
Nothing there
|
||||
1/1: Building Envy (Envy.idr)
|
||||
|
Loading…
Reference in New Issue
Block a user