Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C write() help

Name: Anonymous 2007-02-11 10:59

I just don't get how it works.
write(1, buffer, bytestowrite) writes to stdout.
if i open a file with open() and then do a write(2, etc..) it writes to that file.
thing is how do i know the number every time ? i don't get that :S

Name: Anonymous 2007-02-11 12:15

man open
Given a pathname for a file, open() returns a file descriptor, a small, non-negative integer for  use  in  subsequent  system  calls  (read(2), write(2), lseek(2), fcntl(2), etc.).  The file descriptor returned by a successful call will be the lowest-numbered file  descriptor  not  currently open for the process.

Obviously you have to use the return value of open() as the first arg to write(). And I've never even done any serious C, I just looked at the manpage. Like you should have done.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List