This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]