write system call stops at nul
Well it may be obvious to some but not to me (and it is not mentioned in the documentation) :
int main(int argc, char** argv) {
char s[]= {'h','\0','l','0'};
i开发者_StackOverflownt fd=open("myfile.txt", O_RDWR|O_CREAT|O_APPEND,0644);
write(fd,s,4);
return 0;
}
Will only write 'h' to the file - so a nul in the buffer terminates write() despite being asked to write past it ? How do I write a nul to a file then ?
Thanks !
SOLVED : pico shows h^@10 - so the nul got written after all - so it was "WinSCP's Internal Text Editor". Still something of a mystery to me.
(answered as prompted in the comments - still if someone could confirm this for me so I can be 100% sure...)
精彩评论