New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unix library bug #3782
Comments
Comment author: administrator Xavier's reply to the dup2 problem:
The Cash library does seem to do the job but I'm not sure it is worth it. What val fd_of_int: int -> fd somefile.c: #include <mlvalues.h> CAMLprim unix_fdofint(value fd) as an OCAML module (or even an addition to the standard Unix Module) ;-) Steve |
Comment author: administrator
The typical usage of dup2 is to redirect a descriptor to another let new_stdout =
This you can't do with the Unix module. However, I believe the Cash
|
Comment author: administrator File descriptors are not convertible with integers, intentionally. |
Comment author: administrator On Thursday, Sep 26, 2002, at 10:29 Europe/Paris,
It's true that the Unix library doesn't give a name for file descriptor But if you are starting on this kind of things, I think you will soon -- Damien |
Comment author: administrator Date: Thu, 26 Sep 2002 11:43:07 +0200 On Thursday, Sep 26, 2002, at 10:29 Europe/Paris,
But if you are starting on this kind of things, I think you will The Cash library does seem to do the job but I'm not sure it is Just be careful not to use an int value already in use by a channel. Good luck, |
Original bug ID: 1404
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Hi,
I'm currently playing with sockets under ocaml-3.04 (on Linux) and have found
a small bug in the Unix library.
The problem involves the dup2(oldfd, newfd) system call which will duplicate
the file descriptor oldfd as the new file descriptor newfd which the caller
specifies (not the system, c.f. dup()). Given that the type file_descr is an
abstract type and no constructor function is provided, how is one supposed to
create a new file descriptor for use with dup2()?
One approach is to call socket() and use the new fd it returns. This is not
ideal for us as we wish to duplicate file descriptors to higher-valued
descriptors which we specify. It also doesn't really follow the unix/posix
semantics which allow any integer value to be passed.
May I suggest the following changes:
unix.mli:
val fd_of_int: int -> fd
unix.ml:
external fd_of_int: int -> fd = "unix_fdofint"
somefile.c:
#include <mlvalues.h>
#include "unixsupport.h"
CAMLprim unix_fdofint(value fd)
{
return Val_int(fd);
}
Thanks,
Steve
The text was updated successfully, but these errors were encountered: