It seems both do the same thing, huh?
Can someone show me an example where they do different job?
sysopen
is a thin wrapper around the open(2)
kernel system call (the arguments correspond directly), whereas open
is a higher-level wrapper which enables you to do redirections, piping, etc.
Unless you are working with a specific device that requires some special flags to be passed at open(2)
time, for ordinary files on disk you should be fine with open
.
To quote perlopentut:
If you want the convenience of the shell, then Perl's open is definitely the way to go. On the other hand, if you want finer precision than C's simplistic fopen(3S) provides you should look to Perl's sysopen, which is a direct hook into the open(2) system call. That does mean it's a bit more involved, but that's the price of precision.
Since Perl is written in C, both methods likely end up making the open(2)
system call. The difference is that open()
in Perl has some niceties built in that make opening, piping and redirection very easy. At the same time, though, open()
takes away some flexibility. It has none of the Fcntl
functionality available in sysopen()
, nor does it have the masking functionality.
Most situations just need open()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With