K&R - FILE structure - can't access members


 
Thread Tools Search this Thread
Top Forums Programming K&R - FILE structure - can't access members
# 1  
Old 01-23-2011
K&R - FILE structure - can't access members

Hi!

I'm on section 8.5., implementation of fopen(). I can't access members of the FILE structure, my compiler simply doesn't recognize them, along with some other things, like flags. According to K&R, all these elements should be defined in <stdio.h>.

Any suggestions?
p.s. I'm using Ubuntu.
# 2  
Old 01-23-2011
The reason for your inability is because it's designed to prevent you from doing so. That structure's opaque and system-dependent.

K&R's utterly ancient, that implementation probably has little to nothing in common with yours now, aside from actually having an fopen().
# 3  
Old 01-23-2011
So, if some value is opaque, there is no way we can directly access it?
# 4  
Old 01-23-2011
Opaque means the header file just defines it as a 'struct FILE'. It won't complain about the incomplete definition when you use it as FILE *, since it never needs to know its size or its members to pass it around in that fashion.

You could dig into the source code of glibc and find out where it really is defined, and typecast a FILE * into a pointer to a structure you define yourself. Remember though, the reason you're not supposed to do this is because

1) This will break if you move this code to another platform. We've had people bring code depending on this from Solaris and wonder why it doesn't work in Linux when it says IN THE CODE 'platform dependent'.
2) This could easily break when you update glibc, too.
3) Modifying the contents of this structure may have unforeseen consequences.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 01-25-2011
I found this recent thread:

unix.com/programming/150687-file-structure-stdio-h.html

It describes a problem very similar to mine, so I just wanted to post it here.

=================

I'm currently examining stdio.h on Ubuntu, and I found the following:

struct _IO_FILE;

typedef struct _IO_FILE FILE;

typedef struct _IO_FILE __FILE;

Also there is (among others) #include <libio.h>, and in it there is

struct _IO_FILE;

I've tried looking into most of the other headers included in stdio.h, but I just can't find the definition of _IO_FILE anywhere.
# 6  
Old 01-25-2011
In GNU/Linux the definition is in the libio.h header. As Corona688 said, it is not a portable documented structure.
This User Gave Thanks to fpmurphy For This Post:
# 7  
Old 01-25-2011
I beg your pardon, the structure IS defined. Smilie

Things make sense one againSmilie

Thank you for your help, gentleman.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

New to Forum & Sun Surefire V210 Access

Purchased a Sun Surefire V210 Server off eBay. Unable to Access the Terminal Mode via the Terminal MGT. Using Windows 7 home, and downloaded the ConEmu. The ConEmu brings up a Command line on the PC, and that's it. Being new to all this, I was expecting a Login prompt to pop up. Read the... (22 Replies)
Discussion started by: screenprintr
22 Replies

2. Solaris

Restricting commands & access

Dear all, I am administering a DC environment of over 100+ Solaris servers used by various teams including Databases. Every user created on the node belonging to databases is assigned group staff(10) . I want that all users belonging to staff should NOT be able to execute certain system... (6 Replies)
Discussion started by: Junaid Subhani
6 Replies

3. Shell Programming and Scripting

Concatenating contents of a file with members in a directory

Hi, I have a unix file with the below structure - CustId1 CustName1 CustPhn1 /u/home/xmldata/A000001 CustId2 CustName2 CustPhn2 /u/home/xmldata/A000002 CustId3 CustName3 CustPhn3 /u/home/xmldata/A000003 Then I have another unix directory /u/home/xmldata This directory has... (3 Replies)
Discussion started by: Simanto
3 Replies

4. AIX

Switch Port Becoming Private & restricting access

Hello folks, I have an AIX server that is connected to a storage array via a Brocade switch using 4 ports from either side. The zoning is done such that there are 4 paths visible from the server to the storage. My work involves frequent disabling or enabling the switch ports that are... (1 Reply)
Discussion started by: nkiran
1 Replies

5. Shell Programming and Scripting

directory structure & file permisson comparison

Hi - I want to compare permissions of the directory structure and files beneath it with permissions one week back on same directory structure and files beneath it. if any changes to permissions of any file or directory permissions send an email. I am not sure how to list the permissions of all... (1 Reply)
Discussion started by: oraclermanpt
1 Replies

6. Linux

password hardening & FTP access

I am dealing with an FTP server and I have implemented password hardening on the server. The thing is that, it applies to SSH connection. I forcefully expired password of a user so that he can change password at next login. But the user logged in to the server through FTP and he wasn't asked to... (4 Replies)
Discussion started by: parth_buch
4 Replies

7. Shell Programming and Scripting

Move files & folder structure

Hey, this might be a really basic question, but I'm new to Unix scripting. I'm trying to find a command to replicate a file structure from one location to another & move the actual files contained in the base directories, i.e. I have this structure - home/temp/test/dir1/ ... (3 Replies)
Discussion started by: SOCLA_CELT
3 Replies

8. Programming

Search attributes in one structure using the values from another structure

Hello Groups I am trying to find out ways of comparing a value from a 'c' structure to a value in another 'C' structure. the 'C' structure can be a List or liked list as it contains lot many records. if we loop it in both the structures it is going to consume time. I am looking for a simple... (3 Replies)
Discussion started by: dhanamurthy
3 Replies

9. UNIX for Dummies Questions & Answers

FTP access & control question

Folks; I need some help with these: 1. understanding how to control access rights and manage visibility using FTP in Solaris, in other words, I need to use FTP in Solaris to be able to give some users access to add/modify data to/from the UNIX server. 2. How can i control the space allowed for... (2 Replies)
Discussion started by: Katkota
2 Replies
Login or Register to Ask a Question