Understanding the write function
Solved
Hello, I just used the write function without really understanding it, so I would like some explanations.
Here's my function: write(1, &c, 1)
I would like to know what each thing in the parentheses corresponds to.
Thank you.
Configuration: iPhone / Firefox 32.0
Here's my function: write(1, &c, 1)
I would like to know what each thing in the parentheses corresponds to.
Thank you.
Configuration: iPhone / Firefox 32.0
3 answers
-
ContributorHello,
There's no need to duplicate requests, we won't respond any faster...
You need to refer to the man: http://manpagesfr.free.fr/man/man2/write.2.html
For your information, write() is not standard. We usually use fwrite().
Otherwise, for write(), the type is: ssize_t write(int fd, const void *buf, size_t count)
So for the first argument, you need the descriptor. As for the second, you need the address of a pointer. So rather "0123456789" in quotes. And finally the size, that's okay.
Regards,
--
Google is your friend-
-
ContributorI mainly wanted to say that fwrite() will work on any system. The other one will only work on POSIX.
Additionally, these are not functions of the same level.
Moreover, write() is blocking, etc. In short, the advantage of using wrappers is also to program while abstracting away from the system layer... -
-
-
-