// brief: write a string to a file
// return 0 if success
// return -1 if failure
int write2file(const char *src)
{
char *w_buf = (char *)src;
size_t w_len = strlen(src);
ssize_t written = 0;
// The return value of 'write' is the number of bytes actually written. This
// may be SIZE, but can always be smaller, so call 'write' in a loop, iterating
// until all the data is written
while (w_len > 0) {
if((written = write(fFd, w_buf, w_len)) < 0){
printf("write error");
return -1;
}
w_buf += written;
w_len -= written;
}
return 0;
}