input buffer settings

This is a discussion on input buffer settings within the Linux Programming forums, part of the Platform Specific Boards category; Hello. Is it possible to disable line buffering on input? Right now i am getchar() on stdin and waiting for ...

  1. #1
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507

    input buffer settings

    Hello. Is it possible to disable line buffering on input? Right now i am getchar() on stdin and waiting for an EOF to terminate input. I only get what is writtin into stdin though on a enter press. How to I read the buffer as it comes in without buffering? Will read() do the trick? Is it the only way to do it?

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    Quote Originally Posted by valaris View Post
    Hello. Is it possible to disable line buffering on input? Right now i am getchar() on stdin and waiting for an EOF to terminate input. I only get what is writtin into stdin though on a enter press. How to I read the buffer as it comes in without buffering? Will read() do the trick? Is it the only way to do it?
    Even read() will not do the trick. The terminal device is line buffered at the driver level. Even if you called setvbuf() to disable the C library's line buffering, the device itself is still line buffered. Disabling the device buffering is an OS-specific operation, i.e. not portable.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    32
    Quote Originally Posted by valaris View Post
    Hello. Is it possible to disable line buffering on input? Right now i am getchar() on stdin and waiting for an EOF to terminate input. I only get what is writtin into stdin though on a enter press. How to I read the buffer as it comes in without buffering? Will read() do the trick? Is it the only way to do it?
    Sure, it is a way - any text editor do it. See 'man termios'. Pay attentiom to the part 'Canonical and non-canonical mode'

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Valery Reznic View Post
    Sure, it is a way - any text editor do it. See 'man termios'. Pay attentiom to the part 'Canonical and non-canonical mode'
    Yes, that will work, and since this is the Linux forum, that is the correct solution. I think brewbuck answered the C programming forum question - in which case the answer is "depends on which OS you have".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    32
    Quote Originally Posted by matsp View Post
    Yes, that will work, and since this is the Linux forum, that is the correct solution. I think brewbuck answered the C programming forum question - in which case the answer is "depends on which OS you have".

    --
    Mats
    I don't think I am follow. Editors works under each operation system and termios is quite standard
    (at least among Unixes). So what is Linux specific here ?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Valery Reznic View Post
    I don't think I am follow. Editors works under each operation system and termios is quite standard
    (at least among Unixes). So what is Linux specific here ?
    It is not, as you say, specific to Linux, but the functionality to do this in for example Windows is quite different. So as long as it is some form of Unix (including Linux and MacOS X), then your answer is correct, but if we wanted code that works in Windows, DOS, OS/2 or some other OS not related to Unix, then we'd need a different function. I'm sure this is what brewbuck was referring to.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Oct 2007
    Posts
    32
    Quote Originally Posted by matsp View Post
    It is not, as you say, specific to Linux, but the functionality to do this in for example Windows is quite different. So as long as it is some form of Unix (including Linux and MacOS X), then your answer is correct, but if we wanted code that works in Windows, DOS, OS/2 or some other OS not related to Unix, then we'd need a different function. I'm sure this is what brewbuck was referring to.

    --
    Mats
    I forget that OS otherthen Unix exist.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. Clearing c++ input buffer
    By mramazing in forum C++ Programming
    Replies: 4
    Last Post: 11-08-2007, 11:05 AM
  3. Trouble with a lab
    By michael- in forum C Programming
    Replies: 18
    Last Post: 12-06-2005, 11:28 PM
  4. Can't seem to come to conclusion : cin.ignore()
    By SkyHi in forum C++ Programming
    Replies: 8
    Last Post: 05-13-2005, 09:57 PM
  5. Writing past ...
    By Ana Val sazi in forum C++ Programming
    Replies: 8
    Last Post: 06-29-2002, 09:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21