Thread: Standard bioskey function

  1. #1
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    138

    Standard bioskey function

    Hi,

    I have faced the following code, can you help me to write a standard version of it:

    Code:
    struct timeval tv;
    
    int bioskey() {
        fd_set readfds;
    
    
        FD_ZERO (&readfds);
        FD_SET (fileno(stdin), &readfds);
        tv.tv_sec=0; tv.tv_usec=0;
        select(16, &readfds, 0, 0, &tv);
    
    
        return (FD_ISSET(fileno(stdin), &readfds));
    }
    I get:

    Code:
    error: call to undeclared function 'fileno';

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Did you "#include <stdio.h>" that declares the function, fileno().
    Last edited by rstanley; 02-03-2024 at 11:34 AM.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You should also read the manual page for select() while you're at it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    138
    I found this from stackoverflow:

    Code:
    int bioskey(void)
    {
        //struct timeval tv = { 0L, 0L };
        fd_set fds;
        FD_ZERO(&fds);
        FD_SET(0, &fds);
        return select(1, &fds, NULL, NULL, &tv) > 0;
    }

  5. #5
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    Depending on your system you may also need to define _POSIX_C_SOURCE before including stdio.h to use fileno:
    Code:
    #define _POSIX_C_SOURCE
    #include <stdio.h>
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function name to wrap the standard strncpy function.
    By stahta01 in forum C Programming
    Replies: 5
    Last Post: 11-07-2014, 12:12 PM
  2. Is there a standard function?
    By frktons in forum C Programming
    Replies: 223
    Last Post: 07-16-2010, 03:31 PM
  3. Is there a standard C function to do this?
    By lucidrave in forum C Programming
    Replies: 9
    Last Post: 08-14-2009, 11:21 PM
  4. bioskey
    By JTtheCPPgod in forum Game Programming
    Replies: 5
    Last Post: 01-18-2002, 09:32 PM
  5. bioskey() - please help me out
    By Leeman_s in forum C++ Programming
    Replies: 1
    Last Post: 12-23-2001, 10:19 AM

Tags for this Thread