Example #1
0
/* void _sys_msg(const char *s)
{ 
    if ((stderr->_flag & _IOWRITE) && !_error_recursion)
    {   _error_recursion = 1;
        fprintf(stderr, "\n%s\n", s);
        _error_recursion = 0;
    }
    else
    {   _ttywrite((unsigned char *)"\n", 1, 0);
        _ttywrite((unsigned char *)s, strlen(s), 0);
        _ttywrite((unsigned char *)"\n", 1, 0);
    }
}
*/
int _sys_read_(FILEHANDLE fh, unsigned char *buf, int len, int mode)
{
  int n = _syscall3(SYS_read, (int)fh, (int)buf, (int)len);
  if (n==-1) {			/* error condition */
    n=0;
  }
  n = len - n;			/* number of bytes NOT read */
  if (n!=0) n |= 0x80000000;
  return n;
}
Example #2
0
FILEHANDLE _sys_open(const char *filename, int openmode)
{   /* nasty magic number interface for openmode */
    static int modtab[6] = { /* r = */  O_RDONLY,
			     /* r+ = */ O_RDWR,
                             /* w = */  O_WRONLY|O_CREAT|O_TRUNC,
			     /* w+ = */ O_RDWR  |O_TRUNC|O_CREAT,
                             /* a = */  O_WRONLY|O_CREAT,
			     /* a+ = */ O_RDWR  |O_CREAT|O_APPEND };
    char *name = (char *)filename;            /* yuk */
    FILEHANDLE fh;
    openmode = modtab[openmode >> 1];         /* forget the 'b'inary bit */
    fh = _syscall3(SYS_open, (int)name, openmode, 0666);
    if (fh<0) return NONHANDLE;            /* not found             */
    return fh;
}
Example #3
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);
    }
  }
}
Example #4
0
//从文件描述符fd中读取count个字节到buf
int32_t read(int32_t fd,void* buf,uint32_t count){
	return _syscall3(SYS_READ,fd,buf,count);
}
Example #5
0
//将buf中count个字符写入文件描述符fd中
uint32_t write(int32_t fd,const void* buf,uint32_t count){
	return _syscall3(SYS_WRITE,fd,buf,count);
}
Example #6
0
/* 设置文件偏移量 */
int32_t lseek(int32_t fd, int32_t offset, uint8_t whence) {
	   return _syscall3(SYS_LSEEK, fd, offset, whence);
}