caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Conversion between file descriptors and strings
@ 1997-03-10 14:01 Pawel Wojciechowski
  0 siblings, 0 replies; only message in thread
From: Pawel Wojciechowski @ 1997-03-10 14:01 UTC (permalink / raw)
  To: caml-list; +Cc: Pawel.Wojciechowski


Hi all,

I just started programming in the Objective Caml language. At the current 
stage of my project, I need to implement a communication between a process 
and its child process, which is created by 'fork'. I decided to use pipes 
from the Unix library. Instead of exchanging standard descriptors (0 and 1) 
for descriptors fd_in and fd_out created by 'pipe' (as in the expression
(fd_out, fd_in) = pipe()), I'd prefer to pass descriptors fd_out and fd_in,
to a program executed as a forked process, as arguments when invoking
'execvp'. Then, you can pass these values to the program (which is stored 
in a separate file and compiled separately) as an array of *strings*
being a structural argument to the 'execvp'.

My question is how to convert a descriptor of type file_descr into a string 
and vice-versa?

In C, there is no such problems, since descriptors are integers, and you 
can always write accordingly: 

sprintf(arg1, "%d", pipe[0])

and

descr =  atoi(argv[1])

In strongly-typed (O)Caml, we should expect the following error message:
"This expression has type int but is here used with type Unix.file_descr"

I don't have much experience in using (O)Caml so appologize if you
consider that my problem is trivial but please help me sort it out! :)

regards,

Pawel

ps. Pipe is a function from the Unix library and it has types as follows:

pipe : init -> file_descr * file_desc








^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-03-10 14:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-03-10 14:01 Conversion between file descriptors and strings Pawel Wojciechowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).