Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

write() function returning -1 (error) on terminals???

1 view
Skip to first unread message

Jerry Geis

unread,
Jul 7, 1993, 12:07:40 PM7/7/93
to
I'm using the write() function to output characters in my program.
Once in a while characters mess up on my wyse60 terminal, but never
on the console. I looked a little closer and when the terminal messes
up the write() function had returned a -1 (error condition). My
question is what would cause this??? Here are the things I have tried
that made not difference at all:

1) did a fflush() after every character sent
2) did a delay after every character sent

3) tried sending just one character at a time and not strings
with write(). trying sending the one character with the steps
mentioned above

nothing made a difference. I would have at least expected the delay to
do something different.

Thanks for any ideas!

jerry geis

ge...@se01.elk.miles.com

James C. Graves Jr.

unread,
Jul 8, 1993, 12:15:02 AM7/8/93
to
Well, you didn't post any code, so we'll have to keep the discussion general.

Be careful mixing system calls with functions from the stdio library.
The calls open(), write(), read(), etc. don't work the same way as
fopen(), printf(), getchar(), etc. The system calls like open() work
with file descriptors (integers). The library functions like fopen()
work with FILE pointers. Compare the two entries in your manual.

Even if you are using the functions and system calls correctly, I don't
recommend mixing them. The STDIO functions use buffered I/O, and the
system calls don't.

How are you opening up? If you run the program from the same terminal
that the output goes to, you can just use stdin, stdout, and stderr
(FILE pointers), which are opened automatically when your program
starts to execute. Don't put any stuff to specifically open up a
particular tty unless that's what you really want.

You may want to pick up a good book on 'C' and UNIX. I really enjoyed
'The UNIX Programming Environment' by Kerningham & Pike. It covers the
Bourne shell, awk, make, stdio & system calls, and more in a easy and
readable style.

Good Luck!
----
James C. Graves Jr. p00...@psilink.com
Philosophical Consulting & Computer Repair

0 new messages