📄 ustdio.c
字号:
/* *---------------------------------------------------------------------- * T-Kernel / Standard Extension * * Copyright (C) 2006 by Ken Sakamura. All rights reserved. * T-Kernel / Standard Extension is distributed * under the T-License for T-Kernel / Standard Extension. *---------------------------------------------------------------------- * * Version: 1.00.00 * Released by T-Engine Forum(http://www.t-engine.org) at 2006/8/11. * *---------------------------------------------------------------------- *//* * @(#)ustdio.c (seio) * * Standard input-output * Console I/O */#include <sys/consio.h>#include "sfmgr.h"/* * STDIO File system connection information */EXPORT STDIOFS STDIO_FS;#define STDIN_FILE 0#define STDOUT_FILE 1#define STDERR_FILE 2#define TSD_SIN_POS_0 0#define TSD_SIN_POS_1 1#define TSD_SIN_POS_2 2#define TSD_SIN_BSZ_512 512/* * Standard input */EXPORT WER std_read( FDPkt *fdp, void *buf, size_t nbyte ){ STDIOFD *fd = (STDIOFD*)fdp->fd; W rdsize; ER err; /* File descriptor STDIN_FILE only */ if ( fd->fileno != STDIN_FILE ) { err = E_FD; goto err_ret; } /* Console input */ rdsize = console_in(fd->port, buf, nbyte); if ( rdsize < E_OK ) { err = rdsize; goto err_ret; } return rdsize;err_ret: DEBUG_PRINT(("std_read err=%#x\n", err)); return err;}/* * Standard output and standard error output */EXPORT WER std_write( FDPkt *fdp, const void *buf, size_t nbyte ){ STDIOFD *fd = (STDIOFD*)fdp->fd; W wrsize; ER err; /* File decriptor STDOUT_FILE or STDERR_FILE*/ if (( fd->fileno != STDOUT_FILE )&&( fd->fileno != STDERR_FILE )) { err = E_FD; goto err_ret; } /* Console output */ wrsize = console_out(fd->port, (B*)buf, nbyte); if ( wrsize < E_OK ) { err = wrsize; goto err_ret; } return wrsize;err_ret: DEBUG_PRINT(("std_write err=%#x\n", err)); return err;}/* * Standard input-output console information */EXPORT ER std_fstat( FDPkt *fdp, struct stat *sb ){ STDIOFD *fd = (STDIOFD*)fdp->fd; sb->st_dev = STDIO_DEV; sb->st_ino = fd->fileno; sb->st_mode = (S_IRUSR|S_IWUSR|S_IFCHR); sb->st_nlink = 1; sb->st_uid = 0; sb->st_gid = 0; sb->st_rdev = 0; (sb->st_atimespec).tv_sec = 0; (sb->st_mtimespec).tv_sec = 0; (sb->st_ctimespec).tv_sec = 0; (sb->st_atimespec).tv_nsec = 0; (sb->st_mtimespec).tv_nsec = 0; (sb->st_ctimespec).tv_nsec = 0; sb->st_size = 0; sb->st_blocks = 0; sb->st_blksize = TSD_SIN_BSZ_512; sb->st_flags = 0; sb->st_gen = 0; sb->st_lspare = 0; sb->st_qspare[TSD_SIN_POS_0] = sb->st_qspare[TSD_SIN_POS_1] = 0; return E_OK;}/* * Standard input-output file pointer transfer */EXPORT WER std_lseek( FDPkt *fdp, long offset, int whence ){ STDIOFD *fd = (STDIOFD*)fdp->fd; /* Transfer file pointer to the top */ switch ( whence ) { case SEEK_SET: if ( offset != 0L ) { goto err_ret; } break; case SEEK_CUR: if (( offset != 0L )||( fd->c.fpos != 0 )) { goto err_ret; } break; default: goto err_ret; } return (WER)(fd->c.fpos = 0);err_ret: DEBUG_PRINT(("std_lseek err=%#x\n", E_PAR)); return E_PAR;}/* * Standard input-output open */EXPORT WER std_open( FDPkt *fdp, int oflag, mode_t mode ){ /* Unsupport */ return E_NOSPT;}/* * Standard input-output close */EXPORT ER std_close( FDPkt *fdp ){ /* Do nothing */ return E_OK;}/* * Standard input-output initilization */EXPORT void std_init( UXINFO *uxinfo ){ STDIOFD *fd; UW consport; /* Fetch of port number */ if ( console_conf(CS_GETPORT, &consport) < E_OK ) { return; } fd = Vcalloc(1, sizeof(STDIOFD)); if ( fd != NULL ) { fd->c.fs = (FS*)&STDIO_FS; fd->c.inode = NULL; fd->c.fpos = 0; fd->c.omode = O_RDONLY; fd->c.refcnt = 1; fd->fileno = STDIN_FILE; fd->port = (W)consport; uxinfo->fdtbl[TSD_SIN_POS_0] = (FD*)fd; } /* Standard input-output open */ fd = Vcalloc(1, sizeof(STDIOFD)); if ( fd != NULL ) { fd->c.fs = (FS*)&STDIO_FS; fd->c.inode = NULL; fd->c.fpos = 0; fd->c.omode = O_WRONLY; fd->c.refcnt = 1; fd->fileno = STDOUT_FILE; fd->port = (W)consport; uxinfo->fdtbl[TSD_SIN_POS_1] = (FD*)fd; } /* Standard error output open */ fd = Vcalloc(1, sizeof(STDIOFD)); if ( fd != NULL ) { fd->c.fs = (FS*)&STDIO_FS; fd->c.inode = NULL; fd->c.fpos = 0; fd->c.omode = O_WRONLY; fd->c.refcnt = 1; fd->fileno = STDERR_FILE; fd->port = (W)consport; uxinfo->fdtbl[TSD_SIN_POS_2] = (FD*)fd; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -