Arguments for POSIX write() :
#include <unistd.h> ssize_t write(int fildes, const void *buf, size_t nbyte);
What a:
- file descriptor
- Buffer
- the size
You passed two sizes instead of an address and a size.
Using:
rtn = write(data, PATHA, sizeof(PATHA)-1);
or
rtn = write(data, PATHA, strlen(PATHA));
If you want to write the size of the string as an int , you will need an int variable to go to write() , for example:
int len = strlen(PATHA); rtn = write(data, &len, sizeof(len));
Note that you cannot just use the size_t variable if you do not want to write size_t ; on 64-bit Unix systems, in particular, sizeof(size_t) != sizeof(int) in general, and you need to decide what size you want to write.
You also need to know that some systems are low-risk and other big-endian, and what you write using this mechanism for one type will not be readable for another type (without working with cartography before or after the I / O operation). You can ignore this as a problem, or you can use a portable format (usually called "network order" and is equivalent to big-endian), or you can determine that your code uses the opposite order. You can write code so that the same logic is used on all platforms if you are careful (and all platforms get the same answers).
source share