Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

Where is fcntl

alt_avalon_uart_read() and alt_avalon_uart_write() routines support a 'O_NONBLOCK' parameter. I'd like to control this flag from my code using the following function:

static void set_block_mode(bool block_mode) {
        int cntl = fcntl(STDIN_FILENO, F_GETFL);
        if (cntl & O_NONBLOCK)
        {
                if (block_mode)
                        fcntl(STDIN_FILENO, F_SETFL, cntl & ~O_NONBLOCK);
        }
        else
        {
                if (! block_mode)
                        fcntl(STDIN_FILENO, F_SETFL, cntl | O_NONBLOCK);
        }
}

I included <fcntl.h> and compiled my code, but I was not able to link it successfully because fcntl() is not defined in libc.

I found another potential way of doing this from the thread entitled "Nios II UART Troubles", but would prefer to handle things with the above routine. Where did the fcntl routine go?

Thanks,

-Mark

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Unfortunately the function fcntl() is not implemented by the Altera HAL. The Altera HAL is a minimal C runtime environment, and so doesn&#39;t support the complete POSIX spec. If you want to use functions like this you will need to use an environment that provides a more comprehensive POSIX implementation. For example both the ucLinux and eCos operating systems contain this function. Both of these are available for download through this forum.

    If you want a single-threaded C runtime environment that includes POSIX file I/O then eCos can be configured in this way (i.e. without a scheduler). That may be an option to consider, depending on your memory budget.

    With the Altera HAL, you will need to set a file descriptor into non-blocking mode at open time.