[Ecls-list] ecl_make_stream_from_fd() && smm_io crashes

Matthew Mondor mm_lists at pulsar-zone.net
Sat Mar 20 19:04:15 UTC 2010


On Sat, 20 Mar 2010 15:32:56 +0100
Juan Jose Garcia-Ripoll <juanjose.garciaripoll at googlemail.com> wrote:

> A candidate for failure is when you create a file descriptor with one mode
> and try to fdopen() it with a different mode, as in the following tiny
> example:
> 
> (ffi::clines "#include <fcntl.h>")
> 
> (defun make-stream (filename)
>   (let ((f (namestring filename)))
>     (ffi:c-inline (f) (:object) :object "
> {
> mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
> cl_object file = #0;
> int fd = open(file->base_string.self, O_RDONLY, mode);
> printf(\"%d %s\", fd, file->base_string.self);
> @(return) = ecl_make_stream_from_fd(file, fd, smm_io,
>                                             8, 0, @:default);
> }"
>                   :one-liner nil)))
> 
> Replacing smm_io with smm_input fixes the problem here.

The following (attached) test case works fine however, using mode 0 or
07777, except for the close(2) syscall since fclose(3) closes the
internal file descriptor (which as necessary could be fixed using
dup(2)/dup2(2) of course).  There the FD is also open O_RDONLY yet the
fdopen(3) and fgets(3) calls work fine with an "rw" FILE...

Thanks,
-- 
Matt




More information about the ecl-devel mailing list