Hi,
can anyone tell me how to get the retun value of the function:
Would I be right in saying that the return value of -1 for the function write represents an error?Code:write(int fildes, const void *buf, size_t ubyte);
Hi,
can anyone tell me how to get the retun value of the function:
Would I be right in saying that the return value of -1 for the function write represents an error?Code:write(int fildes, const void *buf, size_t ubyte);
write should return a positive (or zero) value representing the number of bytes written for when it is successful, and anything negative returned is an error, yes. The value in errno would indicate WHAT went wrong.
Edit: If the result of this:
is actually -1, then I'd say my reply in the thread with this code explains why - you should not be calling write with a handle from CreateFile or OpenFile.Code:if((bytes_written=write(handle, data, length)) != length) printf("SendData(): system call \"write()\" return error.\n Asked for %d bytes to be written, but %d bytes reported as written.\n", length,(int)bytes_written);
--
Mats
Last edited by matsp; 04-17-2009 at 04:27 AM.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thanks Mats
but how would I find out the number of bytes it has written or if it returns an error?
Erm, if it's negative, then it (most likely) didn't write any bytes. But what I was trying to say is that you are mixing functions that are part of different API's - write is not using the same type of information as a "handle" or "file descriptor" as you get back from CreateFile(). This is the source of the Warning you got yesterday, and whilst casting gets rid of the warning, it doesn't actually give the RIGHT VALUE that write would expect to use.
WriteFile() will give you the number of bytes written as one of the parameters.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.