Thread overview
Where is "open" in "core.sys.linux.unistd"?
Jul 09, 2021
rempas
Jul 09, 2021
rikki cattermole
Jul 09, 2021
rempas
Jul 09, 2021
Dennis
Jul 09, 2021
rempas
Jul 09, 2021
rempas
Jul 09, 2021
Ali Çehreli
Jul 09, 2021
rempas
July 09, 2021

The file can be found quickly here or in your system if you want. Now the question is, why isn't there an "open" function for the equivalent system call? "close", "write", "read" etc. all exist. Anyone knows what's going on with open?

July 10, 2021
On 10/07/2021 2:51 AM, rempas wrote:
> The file can be found quickly [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/unistd.d) or in your system if you want. Now the question is, why isn't there an "open" function for the equivalent system call? "close", "write", "read" etc. all exist. Anyone knows what's going on with open?

This is easily explained.

open is not declared to be defined in unist.h[0]

You may be wanting fopen from stdio.h[1]

Or open from fcntl.h[2]

[0] https://man7.org/linux/man-pages/man0/unistd.h.0p.html
[1] https://man7.org/linux/man-pages/man0/stdio.h.0p.html
[2] https://man7.org/linux/man-pages/man0/fcntl.h.0p.html
July 09, 2021

On 7/9/21 10:51 AM, rempas wrote:

>

The file can be found quickly here or in your system if you want. Now the question is, why isn't there an "open" function for the equivalent system call? "close", "write", "read" etc. all exist. Anyone knows what's going on with open?

Because file descriptors are created in different ways.

For example, open exists for files here

But opening a socket is done via the socket system call here

They don't take the same arguments (nor should they).

But reading/writing, closing these file descriptors is always the same.

-Steve

July 09, 2021
On Friday, 9 July 2021 at 15:04:32 UTC, rikki cattermole wrote:
>
> On 10/07/2021 2:51 AM, rempas wrote:
>> The file can be found quickly [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/unistd.d) or in your system if you want. Now the question is, why isn't there an "open" function for the equivalent system call? "close", "write", "read" etc. all exist. Anyone knows what's going on with open?
>
> This is easily explained.
>
> open is not declared to be defined in unist.h[0]
>
> You may be wanting fopen from stdio.h[1]
>
> Or open from fcntl.h[2]
>
> [0] https://man7.org/linux/man-pages/man0/unistd.h.0p.html
> [1] https://man7.org/linux/man-pages/man0/stdio.h.0p.html
> [2] https://man7.org/linux/man-pages/man0/fcntl.h.0p.html

Thanks man, have a nice day
July 09, 2021

On Friday, 9 July 2021 at 15:11:38 UTC, Steven Schveighoffer wrote:

>

But reading/writing, closing these file descriptors is always the same.

For sockets you'd typically use recv and send instead or read and write because the former give extra options and the latter don't work on Windows. But yeah, on Linux read and write should work universally among file descriptors.

July 09, 2021

On Friday, 9 July 2021 at 15:11:38 UTC, Steven Schveighoffer wrote:

>

On 7/9/21 10:51 AM, rempas wrote:

>

The file can be found quickly here or in your system if you want. Now the question is, why isn't there an "open" function for the equivalent system call? "close", "write", "read" etc. all exist. Anyone knows what's going on with open?

Because file descriptors are created in different ways.

For example, open exists for files here

But opening a socket is done via the socket system call here

They don't take the same arguments (nor should they).

But reading/writing, closing these file descriptors is always the same.

-Steve

If I tell you that I searched "fnctl" in the repo and didn't find anything will you believe me? Probably made a typo idk... Anyway thanks a lot your help and I wish you to have an amazing day!

July 09, 2021

On Friday, 9 July 2021 at 15:31:50 UTC, Dennis wrote:

>

On Friday, 9 July 2021 at 15:11:38 UTC, Steven Schveighoffer wrote:

>

But reading/writing, closing these file descriptors is always the same.

For sockets you'd typically use recv and send instead or read and write because the former give extra options and the latter don't work on Windows. But yeah, on Linux read and write should work universally among file descriptors.

That's very important! Thanks a lot for the info!

July 09, 2021
On 7/9/21 8:31 AM, rempas wrote:

> I searched "fnctl" in the repo [...] Probably made a typo

Yes, the typo should be obvious to the non-dyslexic among us. :)

fnctl <-- wrong
fcntl <-- correct

Ali

July 09, 2021

On 7/9/21 11:31 AM, Dennis wrote:

>

On Friday, 9 July 2021 at 15:11:38 UTC, Steven Schveighoffer wrote:

>

But reading/writing, closing these file descriptors is always the same.

For sockets you'd typically use recv and send instead or read and write because the former give extra options and the latter don't work on Windows. But yeah, on Linux read and write should work universally among file descriptors.

I typically only use send and recv for for connectionless sockets. For TCP sockets, it's generally read and write for me (and it works fine).

Windows is a different story, they have different i/o routines for system calls (yes, there's the shims for Posix file descriptors, but I wouldn't use those anyway).

The larger point is that the reason read/write are separate from descriptor creation is because they are universal, while creation is not.

-Steve

July 09, 2021
On Friday, 9 July 2021 at 15:37:41 UTC, Ali Çehreli wrote:
> On 7/9/21 8:31 AM, rempas wrote:
>
> > I searched "fnctl" in the repo [...] Probably made a typo
>
> Yes, the typo should be obvious to the non-dyslexic among us. :)
>
> fnctl <-- wrong
> fcntl <-- correct
>
> Ali

Lol, I'm not dyslexic (or at least I haven't find out) but still some times I just miss those small details. Its probably that in my mind, I never really noticed how it's typed in the first place. I thought "fn" then "ctl" for "control" so "function control" or something idk.... Anyway yeah nice catch ;)