www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Where is "open" in "core.sys.linux.unistd"?

reply rempas <rempas tutanota.com> writes:
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?
Jul 09
next sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
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
Jul 09
parent rempas <rempas tutanota.com> writes:
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
Jul 09
prev sibling parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 7/9/21 10: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?
Because file descriptors are created in different ways. For example, `open` exists for files [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/fcntl.d) But opening a socket is done via the `socket` system call [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/sys/socket.d) They don't take the same arguments (nor should they). But reading/writing, closing these file descriptors is always the same. -Steve
Jul 09
next sibling parent reply Dennis <dkorpel gmail.com> writes:
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.
Jul 09
next sibling parent rempas <rempas tutanota.com> writes:
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!
Jul 09
prev sibling parent Steven Schveighoffer <schveiguy gmail.com> writes:
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
Jul 09
prev sibling parent reply rempas <rempas tutanota.com> writes:
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](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?
Because file descriptors are created in different ways. For example, `open` exists for files [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/fcntl.d) But opening a socket is done via the `socket` system call [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/sys/socket.d) 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!
Jul 09
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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
Jul 09
parent rempas <rempas tutanota.com> writes:
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 ;)
Jul 09