#include "locale.h"
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
int errno;
+static int at_exit_registered;
+#define REGISTER_AT_EXIT() \
+ do { \
+ if (!at_exit_registered) \
+ at_exit_registered = !atexit(cleanup_libc); \
+ } while(0)
+
+#define MAXENV 32
+static char *envnames[MAXENV];
+static char *envvars[MAXENV];
+
+static void cleanup_libc(void)
+{
+ int i;
+ for (i=0; i <MAXENV; i++) {
+ if (envnames[i])
+ free(envnames[i]);
+ if (envvars[i])
+ free(envvars[i]);
+ }
+}
+
char *
getenv(char *name)
{
- return 0;
+ int i;
+ REGISTER_AT_EXIT();
+ for (i=0; i < MAXENV; i++) {
+ if (envnames[i] && !strcmp(envnames[i], name))
+ return envvars[i];
+ }
+ return NULL;
}
-void
-setenv(void)
+int
+setenv(const char *name, const char *value, int overwrite)
+{
+ int i;
+ char *val;
+ REGISTER_AT_EXIT();
+ for (i=0; i < MAXENV; i++) {
+ if (envnames[i] && !strcmp(envnames[i], name)) {
+ if (overwrite) {
+ val = strdup(value);
+ if (!val)
+ return -1;
+ if (envvars[i])
+ free(envvars[i]);
+ envvars[i] = val;
+ }
+ return 0;
+ }
+ }
+ for (i=0; i < MAXENV; i++) {
+ if (!envnames[i]) {
+ envnames[i] = strdup(name);
+ envvars[i] = strdup(value);
+ if (!envnames[i] || !envvars[i]) {
+ if (envnames[i])
+ free(envnames[i]);
+ if (envvars[i])
+ free(envvars[i]);
+ envnames[i] = NULL;
+ envvars[i] = NULL;
+ return -1;
+ }
+ return 0;
+ }
+ }
+ return -1;
+}
+
+int unsetenv(const char *name)
{
+ int i;
+ for (i=0; i < MAXENV; i++) {
+ if (envnames[i] && !strcmp(envnames[i], name)) {
+ free(envnames[i]);
+ envnames[i] = NULL;
+ if (envvars[i])
+ free(envvars[i]);
+ envvars[i] = NULL;
+ }
+ }
+ return 0;
}
char *
-getcwd(void)
+getcwd(char *buf, int size)
{
return "dummy";
}
char *
-getwd(void)
+getwd(char *buf)
{
return "dummy";
}
}
void
-perror(char *x)
+perror(const char *x)
{
}