[pypy-svn] r33220 - pypy/dist/pypy/translator/cli/src
antocuni at codespeak.net
antocuni at codespeak.net
Thu Oct 12 12:27:52 CEST 2006
Author: antocuni
Date: Thu Oct 12 12:27:51 2006
New Revision: 33220
Modified:
pypy/dist/pypy/translator/cli/src/ll_os.cs
Log:
Added support for getting/setting environment variables.
Modified: pypy/dist/pypy/translator/cli/src/ll_os.cs
==============================================================================
--- pypy/dist/pypy/translator/cli/src/ll_os.cs (original)
+++ pypy/dist/pypy/translator/cli/src/ll_os.cs Thu Oct 12 12:27:51 2006
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using pypy.runtime;
@@ -144,6 +145,7 @@
private static Dictionary<int, IFile> FileDescriptors;
private static int fdcount;
private static Dictionary<int, string> ErrorMessages;
+ private static SortedList MyEnviron;
// NB: these values are those used by Windows and they differs
// from the Unix ones; the os module is patched with these
@@ -165,6 +167,8 @@
static ll_os()
{
ErrorMessages = new Dictionary<int, string>();
+ MyEnviron = new SortedList(Environment.GetEnvironmentVariables());
+
FileDescriptors = new Dictionary<int, IFile>();
// XXX: what about CRLF conversion for stdin, stdout and stderr?
// It seems that Posix let you read from stdout and
@@ -325,14 +329,28 @@
return ll_os_stat(path); // TODO
}
+ public static void ll_os_unlink(string path)
+ {
+ File.Delete(path);
+ }
+
public static string ll_os_environ(int index)
{
- return null; // TODO
+ string key = (string)MyEnviron.GetKey(index);
+ string value = (string)MyEnviron.GetByIndex(index);
+ return string.Format("{0}={1}", key, value);
}
- public static void ll_os_unlink(string path)
+ public static void ll_os_putenv(string s)
{
- File.Delete(path);
+ char[] delim = {'='};
+ string[] parts = s.Split(delim, 2);
+ Environment.SetEnvironmentVariable(parts[0], parts[1]);
+ }
+
+ public static void ll_os_unsetenv(string s)
+ {
+ Environment.SetEnvironmentVariable(s, null);
}
public static long ll_os_lseek(int fd, int offset, int whence)
@@ -450,11 +468,6 @@
return null;
}
- public static void ll_os_putenv(string s)
- {
- Helpers.raise_OSError(Errno.EPERM); // this is only a stub
- }
-
public static string ll_os_readlink(string s)
{
Helpers.raise_OSError(Errno.EPERM); // this is only a stub
@@ -482,11 +495,6 @@
return -1;
}
- public static void ll_os_unsetenv(string s)
- {
- Helpers.raise_OSError(Errno.EPERM); // this is only a stub
- }
-
public static Record_Signed_Signed ll_os_waitpid(int x, int y)
{
Helpers.raise_OSError(Errno.EPERM); // this is only a stub
More information about the Pypy-commit
mailing list