FILE* and fd
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > FILE* and fd




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    FILE* and fd  
vineeth


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-24-05 08:48 PM

hi all,
Is there any advantage in using FILE* related api calls instead of
using the file descriptor and related calls like read()?
pls share your ideas.






[ Post a follow-up to this message ]



    Re: FILE* and fd  
Gordon Burditt


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-24-05 08:48 PM

>Is there any advantage in using FILE* related api calls instead of
>using the file descriptor and related calls like read()?
>pls share your ideas.

The use of, say, getc() and putc() calls or other
single-character-at-a-time I/O operations using stdio can be
significantly faster than single-character read() or write() calls.

If you're doing I/O in large blocks anyway, reading and writing in
64k read() or write() calls might be faster than stdio calls (which
might use a buffer like 512 bytes or 4k or 16k).

This can interact with the sector interleave of floppies and hard
disks to the point that writing a whole floppy as a buffered device
can take 1 minute with stdio and over an hour with
single-character-at-a-time write() calls.

Gordon L. Burditt





[ Post a follow-up to this message ]



    Re: FILE* and fd  
Keith Thompson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-24-05 08:48 PM

"vineeth" <nvineeth@gmail.com> writes:
> Is there any advantage in using FILE* related api calls instead of
> using the file descriptor and related calls like read()?
> pls share your ideas.

The FILE* calls are defined by the C language standard.  The calls
using file descriptors are not; they're defined by the POSIX standard.
Code using Unix-style file descriptors is less portable than code that
uses only the standard FILE* interface.

(This may not be relevant if you don't care about portability to
non-Unix system.)

--
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
We must do something.  This is something.  Therefore, we must do this.





[ Post a follow-up to this message ]



    Re: FILE* and fd  
50295@web.de


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-28-05 09:53 PM


Keith Thompson wrote:
> "vineeth" <nvineeth@gmail.com> writes: 
>
> The FILE* calls are defined by the C language standard.  The calls
> using file descriptors are not; they're defined by the POSIX standard.
> Code using Unix-style file descriptors is less portable than code that
> uses only the standard FILE* interface.
>
> (This may not be relevant if you don't care about portability to
> non-Unix system.)

Just a note, the file decriptor is a member of the FILE structure. i.e:


typedef struct  {
unsigned char  *curp;	/* Current active pointer (mandatory) */
unsigned char  *buffer;	/* Data transfer buffer	  (mandatory) */
int             level;	/* fill/empty level of buffer	        */
int             bsize;	/* Buffer size            (mandatory) */
unsigned short  istemp;	/* Temporary file indicator   	  */
unsigned short  flags;	/* File status flags      (mandatory) */
wchar_t         hold;	/* ungetc char if no buffer exists    */
char            fd;		/* FILE DESCRIPTOR        (mandatory) */
unsigned char   token;	/* Used for validity checking 	  */
}   FILE;			      /* This is the FILE type

Even the MSDN has its versions of read(2) and write(2) -- using file
descriptors. See:
_write() : http://tinyurl.com/ddon8
_read()  : http://tinyurl.com/9ju9e






[ Post a follow-up to this message ]



    Re: FILE* and fd  
Lew Pitcher


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-28-05 09:53 PM

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

50295@web.de wrote:
> Keith Thompson wrote:
> 
>
>
> Just a note, the file decriptor is a member of the FILE structure. i.e:

on the platform you got that from.

I can promise you that the FILE structure is not the same on all platforms

> Even the MSDN has its versions of read(2) and write(2) -- using file
> descriptors.

/But/, systems like Z/OS (OS/390, MVS, etc.) /do not/ have file descriptors.

- --
Lew Pitcher
IT Specialist, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

 iD8DBQFDYRxuagVFX4UWr64RAiB3AJ44hHf8vMRM
0Hkg7f1KgWLaXRUpcACfcEdQ
IKh4JFs2vuUo0jH4ZNaVkgs=
=iCat
-----END PGP SIGNATURE-----





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:24 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register