On Wednesday, 30 November 2016 at 07:16:38 UTC, Anders S wrote:
On Tuesday, 29 November 2016 at 23:33:19 UTC, Ali Çehreli wrote:
On 11/29/2016 07:30 AM, Anders S wrote:
....
Ali


Thanks you all guys, and the cast (IOREQ *) ... did the trick!!
I'll have a look at your other comments aswell on struct a.s.o.
/anders

Hi again, still have problem. It works when using plain text but not like this:
(Hope you can identify my errors ;) )

import std.range, std.stdio, std.conv;
import core.stdc.string;
import core.stdc.stdio;
import core.sys.posix.sys.stat;
import core.sys.posix.unistd;
import core.sys.posix.fcntl;
import core.sys.posix.sys.stat;

extern (C) uint read(int, void *, uint);
extern (C) uint write(int, void *, ulong);

struct IOREQ {
        short   fc;                     /* function code */
        short   rs;                     /* return code */
        int     size;                   /* size of this request, including */
        short   src;                    /* source */
        int     [1] argv;               /* list of arguments */
 };

    void main(string[] args) {
           //f;
           int fd = -1;
           IOREQ *io;
           fd = mkfifo("/Users/anders/pipes/8556",666 );
           char [1024]rbuf;
           char [1024]sbuf;
sbuf = "You must use the cast keyword, the pointer to first element of an array is .ptr, and I think you meant sbuf:
                    io = cast(IOREQ *)sbuf.ptr;";

            io = cast (IOREQ *) sbuf;
            io.fc = 501;
            io.rs = 1234;
            io.src = 8556;
            writeln("\nio.fc :", io.fc);
           writeln("io.rs :", io.rs);
           writeln("\nio.src :", io.src);
            writeln ("\nio :",io);
writeln("Skrev ", write(fd, cast (void*) sbuf, sbuf.length)); writeln("läste ", read(fd, cast (void*) rbuf, sbuf.length));

           writeln("\nrbuf :", rbuf);
           io = cast(IOREQ *) rbuf;
           writeln("\nrio.fc :", io.fc);
           writeln("\nrio.rs :", io.rs);
           writeln("\nrio.src :", io.src);
           //unlink("/Users/anders/pipes/8556");

    }


Reply via email to