Sponsored Content
Top Forums Programming which head file define '_IO_*' Post 302322791 by Corona688 on Thursday 4th of June 2009 02:54:43 PM
Old 06-04-2009
Code:
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/termios.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>	
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>	
#define _IO_UNBUFFERED	__SNBF
#define _IO_LINE_BUF	__SLBF
#define _IO_file_flags	_flags
#define BUFFERSZ(fp)	(fp)->_bf._size
void	pr_stdio(const char *, FILE *);

int
main(void)
{
   FILE	*fp;

  fputs("enter any character\n", stdout);
  if (getchar() == EOF)
	err_sys("getchar error");
  fputs("one line to standard error\n", stderr);

  pr_stdio("stdin",  stdin);
  pr_stdio("stdout", stdout);
  pr_stdio("stderr", stderr);

  if ((fp = fopen("/etc/motd", "r")) == NULL)
	err_sys("fopen error");
  if (getc(fp) == EOF)
	err_sys("getc error");
  pr_stdio("/etc/motd", fp);
	exit(0);
}

void pr_stdio(const char *name, FILE *fp)
{
	printf("stream = %s, ", name);

	/*
	 * The following is nonportable.
	 */
	if (fp->_IO_file_flags & _IO_UNBUFFERED)
		printf("unbuffered");
	else if (fp->_IO_file_flags & _IO_LINE_BUF)
		printf("line buffered");
	else /* if neither of above */
		printf("fully buffered");
	printf(", buffer size = %d\n", BUFFERSZ(fp));
}

You're not supposed, and almost always can't, access the members of a FILE * structure. Its exact contents are platform and implementation specific. The code you were given will only work on the exact same implementation of stdio it was written to work with.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

printing first n lines in a file without using head

i have to print first n lines of a file. how can i do that without using head command. for some reason i do not want to use Head. is there a way to get that result using awk or sed?. i an using this on korn shell for AIX Thanks.. (7 Replies)
Discussion started by: dareman123
7 Replies

2. Shell Programming and Scripting

Problem in define cpu in Rules file

i try to install solaris OS in M4000 using OK prompts by boot net . in my rules file i define the cpus like below probe cpus probe networks networks 2 && cpus 8-10 && disksize c0t0d0 100000-292000 && disksize c0t1d0 100000-292000 && memsize 16384 && model SUNW,SPARC-Enterprise... (0 Replies)
Discussion started by: neruppu
0 Replies

3. Programming

which head file for major and minor function?

#include <sys/types.h> #include <sys/stat.h> #include <sys/termios.h> #include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <string.h> #include <unistd.h> #include <signal.h> #include <sys/mkdev.h> int main(int argc, char *argv) { int i; struct stat buf; ... (4 Replies)
Discussion started by: konvalo
4 Replies

4. Shell Programming and Scripting

head command with more than one file

Hi, I have the following problem. I have files with one column of data (let's say file1.dat, file2.dat...file6.dat), and I would like to record the first value of the column of each file into another file (let's name it fileall.dat), which would have the the six values, one in each column. I use to... (4 Replies)
Discussion started by: josegr
4 Replies

5. UNIX for Advanced & Expert Users

does head create new file

hi, Here my doubt is can we create a file using head/tail command in unix. for example: my file consists 2000 lines , i want to cut it into 2. does this work please give correct command line. head -1000 abc.txt > acd.txt tail -1000 abc.txt > bdc.txt hi, Here my doubt is can we... (5 Replies)
Discussion started by: chittisri
5 Replies

6. Shell Programming and Scripting

appending the count of line in each file at head of each file

hello everybody, I have some files in directory.each file contain some data. my requirement is add the count of each line of file in head of each file. any advice !!!!!!!! (4 Replies)
Discussion started by: abhigrkist
4 Replies

7. Shell Programming and Scripting

How can i get the head of file while using awk?

Hi All, I'm a newbie here, I'm just wondering how can i get the head of my file while using awk? input data: nik1,nik2,nik3 nik2,nik3,nik4 nik3,nik4,nik5 expected output is: nik1 because it is in the top and it is in the first delimeted. i tried awk -F "," '{print $1}' but i... (2 Replies)
Discussion started by: nikki1200
2 Replies

8. Shell Programming and Scripting

Define variable from file.

HI I have file A.txt _1A _2A _3A _4A I want define all as different variable. $1A=_1A $2B=_2A $3C=_3A $4D=_4A Now i can use any variable in my script. (3 Replies)
Discussion started by: pareshkp
3 Replies

9. UNIX for Dummies Questions & Answers

Rsync whole folder and head of each file

Hello, I am trying to backup the whole folder which contains years of data and huge size, some files are > 10GB. I want keep the exact organization of the folder, except that for bigger file only part of it (say head -50, or simply only the name of the file) will be kept. Then the structure of the... (2 Replies)
Discussion started by: yifangt
2 Replies

10. Shell Programming and Scripting

Using input from one file to define scope of other file in Linux

Hi, I have two files A and B and would like to use A as a filter. Like this: File A.txt: Contains a list of IP addresses, each one occurring only once and in order: 10.0.0.1 10.0.0.2 10.0.0.4 10.0.0.8 File B.txt: Contains the same IP addresses with a corresponding ping time each (in... (16 Replies)
Discussion started by: Zooma
16 Replies
setbuf(3s)																setbuf(3s)

Name
       setbuf, setbuffer, setlinebuf, setvbuf - assign buffering to a stream

Syntax
       #include <stdio.h>

       void setbuf(stream, buf)
       FILE *stream;
       char *buf;

       void setbuffer(stream, buf, size)
       FILE *stream;
       char *buf;
       int size;

       void setlinebuf(stream)
       FILE *stream;

       int setvbuf(stream, buf, type, size)
       FILE *stream;
       char *buf;
       int type; 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 new line is encountered or input is read from stdin.	The routine may be
       used to force the block out early.  Normally all files are block buffered.  For further information, see A buffer is obtained from upon the
       first  or  on  the  file.   If  the  standard stream stdout refers to a terminal it is line buffered.  The standard stream stderr is always
       unbuffered.

       The routine is used after a stream has been opened but before it is read or written.  The character array buf is used instead of  an  auto-
       matically  allocated  buffer.  If buf is the constant pointer NULL, input/output will be completely unbuffered.	A manifest constant BUFSIZ
       tells how big an array is needed:
       char buf[BUFSIZ];

       The routine, an alternate form of is used after a stream has been opened but before it is read or written.  The character array	buf  whose
       size  is  determined  by  the  size  argument  is  used instead of an automatically allocated buffer.  If buf is the constant pointer NULL,
       input/output will be completely unbuffered.

       The routine is used to change stdout or stderr from block buffered or unbuffered to line buffered.  Unlike and it can be used at  any  time
       that the file descriptor is active.

       The  routine  may  be  used  after a stream has been opened but before it is read or written.  Type determines how stream will be buffered.
       Legal values for type, defined in stdio.h are:

	_IOFBF	      causes input/output to be fully buffered.

	_IOLBF	      causes output to be line buffered; the buffer will be flushed when a new line is written, the buffer is full,  or  input	is
		      requested.

	_IONBF	      causes input/output to be completely unbuffered.

       If  buf is not the NULL pointer, the array it points to will be used for buffering, instead of an automatically allocated buffer.  The size
       specifies the size of the buffer to be used.  The constant BUFSIZ in <stdio.h> is suggested as a good  buffer  size.   If  input/output	is
       unbuffered, buf and size are ignored.

       By default, output to a terminal is line buffered and all other input/output is fully buffered.

       A  file	can be changed from unbuffered or line buffered to block buffered by using For further information, see A file can be changed from
       block buffered or line buffered to unbuffered by using followed by with a buffer argument of NULL.

Restrictions
       The standard error stream should be line buffered by default.

       The and functions are not portable to non 4.2 BSD versions of UNIX.

See Also
       malloc(3), fclose(3s), fopen(3s), fread(3s), getc(3s), printf(3s), putc(3s), puts(3s).

																	setbuf(3s)
All times are GMT -4. The time now is 10:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy