Пример #1
0
int __init(int argc, char **argv)
{   int ans;
    _error_recursion = 0;
    _curbrk = &end;
    _ctype_init();		/* init to C locale */
    _init_alloc();
    _exit_init();           /* must happen before exit() can be called   */
    _initio(NULL, NULL, NULL);
    ans = main(argc, argv, _environ);
    while (number_of_exit_functions!=0)
      (*_exitvector[--number_of_exit_functions])();
    _terminateio();
    _syscall1(SYS_exit, ans);
}
Пример #2
0
extern int system(const char *string)
{
  int pid;
  void (*s2)(int);
  void (*s3)(int);
  if ((pid = _vfork()) == 0) {
    char *gv[4] = {"sh", "-c", (char*)0, (char*)0};
    gv[2] = (char *)string;
    _syscall3(SYS_execve, (int)"/bin/sh", (int)gv, (int)_environ);
    _syscall1(SYS_exit,127);			/* Should not get here!! */
  }
  s2 = signal(SIGINT, SIG_IGN);
  s3 = signal(SIGQUIT, SIG_IGN);
  while (1) {
    int status;
    int wp = _wait(&status);
    if (wp == pid || wp == -1) {
      signal(SIGINT,s2);
      signal(SIGQUIT,s3);
      return (wp == -1 ? -1 : status);
    }
  }
}
Пример #3
0
//等待子进程,子进程状态存储到status
pid_t wait(int32_t* status){
	return _syscall1(SYS_WAIT,status);
}
Пример #4
0
//以状态status退出
void exit(int32_t status){
	_syscall1(SYS_EXIT,status);
}
Пример #5
0
/* 改变工作目录为path */
int32_t chdir(const char* path) {
	   return _syscall1(SYS_CHDIR, path);
}
Пример #6
0
/* 回归目录指针 */
void rewinddir(struct dir* dir) {
	   _syscall1(SYS_REWINDDIR, dir);
}
Пример #7
0
/* 读取目录dir */
struct dir_entry* readdir(struct dir* dir) {
	   return (struct dir_entry*)_syscall1(SYS_READDIR, dir);
}
Пример #8
0
//释放ptr指向的内存
void free(void* ptr){
	_syscall1(SYS_FREE,ptr);
}
Пример #9
0
/* 打开目录name */
struct dir* opendir(const char* name) {
	   return (struct dir*)_syscall1(SYS_OPENDIR, name);
}
Пример #10
0
/* 创建目录pathname */
int32_t mkdir(const char* pathname) {
	   return _syscall1(SYS_MKDIR, pathname);
}
Пример #11
0
/* 删除文件pathname */
int32_t unlink(const char* pathname) {
	   return _syscall1(SYS_UNLINK, pathname);
}
Пример #12
0
/* 关闭文件fd */
int32_t close(int32_t fd) {
	   return _syscall1(SYS_CLOSE, fd);
}
Пример #13
0
uint32_t
wait(int* stat_loc)
{
    return _syscall1(SYS_WAIT, (uint32_t)stat_loc);
}
Пример #14
0
//生成管道,pipefd[0]负责读入管道,pipefd[1]负责写入管道
int32_t pipe(int32_t pipefd[2]){
	return _syscall1(SYS_PIPE,pipefd);
}
Пример #15
0
/* 关闭目录dir */
int32_t closedir(struct dir* dir) {
	   return _syscall1(SYS_CLOSEDIR, dir);
}
Пример #16
0
//申请size字节大小的内存,并返回结果
void *malloc(uint32_t size){
	return (void*)_syscall1(SYS_MALLOC,size);
}
Пример #17
0
/* 删除目录pathname */
int32_t rmdir(const char* pathname) {
	   return _syscall1(SYS_RMDIR, pathname);
}
Пример #18
0
//输出一个字符
void putchar(char char_asci){
	_syscall1(SYS_PUTCHAR,char_asci);
}
Пример #19
0
int remove(const char *pathname)
{
    return _syscall1(SYS_unlink,(int)pathname);
}