Implemented _exit().

Added empty implementations of fork() and all the exec*() variants; the
latter currently all call execve() and may pass the correct parameters
(not tested).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8339 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-07-07 12:28:22 +00:00
parent 007a64beef
commit aa1ea490d0
4 changed files with 202 additions and 0 deletions

View File

@ -7,7 +7,10 @@ KernelMergeObject posix_unistd.o :
<$(SOURCE_GRIST)>conf.c
<$(SOURCE_GRIST)>directory.c
<$(SOURCE_GRIST)>dup.c
<$(SOURCE_GRIST)>exec.c
<$(SOURCE_GRIST)>_exit.c
<$(SOURCE_GRIST)>fcntl.c
<$(SOURCE_GRIST)>fork.c
<$(SOURCE_GRIST)>getopt.c
<$(SOURCE_GRIST)>hostname.c
<$(SOURCE_GRIST)>ioctl.c

View File

@ -0,0 +1,23 @@
/*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#include <unistd.h>
#include <syscalls.h>
extern void (*_IO_cleanup)(void);
void
_exit(int status)
{
// close all open files
_IO_cleanup();
// exit with status code
_kern_exit(status);
}

View File

@ -0,0 +1,154 @@
/*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#include <syscalls.h>
#include <unistd.h>
#include <errno.h>
#include <alloca.h>
#include <stdio.h>
#include <stdarg.h>
static int
count_arguments(va_list list, const char *arg, char ***_env)
{
int count = 0;
while (arg != NULL) {
count++;
arg = va_arg(list, const char *);
}
if (_env)
*_env = va_arg(list, char **);
return count;
}
static void
copy_arguments(va_list list, const char **args, const char *arg)
{
int count = 0;
while (arg != NULL) {
arg = va_arg(list, const char *);
args[count++] = arg;
}
args[count] = NULL;
// terminate list
}
// #pragma mark -
int
execve(const char *path, char * const argv[], char * const envp[])
{
// ToDo: implement me for real!
fprintf(stderr, "execve(): NOT IMPLEMENTED\n");
return -1;
}
int
execv(const char *path, char * const *argv)
{
return execve(path, argv, environ);
}
int
execvp(const char *file, char * const *argv)
{
// ToDo: do the "p" thing
return execve(file, argv, environ);
}
int
execl(const char *path, const char *arg, ...)
{
const char **args;
va_list list;
int count;
// count arguments
va_start(list, arg);
count = count_arguments(list, arg, NULL);
va_end(list);
// copy arguments
args = alloca((count + 1) * sizeof(char *));
va_start(list, arg);
copy_arguments(list, args, arg);
va_end(list);
return execve(path, (char * const *)args, environ);
}
int
execlp(const char *file, const char *arg, ...)
{
const char **args;
va_list list;
int count;
// count arguments
va_start(list, arg);
count = count_arguments(list, arg, NULL);
va_end(list);
// copy arguments
args = alloca((count + 1) * sizeof(char *));
va_start(list, arg);
copy_arguments(list, args, arg);
va_end(list);
return execvp(file, (char * const *)args);
}
int
execle(const char *path, const char *arg, ... /*, char **env */)
{
const char **args;
char **env;
va_list list;
int count;
// count arguments
va_start(list, arg);
count = count_arguments(list, arg, &env);
va_end(list);
// copy arguments
args = alloca((count + 1) * sizeof(char *));
va_start(list, arg);
copy_arguments(list, args, arg);
va_end(list);
return execve(path, (char * const *)args, env);
}
int
exect(const char *path, char * const *argv)
{
// ToDo: is this any different?
return execv(path, argv);
}

View File

@ -0,0 +1,22 @@
/*
** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#include <syscalls.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
pid_t
fork(void)
{
// ToDo: implement me
// ToDo: atfork()
fprintf(stderr, "fork(): NOT IMPLEMENTED\n");
return -1;
}