An piece of old code that doesn't compile - Unix

This is a discussion on An piece of old code that doesn't compile - Unix ; Hi, below is a piece of old code, which doesn't compile under Linux/GCC: /* * Check if stream is already set up by autopush facility. */ if ((setup = ioctl(fd, I_FIND, "ldterm")) close(fd); return -6; } if (setup == 0) ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: An piece of old code that doesn't compile

  1. An piece of old code that doesn't compile

    Hi,

    below is a piece of old code, which doesn't compile under Linux/GCC:

    /*
    * Check if stream is already set up by autopush facility.
    */
    if ((setup = ioctl(fd, I_FIND, "ldterm")) < 0) {
    close(fd);
    return -6;
    }
    if (setup == 0) {
    if (ioctl(fd, I_PUSH, "ptem") < 0) {
    close(fd);
    return -7;
    }
    if (ioctl(fd, I_PUSH, "ldterm") < 0) {
    close(fd);
    return -8;
    }
    if (ioctl(fd, I_PUSH, "ttcompat") < 0) {
    close(fd);
    return -9;
    }
    }

    The I_FIND and I_PUSH are undeclared for Linux/GCC. Could anyone
    please tell me, what's the intention of the code ( I don't well
    understand what is `autoflush' ) and how should I modify it to make it
    compile?

    Thanks in advance.

    -
    narke

  2. Re: An piece of old code that doesn't compile

    In article
    <8859a235-4275-4abc-9f2f-5b1abc48a182@w8g2000prd.googlegroups.com>,
    Steven Woody wrote:

    > Hi,
    >
    > below is a piece of old code, which doesn't compile under Linux/GCC:
    >
    > /*
    > * Check if stream is already set up by autopush facility.
    > */
    > if ((setup = ioctl(fd, I_FIND, "ldterm")) < 0) {
    > close(fd);
    > return -6;
    > }
    > if (setup == 0) {
    > if (ioctl(fd, I_PUSH, "ptem") < 0) {
    > close(fd);
    > return -7;
    > }
    > if (ioctl(fd, I_PUSH, "ldterm") < 0) {
    > close(fd);
    > return -8;
    > }
    > if (ioctl(fd, I_PUSH, "ttcompat") < 0) {
    > close(fd);
    > return -9;
    > }
    > }
    >
    > The I_FIND and I_PUSH are undeclared for Linux/GCC. Could anyone
    > please tell me, what's the intention of the code ( I don't well
    > understand what is `autoflush' ) and how should I modify it to make it
    > compile?
    >
    > Thanks in advance.
    >
    > -
    > narke


    --
    printf -v email $(echo \ 155 141 162 143 145 154 155 141 162 \
    143 145 154 100 157 162 141 156 147 145 56 156 154 | tr \ \\)
    # O Herr, lass Hirn vom Himmel fallen! #

  3. Re: An piece of old code that doesn't compile

    Steven Woody wrote:

    > below is a piece of old code, which doesn't compile under Linux/GCC:
    >
    > /*
    > * Check if stream is already set up by autopush facility.
    > */


    http://www.hgc.edu/hartford/webgen//...l#ADMIN5-29016

    #if defined(I_FIND) && defined(I_PUSH)
    > if ((setup = ioctl(fd, I_FIND, "ldterm")) < 0) {
    > close(fd);
    > return -6;
    > }
    > if (setup == 0) {
    > if (ioctl(fd, I_PUSH, "ptem") < 0) {
    > close(fd);
    > return -7;
    > }
    > if (ioctl(fd, I_PUSH, "ldterm") < 0) {
    > close(fd);
    > return -8;
    > }
    > if (ioctl(fd, I_PUSH, "ttcompat") < 0) {
    > close(fd);
    > return -9;
    > }
    > }

    #endif

    > The I_FIND and I_PUSH are undeclared for Linux/GCC.



  4. Re: An piece of old code that doesn't compile

    Steven Woody writes:
    >below is a piece of old code, which doesn't compile under Linux/GCC:


    Probably not too old.. There's alot older.

    > /*
    > * Check if stream is already set up by autopush facility.
    > */
    > if ((setup = ioctl(fd, I_FIND, "ldterm")) < 0) {
    > close(fd);
    > return -6;
    > }
    > if (setup == 0) {
    > if (ioctl(fd, I_PUSH, "ptem") < 0) {
    > close(fd);
    > return -7;
    > }
    > if (ioctl(fd, I_PUSH, "ldterm") < 0) {
    > close(fd);
    > return -8;
    > }
    > if (ioctl(fd, I_PUSH, "ttcompat") < 0) {
    > close(fd);
    > return -9;
    > }
    > }


    >The I_FIND and I_PUSH are undeclared for Linux/GCC. Could anyone
    >please tell me, what's the intention of the code ( I don't well
    >understand what is `autoflush' ) and how should I modify it to make it
    >compile?


    It pushes those modules onto the Stream.
    Since Linux doesn't have streams, You'll be doing something totally
    different for this chunk of code, so don't worry about trying to copy
    it line by line, you'll have to go up a level or two of abstraction,
    probably allocate a pty instead.



  5. Re: An piece of old code that doesn't compile

    On Jun 4, 10:33 am, Doug McIntyre wrote:
    > Steven Woody writes:
    > >below is a piece of old code, which doesn't compile under Linux/GCC:

    >
    > Probably not too old.. There's alot older.
    >
    >
    >
    > > /*
    > > * Check if stream is already set up by autopush facility.
    > > */
    > > if ((setup = ioctl(fd, I_FIND, "ldterm")) < 0) {
    > > close(fd);
    > > return -6;
    > > }
    > > if (setup == 0) {
    > > if (ioctl(fd, I_PUSH, "ptem") < 0) {
    > > close(fd);
    > > return -7;
    > > }
    > > if (ioctl(fd, I_PUSH, "ldterm") < 0) {
    > > close(fd);
    > > return -8;
    > > }
    > > if (ioctl(fd, I_PUSH, "ttcompat") < 0) {
    > > close(fd);
    > > return -9;
    > > }
    > > }
    > >The I_FIND and I_PUSH are undeclared for Linux/GCC. Could anyone
    > >please tell me, what's the intention of the code ( I don't well
    > >understand what is `autoflush' ) and how should I modify it to make it
    > >compile?

    >
    > It pushes those modules onto the Stream.
    > Since Linux doesn't have streams, You'll be doing something totally
    > different for this chunk of code, so don't worry about trying to copy
    > it line by line, you'll have to go up a level or two of abstraction,
    > probably allocate a pty instead.


    Actually, I am creating a psuedo tty master/slave pair, those code
    above appeared after the slave descriptor was created using open(2) on
    the slave name. On modern Linux, can I simplly ignore those old code
    after open(2) got a slave descriptor and go off head to use it? If
    not so, can anyone please tell me, is there anything special I still
    need to do to make the slave play just like a normal termianl device.
    Thank you.

  6. Re: An piece of old code that doesn't compile

    Steven Woody writes:
    > On Jun 4, 10:33 am, Doug McIntyre wrote:
    >> Steven Woody writes:
    >> >below is a piece of old code, which doesn't compile under Linux/GCC:


    [setup a pty on a system w/ STREAMS]

    [...]

    > Actually, I am creating a psuedo tty master/slave pair, those code
    > above appeared after the slave descriptor was created using open(2) on
    > the slave name. On modern Linux, can I simplly ignore those old code
    > after open(2) got a slave descriptor and go off head to use it?


    The problem is not that it is 'old', but that it has been written to
    use an particular SVR4 facility called 'STREAMS' which (usually)
    doesn't exist on Linux.

    Documentation for using 'UNIX98' pseudo terminals (which is what I
    would use) is in pty(7) and pts(4) for Linux. A simple example of two
    routines doing this based on open is below:

    static int open_ptmx(void)
    {
    int fd, rc;

    fd = open(PTMX, O_RDWR, 0); /* /dev/ptmx */
    fd != -1 || sys_die(__func__, "open");

    rc = grantpt(fd);
    rc != -1 || sys_die(__func__, "grantpt");
    rc = unlockpt(fd);
    rc != -1 || sys_die(__func__, "unlockpt");
    return fd;
    }

    static int open_ptys(int ptmx)
    {
    char *pty_name;
    int rc;

    pty_name = ptsname(ptmx);
    pty_name || sys_die(__func__, "ptsname");

    rc = open(pty_name, O_RDWR, 0);
    rc != -1 || sys_die(__func__, "open");
    return rc;
    }

    [It's also a nice example of why 'different coding style !!1'-warnings are
    crap ... this code is (c) my employer and cited as example]

    Usually, the 'slave' end of the PTY should be the controlling terminal
    for the process using it. This can be accomplished either be opening
    it in this process (SysV-semantic: open a tty device in a process w/o
    controlling tty [which is a session leader] causes that to become the
    controlling tty of this session) or by using the (BSD-originated)
    TIOCSCTTY-ioctl.

+ Reply to Thread