Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #9794

Re: Function to determine the number of chars in a FILE buffer

From Ike Naar <ike@iceland.freeshell.org>
Newsgroups comp.lang.c
Subject Re: Function to determine the number of chars in a FILE buffer
Date 2011-09-01 04:37 +0000
Organization A noiseless patient Spider
Message-ID <slrn3vfsj5u2vk.hmv.ike@iceland.freeshell.org> (permalink)
References <5303ab8c-2dca-4c04-bb88-49e26fc92f96@n11g2000yqh.googlegroups.com>

Show all headers | View raw


On 2011-08-31, tm <thomas.mertes@gmx.at> wrote:
> int inputReady (FILE *aFile)
>   {
>     int file_no;
>     int nfds;
>     fd_set readfds;
>     struct timeval timeout;
>     int select_result;
>     int result;
>
>   /* inputReady */
>     file_no = fileno(aFile);
>     if (file_no != -1) {
>       FD_ZERO(&readfds);
>       FD_SET(file_no, &readfds);
>       nfds = (int) file_no + 1;
>       timeout.tv_sec = 0;
>       timeout.tv_usec = 0;
>       /* printf("select(%d, %d)\n", nfds, file_no); */
>       select_result = select(nfds, &readfds, NULL, NULL, &timeout);
>       /* printf("select_result: %d\n", select_result); */
>       if (unlikely(select_result < 0)) {
>         raise_error(FILE_ERROR);
>         result = 0;
>       } else {
>         result = FD_ISSET(file_no, &readfds);
>       } /* if */
>     } else {
>       raise_error(FILE_ERROR);
>       result = 0;
>     } /* if */
>     /* printf("filInputReady --> %d\n", result); */
>     return result;
>   } /* inputReady */
>
> This function does not work correctly: It may return 0 although
> a getc() would not block.

Input may have arrived between the moment you called select()
and the moment you call getc().

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Function to determine the number of chars in a FILE buffer tm <thomas.mertes@gmx.at> - 2011-08-31 15:43 -0700
  Re: Function to determine the number of chars in a FILE buffer James Kuyper <jameskuyper@verizon.net> - 2011-08-31 18:56 -0400
    Re: Function to determine the number of chars in a FILE buffer Angel <angel+news@spamcop.net> - 2011-09-01 06:25 +0000
      Re: Function to determine the number of chars in a FILE buffer tm <thomas.mertes@gmx.at> - 2011-09-01 00:23 -0700
        Re: Function to determine the number of chars in a FILE buffer Robert Wessel <robertwessel2@yahoo.com> - 2011-09-01 03:27 -0500
        Re: Function to determine the number of chars in a FILE buffer James Kuyper <jameskuyper@verizon.net> - 2011-09-01 06:58 -0400
          Re: Function to determine the number of chars in a FILE buffer Keith Thompson <kst-u@mib.org> - 2011-09-01 08:29 -0700
        Re: Function to determine the number of chars in a FILE buffer Kenneth Brody <kenbrody@spamcop.net> - 2011-09-01 14:37 -0400
        Re: Function to determine the number of chars in a FILE buffer gordonb.nfrza@burditt.org (Gordon Burditt) - 2011-09-02 21:58 -0500
    Re: Function to determine the number of chars in a FILE buffer tm <thomas.mertes@gmx.at> - 2011-08-31 23:54 -0700
      Re: Function to determine the number of chars in a FILE buffer Jasen Betts <jasen@xnet.co.nz> - 2011-09-01 11:02 +0000
        Re: Function to determine the number of chars in a FILE buffer tm <thomas.mertes@gmx.at> - 2011-09-01 05:44 -0700
      Re: Function to determine the number of chars in a FILE buffer David Schwartz <davids@webmaster.com> - 2011-09-01 04:41 -0700
  Re: Function to determine the number of chars in a FILE buffer Ike Naar <ike@iceland.freeshell.org> - 2011-09-01 04:37 +0000
  Re: Function to determine the number of chars in a FILE buffer Mark Storkamp <mstorkamp@yahoo.com> - 2011-09-01 08:23 -0500

csiph-web