write系统调用在nul处停止
好吧,这对某些人来说可能是显而易见的,但对我来说却不是(文档中没有提到):
int main(int argc, char** argv) {
char s[]= {'h','\0','l','0'};
int fd=open("myfile.txt", O_RDWR|O_CREAT|O_APPEND,0644);
write(fd,s,4);
return 0;
}
只会将“h”写入文件 - 因此缓冲区中的 nul 会终止 write(),尽管被要求写入过去?那么如何将 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'};
int 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 !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已解决:pico 显示 h^@10 - 所以 nul 毕竟被写入 - 所以它是“WinSCP 的内部文本编辑器”。对我来说仍然是一个谜。
(按照评论中的提示回答 - 如果有人可以为我确认这一点,那么我可以 100% 确定......)
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...)