我打开一个文件并想在其中写一些东西。问题是 fd2 出于某种原因是 0。它没有写入文件,而是写入终端。我没有在我的代码中的任何地方关闭(0)。为什么我得到 fd = 0 而不是例如 3。在终端上写的原因是 fd 的值为零?我知道 fd = 0 用于标准输入,
有任何想法吗?谢谢你。
if ((fd2 = open(logFile, O_RDWR |O_APPEND | O_CREAT , 0666) == -1))
DieWithError("open() failed");
printf("FD2 = %d",fd2); //returns me zero
bzero(tempStr, sizeof(tempStr));
bzero(hostname, sizeof(hostname));
gethostname(hostname, sizeof(hostname));
sprintf(tempStr, "\n%sStarting FTP Server on host %s in port %d\n", ctime(¤time), hostname, port);
if (write(fd2, tempStr, strlen(tempStr)) == -1)
DieWithError("write(): failed");