?? lowsrc.c
字號:
/***********************************************************************/
/* */
/* FILE :lowsrc.c */
/* DATE :Fri, Nov 07, 2003 */
/* DESCRIPTION :Program of I/O Stream */
/* CPU TYPE :H8/38024F */
/* */
/* This file is generated by Renesas Project Generator (Ver.3.0). */
/* */
/***********************************************************************/
#include<string.h>
#include <stdio.h>
#include <stddef.h>
#include "lowsrc.h"
#define STDIN 0
#define STDOUT 1
#define STDERR 2
#define FLMIN 0
#define FLMAX 3
#define O_RDONLY 0x0001
#define O_WRONLY 0x0002
#define O_RDWR 0x0004
#define CR 0x0d
#define LF 0x0a
const int _nfiles = IOSTREAM;
struct _iobuf _iob[IOSTREAM];
unsigned char sml_buf[IOSTREAM];
extern void charput(char);
extern char charget(void);
char flmod[FLMAX];
/***********************************************************/
/* open */
/***********************************************************/
open(char *name,
int mode,
int flg)
{
if(strcmp(name,"stdin")==0){
if((mode&O_RDONLY)==0)
return -1;
flmod[STDIN]=mode;
return STDIN;
}
else if(strcmp(name,"stdout")==0){
if((mode&O_WRONLY)==0)
return -1;
flmod[STDOUT]=mode;
return STDOUT;
}
else if(strcmp(name,"stderr")==0){
if((mode&O_WRONLY)==0)
return -1;
flmod[STDERR]=mode;
return STDERR;
}
else
return -1;
}
/***********************************************************/
/* close */
/***********************************************************/
close(int fileno)
{
if(fileno<FLMIN || FLMAX<=fileno)
return -1;
flmod[fileno]=0;
return 0;
}
/***********************************************************/
/* read */
/***********************************************************/
read(int fileno,
char *buf,
int count)
{
int i;
if(flmod[fileno]&O_RDONLY || flmod[fileno]&O_RDWR){
for(i=count; i>0; i--){
*buf=charget();
if(*buf==CR)
*buf=LF;
buf++;
}
return count;
}
else
return -1;
}
/***********************************************************/
/* write */
/***********************************************************/
write(int fileno,
char *buf,
int count)
{
int i;
char c;
if(flmod[fileno]&O_WRONLY || flmod[fileno]&O_RDWR){
for(i=count; i>0; i--){
c=*buf++;
charput(c);
}
return count;
}
else
return -1;
}
/***********************************************************/
/* lseek */
/***********************************************************/
long lseek(int fileno,
long offset,
int base)
{
return -1L;
}
/****************************************************************************/
/* _INIT_IOLIB */
/****************************************************************************/
void _INIT_IOLIB(void)
{
FILE *fp;
for( fp = _iob; fp < _iob + _NFILE; fp++ )
{
fp->_bufptr = NULL;
fp->_bufcnt = 0;
fp->_buflen = 0;
fp->_bufbase = NULL;
fp->_ioflag1 = 0;
fp->_ioflag2 = 0;
fp->_iofd = 0;
}
if(freopen( "stdin", "r", stdin )==NULL)
stdin->_ioflag1 = 0xff;
stdin->_ioflag1 |= _IOUNBUF;
if(freopen( "stdout", "w", stdout )==NULL)
stdout->_ioflag1 = 0xff;
stdout->_ioflag1 |= _IOUNBUF;
if(freopen( "stderr", "w", stderr )==NULL)
stderr->_ioflag1 = 0xff;
stderr->_ioflag1 |= _IOUNBUF;
}
/****************************************************************************/
/* _CLOSEALL */
/****************************************************************************/
void _CLOSEALL(void)
{
int i;
for( i=0; i < _NFILE; i++ )
if( _iob[i]._ioflag1 & (_IOREAD | _IOWRITE | _IORW ) )
fclose( & _iob[i] );
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -