which head file define '_IO_*'


 
Thread Tools Search this Thread
Top Forums Programming which head file define '_IO_*'
# 1  
Old 06-04-2009
Question which head file define '_IO_*'

Under Solaris 10,I compile following file,

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));
}

It raise following errors

In function 'pr_stdio':
error:structure has no member named '_IO_file_flags'
error:'_IO_UNBUFFERED' undeclared
error:'_IO_LINE_BUF' undeclared
error:structure has no member named '_IO_buf_end'
error:structure has no member named '_IO_buf_base'

Which head file should I use?

Thanks
# 2  
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question