当前位置: 技术问答>linux和unix
linux 文件能正确打开,但是显示bad file descriptor,写不了
来源: 互联网 发布时间:2017-01-13
本文导语: #define PRO_TMP_NAME "wait.c" #include #include #include #include #include #include int write_pro(char *pro); void err_unix(char *msg); int main() { write_pro("Hello world"); return 0; } //简易错误处理程序 void err_unix(char *msg) { printf("Error:...
#define PRO_TMP_NAME "wait.c"
#include
#include
#include
#include
#include
#include
int write_pro(char *pro);
void err_unix(char *msg);
int main()
{
write_pro("Hello world");
return 0;
}
//简易错误处理程序
void err_unix(char *msg)
{
printf("Error: %-3d%-30s%-30sn", errno, strerror(errno),msg);
//perror(msg);
}
//功能:将字符串pro写入文件PRO_TMP_NAME中去
//成功返回1 失败返回0
int write_pro(char *pro)
{
int fd;
fd = open(PRO_TMP_NAME, O_RDONLY|O_TRUNC|O_CREAT, S_IRUSR|S_IWUSR);
// check fd
printf("%dn", fd);
if(fd