3 ms·
I asked it just now: "In POSIX, how do I create a new file descriptor which refers to the same file as another file descriptor but with its own seek offset?" I
by mort96 4y ago
I asked it just now: "In POSIX, how do I create a new file descriptor which refers to the same file as another file descriptor but with its own seek offset?"
It answered:
> In POSIX, you can use the dup or dup2 system call to create a new file descriptor that refers to the same file as an existing file descriptor. The new file descriptor will have its own seek offset, which can be manipulated independently of the original file descriptor.
The actual answer is that there is no way to do what I asked. The dup or dup2 system calls give you a new file descriptor which refers to the same file description, so the two FDs will use the same seek offset; seeking one FD will seek the other FD too. But ChatGPT just confidently insists that dup creates a new FD which has a separate seek offset and can be manipulated independently.
This isn't the first time I've seen it invent plausible-sounding but wrong answers to tricky questions. The file descriptor thing is just something I decided to try just now because I encountered the problem a couple of days ago and it felt like the kind of thing ChatGPT would bullshit about. I was right.