This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
read and write to standerd IO
- From: Satoshi Sasaki <sasaki at info dot kobelco dot co dot jp>
- To: "'eCos Discussion'" <ecos-discuss at sources dot redhat dot com>
- Date: Wed, 23 Oct 2002 14:49:22 +0900
- Subject: [ECOS] read and write to standerd IO
Hello there,
I'm examining Man Machine Interface using Serial I/F on MBX860.
I want to use read() and write() command, for compatibility
with other OS.
My understanding is as follows.
STDIN fd : 0
STDOUT fd : 1
STDERROR fd : 2
read() failed if the following programs are executed.
test_prog() is executed as a thread.
int test_prog()
{
char tmpbuf[5];
write(1,"XXXX",4);
read(0,&tmpbuf,4);
tmpbuf[4]=0;
printf("%s\n",(char *)&tmpbuf);
return(0);
}
The following program works correct.
int test_prog()
{
int testfd;
char tmpbuf[5];
testfd=open("/dev/ser1",3,0666);
write(testfd,"XXXX",4);
read(testfd,&tmpbuf,4);
tmpbuf[4]=0;
printf("fd=%d,%s\n",testfd,(char *)&tmpbuf);
close (testfd);
return(0);
}
Testfd was 3 at this time.
Can I use standard input(fd number 0)?
Or is it necessary to call open() again from a user program?
(Like the 2nd program)
In this case, doesn't it compete with the device which has already
opend for STDIO?
Or is STDIO input not opened ?
Thank you
---------------
Satoshi Sasaki
sasaki@info.kobelco.co.jp (Kobe Japan)
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss