Index: /trunk/src/kash/main.c
===================================================================
--- /trunk/src/kash/main.c	(revision 1228)
+++ /trunk/src/kash/main.c	(revision 1229)
@@ -450,5 +450,5 @@
 {
 	size_t len;
-	strip_argv0(argv0, &len);
+	argv0 = strip_argv0(argv0, &len);
 
 	fprintf(stdout,
Index: /trunk/src/kash/output.c
===================================================================
--- /trunk/src/kash/output.c	(revision 1228)
+++ /trunk/src/kash/output.c	(revision 1229)
@@ -109,4 +109,5 @@
 	file->fd = BLOCK_OUT;
 	file->flags = 0;
+	file->psh = psh;
 }
 #endif
Index: /trunk/src/kash/shinstance.c
===================================================================
--- /trunk/src/kash/shinstance.c	(revision 1228)
+++ /trunk/src/kash/shinstance.c	(revision 1229)
@@ -42,9 +42,7 @@
     shinstance *psh;
 
-    psh = malloc(sizeof(*psh));
+    psh = calloc(sizeof(*psh), 1);
     if (psh)
     {
-        memset(psh, 0, sizeof(*psh));
-
         /* memalloc.c */
         psh->stacknleft = MINSIZE;
@@ -61,7 +59,10 @@
         psh->output.bufsize = OUTBUFSIZ;
         psh->output.fd = 1;
+        psh->output.psh = psh;
         psh->errout.bufsize = 100;
         psh->errout.fd = 2;
+        psh->errout.psh = psh;
         psh->memout.fd = MEM_OUT;
+        psh->memout.psh = psh;
         psh->out1 = &psh->output;
         psh->out2 = &psh->errout;
@@ -81,21 +82,58 @@
 char *sh_getenv(shinstance *psh, const char *var)
 {
+#ifdef SH_PURE_STUB_MODE
     return NULL;
+#elif defined(SH_STUB_MODE)
+    return getenv(var);
+#else
+#endif
 }
 
 char **sh_environ(shinstance *psh)
 {
+#ifdef SH_PURE_STUB_MODE
     static char *s_null[2] = {0,0};
     return &s_null[0];
+#elif defined(SH_STUB_MODE)
+    return environ;
+#else
+#endif
 }
 
 const char *sh_gethomedir(shinstance *psh, const char *user)
 {
+#ifdef SH_PURE_STUB_MODE
     return NULL;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return NULL;
+# else
+    struct passwd *pwd = getpwnam(user);
+    return pwd ? pwd->pw_dir;
+# endif
+#else
+#endif
 }
 
 int sh_sigaction(int signo, const struct sh_sigaction *newp, struct sh_sigaction *oldp)
 {
-    return -1;
+#ifdef SH_PURE_STUB_MODE
+    return -1;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return -1;
+# else
+    struct sigaction old;
+    if (newp)
+        return -1;
+    if (sigaction(signo, NULL, &old))
+        return -1;
+    oldp->sh_flags = old.sa_flags;
+    oldp->sh_handler = old.sa_handler;
+    oldp->sh_mask = old.sa_mask;
+    return 0;
+# endif
+#else
+#endif
 }
 
@@ -112,5 +150,5 @@
 void sh_sigemptyset(sh_sigset_t *setp)
 {
-
+    memset(setp, 0, sizeof(*setp));
 }
 
@@ -122,108 +160,293 @@
 void sh_abort(shinstance *psh)
 {
+#ifdef SH_PURE_STUB_MODE
+#elif defined(SH_STUB_MODE)
+    abort();
+#else
+#endif
 }
 
 void sh_raise_sigint(shinstance *psh)
 {
-
+#ifdef SH_PURE_STUB_MODE
+#elif defined(SH_STUB_MODE)
+    raise(SIGINT);
+#else
+#endif
 }
 
 int sh_kill(shinstance *psh, pid_t pid, int signo)
 {
-    return -1;
+#ifdef SH_PURE_STUB_MODE
+    return -1;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return -1;
+# else
+    return kill(pid, signo);
+# endif
+#else
+#endif
 }
 
 int sh_killpg(shinstance *psh, pid_t pgid, int signo)
 {
-    return -1;
+#ifdef SH_PURE_STUB_MODE
+    return -1;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return -1;
+# else
+    return killpg(pgid, signo);
+# endif
+#else
+#endif
 }
 
 clock_t sh_times(shinstance *psh, shtms *tmsp)
 {
-    return 0;
+#ifdef SH_PURE_STUB_MODE
+    return 0;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return 0;
+# else
+    return times(tmsp);
+# endif
+#else
+#endif
 }
 
 int sh_sysconf_clk_tck(void)
 {
+#ifdef SH_PURE_STUB_MODE
     return 1;
+#else
+# ifdef _MSC_VER
+    return CLK_TCK;
+# else
+    return sysconf(_SC_CLK_TCK)
+# endif
+#endif
 }
 
 pid_t sh_fork(shinstance *psh)
 {
-    return -1;
+#ifdef SH_PURE_STUB_MODE
+    return -1;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return -1;
+# else
+    return fork();
+# endif
+#else
+#endif
 }
 
 pid_t sh_waitpid(shinstance *psh, pid_t pid, int *statusp, int flags)
 {
-    return -1;
+#ifdef SH_PURE_STUB_MODE
+    return -1;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return -1;
+# else
+    return waitpid(pid, statusp, flags);
+# endif
+#else
+#endif
 }
 
 void sh__exit(shinstance *psh, int rc)
 {
+#ifdef SH_PURE_STUB_MODE
+    return -1;
+#elif defined(SH_STUB_MODE)
+    _exit(rc);
+#else
+#endif
 }
 
 int sh_execve(shinstance *psh, const char *exe, const char * const *argv, const char * const *envp)
 {
-    return -1;
+#ifdef SH_PURE_STUB_MODE
+    return -1;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return -1;
+# else
+    return execve(exe, (char **)argv, (char **)envp);
+# endif
+#else
+#endif
 }
 
 uid_t sh_getuid(shinstance *psh)
 {
-    return 0;
+#ifdef SH_PURE_STUB_MODE
+    return 0;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return 0;
+# else
+    return getuid();
+# endif
+#else
+#endif
 }
 
 uid_t sh_geteuid(shinstance *psh)
 {
-    return 0;
+#ifdef SH_PURE_STUB_MODE
+    return 0;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return 0;
+# else
+    return geteuid();
+# endif
+#else
+#endif
 }
 
 gid_t sh_getgid(shinstance *psh)
 {
-    return 0;
+#ifdef SH_PURE_STUB_MODE
+    return 0;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return 0;
+# else
+    return getgid();
+# endif
+#else
+#endif
 }
 
 gid_t sh_getegid(shinstance *psh)
 {
-    return 0;
+#ifdef SH_PURE_STUB_MODE
+    return 0;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return 0;
+# else
+    return getegid();
+# endif
+#else
+#endif
 }
 
 pid_t sh_getpid(shinstance *psh)
 {
-    return 0;
+#ifdef SH_PURE_STUB_MODE
+    return 0;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return _getpid();
+# else
+    return getpid();
+# endif
+#else
+#endif
 }
 
 pid_t sh_getpgrp(shinstance *psh)
 {
-    return 0;
+#ifdef SH_PURE_STUB_MODE
+    return 0;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return _getpid();
+# else
+    return getpgrp();
+# endif
+#else
+#endif
 }
 
 pid_t sh_getpgid(shinstance *psh, pid_t pid)
 {
+#ifdef SH_PURE_STUB_MODE
     return pid;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return pid;
+# else
+    return getpgid(pid);
+# endif
+#else
+#endif
 }
 
 int sh_setpgid(shinstance *psh, pid_t pid, pid_t pgid)
 {
-    return -1;
+#ifdef SH_PURE_STUB_MODE
+    return -1;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return -1;
+# else
+    return setpgid(pid, pgid);
+# endif
+#else
+#endif
 }
 
 pid_t sh_tcgetpgrp(shinstance *psh, int fd)
 {
-    return -1;
+#ifdef SH_PURE_STUB_MODE
+    return -1;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return -1;
+# else
+    return tcgetpgrp(fd);
+# endif
+#else
+#endif
 }
 
 int sh_tcsetpgrp(shinstance *psh, int fd, pid_t pgrp)
 {
-    return -1;
+#ifdef SH_PURE_STUB_MODE
+    return -1;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return -1;
+# else
+    return tcsetpgrp(fd, pgrp);
+# endif
+#else
+#endif
 }
 
 int sh_getrlimit(shinstance *psh, int resid, shrlimit *limp)
 {
-    return -1;
+#ifdef SH_PURE_STUB_MODE
+    return -1;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return -1;
+# else
+    return getrlimit(resid, limp);
+# endif
+#else
+#endif
 }
 
 int sh_setrlimit(shinstance *psh, int resid, const shrlimit *limp)
 {
-    return -1;
-}
-
+#ifdef SH_PURE_STUB_MODE
+    return -1;
+#elif defined(SH_STUB_MODE)
+# ifdef _MSC_VER
+    return -1;
+# else
+    return setrlimit(resid, limp);
+# endif
+#else
+#endif
+}
+
Index: /trunk/src/kash/shinstance.h
===================================================================
--- /trunk/src/kash/shinstance.h	(revision 1228)
+++ /trunk/src/kash/shinstance.h	(revision 1229)
@@ -200,12 +200,11 @@
     int                 njobs;          /**< size of array */
     int                 jobs_invalid;   /**< set in child */
-#if JOBS
     int                 initialpgrp;    /**< pgrp of shell on invocation */
     int                 curjob/* = -1*/;/**< current job */
-#endif
     int                 ttyfd/* = -1*/;
     int                 jobctl;         /**< job control enabled / disabled */
     char               *cmdnextc;
     int                 cmdnleft;
+
 
     /* mail.c */
@@ -290,7 +289,5 @@
     /* var.h */
     struct localvar    *localvars;
-#if ATTY
     struct var          vatty;
-#endif
     struct var          vifs;
     struct var          vmail;
