Sponsored Content
Full Discussion: unbuffered streams.
Top Forums Programming unbuffered streams. Post 79329 by gandhevinod on Wednesday 27th of July 2005 04:32:41 AM
Old 07-27-2005
unbuffered streams.

#include "../ourhdr.h"

int main(void)
{
int c;
char *buf;
setvbuf(stdin,buf,_IONBF,10);
setvbuf(stdout,buf,_IONBF,10);
while((c=getc(stdin)) != EOF)
{
if(putc(c,stdout) == EOF)
err_sys("output error");
}
if (ferror(stdin))
err_sys("input error");
exit(0);
}


for the above program i expected following output.
$> ./a.out
hh
(user input is in black colour and output is indicated in blue colour)
but the output is coming after pressing return key

h<return-key>
h

see in the above code i made stdin and stdout as unbuffered streams..

so can anyone explain why the output is coming after pressing return key..
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

STREAMS

Hi Everyone I am building some A Class HP boxes as web proxy servers, have just installed HP-UX 11.00 and am starting to configure one according to our standard build policy. However on the A Class I just happened to place the software depot this error message keeps popping up every 2 mins: ... (1 Reply)
Discussion started by: alwayslearningunix
1 Replies

2. UNIX for Advanced & Expert Users

Transparent ioctls Streams calls

What are transparent ioctls messages and when and why we have to issue copyin or copyout kernel utilities with respect to ioctls calls to a Stream. (2 Replies)
Discussion started by: S.P.Prasad
2 Replies

3. Shell Programming and Scripting

Help capturing and reformatting buffered and unbuffered output

Ok, so I have a shell script which runs a specific command, and that command sends it's output to the display. At certain times, the command sends buffered output, and at other times, the command sends unbuffered output in the form of a % progress bar, so if I run the command, the output I receive... (0 Replies)
Discussion started by: vikingshelmut
0 Replies

4. SCO

WARNING: No Memory for Streams (NSTRPAGES)

Anybody have a clue what might have caused the Failures under Class 6? I did a reboot and so far so good, I had been up for about 55 days prior to the reboot. I'm running SCO_SV rel 3.2v5.0.7. Steve #netstat -m streams... (1 Reply)
Discussion started by: Steve_93630
1 Replies

5. Shell Programming and Scripting

Problem with pipes on infinite streams

Here is an example code that shows the issue I have: #!/bin/bash counter() { seq 1000 | while read NUM; do echo $NUM echo "debug: $NUM" >&2 sleep 0.1 # slow it down so we know when this loop really ends done } counter | grep --line-buffered "" | head -n1 ... (10 Replies)
Discussion started by: tokland
10 Replies

6. AIX

AIX STREAMS driver question

Hi all, I have a AIX kernel STREAMS question need your help, I need to implement a firewall on AIX and get packet raw data then decide pass or drop it, I've seen similiar firewall code on HP-UX, on HP-UX, you have to implement a "dlpi STREAMS driver", and specify it as a "dlpi" driver in... (1 Reply)
Discussion started by: rocktilldie
1 Replies

7. Programming

Why must flush all line-buffered output streams?

Hi, Mentioned in Stevens & Rago "Advanced Programming in the UNIX" I don't understand why must flush all line-buffered output streams when (a)an unbuffered or (b)a line-buffered stream require data from kernel? (2 Replies)
Discussion started by: Edward114
2 Replies

8. Homework & Coursework Questions

grep Simulation Using Only Unbuffered I/O - C

1. The problem statement, all variables and given/known data: Basically, I'm trying to search for a particular string pattern within a text file and print "textfile: line_no line". I need to read this in line at a time, but I'm restricted to using unbuffered I/O functions. I'm not sure if I'm... (3 Replies)
Discussion started by: jdkirby
3 Replies

9. Shell Programming and Scripting

AWK Too many open streams to print/printf

hallow all i need your advice about this script i have script like this: INDEX=/zpool1/NFS/INDEX/${1} SCRIPT=/zpool1/NFS/script/${1} LIST=SAMPLE cd ${SCRIPT} for i in `cat ${LIST}` do GETDATE=`echo ${i}|awk '{print substr($1,9,8)}'` /usr/xpg4/bin/awk -F ":" '{close(f);f=$4}{print >>... (4 Replies)
Discussion started by: zvtral
4 Replies
SETBUF(3)						   BSD Library Functions Manual 						 SETBUF(3)

NAME
setbuf, setbuffer, setlinebuf, setvbuf -- stream buffering operations LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <stdio.h> void setbuf(FILE * restrict stream, char * restrict buf); void setbuffer(FILE *stream, char *buf, int size); int setlinebuf(FILE *stream); int setvbuf(FILE * restrict stream, char * restrict buf, int mode, size_t size); DESCRIPTION
The three types of buffering available are unbuffered, block buffered, and line buffered. When an output stream is unbuffered, information appears on the destination file or terminal as soon as written; when it is block buffered many characters are saved up and written as a block; when it is line buffered characters are saved up until a newline is output or input is read from any stream attached to a terminal device (typically stdin). The function fflush(3) may be used to force the block out early. (See fclose(3).) Normally all files are block buffered. When the first I/O operation occurs on a file, malloc(3) is called, and an optimally-sized buffer is obtained. If a stream refers to a terminal (as stdout normally does) it is line buffered. The standard error stream stderr is always unbuffered. Note that these defaults may be altered using the stdbuf(1) utility. The setvbuf() function may be used to alter the buffering behavior of a stream. The mode argument must be one of the following three macros: _IONBF unbuffered _IOLBF line buffered _IOFBF fully buffered The size argument may be given as zero to obtain deferred optimal-size buffer allocation as usual. If it is not zero, then except for unbuffered files, the buf argument should point to a buffer at least size bytes long; this buffer will be used instead of the current buffer. If buf is not NULL, it is the caller's responsibility to free(3) this buffer after closing the stream. (If the size argument is not zero but buf is NULL, a buffer of the given size will be allocated immediately, and released on close. This is an extension to ANSI C; portable code should use a size of 0 with any NULL buffer.) The setvbuf() function may be used at any time, but may have peculiar side effects (such as discarding input or flushing output) if the stream is ``active''. Portable applications should call it only once on any given stream, and before any I/O is performed. The other three calls are, in effect, simply aliases for calls to setvbuf(). Except for the lack of a return value, the setbuf() function is exactly equivalent to the call setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ); The setbuffer() function is the same, except that the size of the buffer is up to the caller, rather than being determined by the default BUFSIZ. The setlinebuf() function is exactly equivalent to the call: setvbuf(stream, (char *)NULL, _IOLBF, 0); RETURN VALUES
The setvbuf() function returns 0 on success, or EOF if the request cannot be honored (note that the stream is still functional in this case). The setlinebuf() function returns what the equivalent setvbuf() would have returned. SEE ALSO
stdbuf(1), fclose(3), fopen(3), fread(3), malloc(3), printf(3), puts(3) STANDARDS
The setbuf() and setvbuf() functions conform to ISO/IEC 9899:1990 (``ISO C90''). BUGS
setbuf() usually uses a suboptimal buffer size and should be avoided. BSD
February 18, 2013 BSD
All times are GMT -4. The time now is 10:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy