Re: Can we emulate a char buffer to a FILE* ?

Discussion in 'C Programming' started by Malcolm, Jul 7, 2003.

  1. Malcolm

    Malcolm Guest

    "Krishna Reddy Gaddam" <> wrote in message
    >
    > void printDebugInfo(FILE* f, );
    >
    > I have to use this function, However, I want the DebugInfo to filled
    > into my own buffer rather than to a file (f).
    >

    This is an extension I would like to see to the standard library - a
    function that allows you to open your own stream by supplying your own
    fputc() and fgetc() functions. It would be useful for compression and
    encryption, as well as special streams like error logs.
    Unfortunately it is not supported by the standard as is.
     
    Malcolm, Jul 7, 2003
    #1
    1. Advertising

  2. Malcolm

    Chris Torek Guest

    [on generalized stdio "read/write functions under streams"]

    In article <>
    Paul Hsieh <> writes:
    >And its not likely to ever be proposed, or course. The C standards
    >people does not serve the purpose of providing useful functionality
    >in the language. Their only purpose is to rubber stamp the standard
    >practice.


    Actually, the charter is supposedly to include "existing" practice.

    I put a "functional" stdio function (funopen(); it takes pointers
    to four functions -- read, write, seek, and close -- and a fifth
    "cookie" pointer that it passes on to the other four) in the 4.xBSD
    stdio back in 1990 or so, and the same idea now appears, in perhaps
    slightly mutated forms, in versions of the GNU C library, including
    those on Linux. So there was plenty of existing practice to draw
    on for C99.

    The funopen() interface is somewhat klunky to use, but allows you
    do to things like open a "compression" stream that sits on top of
    an "uncompressed" stream, e.g., you can get a stdio "FILE *" object
    that you can write to produce a bzipped file, or use to read a
    bzipped file. The underlying file is yet another stdio "FILE *",
    and when you write to the compression stream, the write function
    compresses and putc()s as needed to the underlying file. Naturally,
    you can stack these as deep as you like (provided you do not run
    out of memory). If you are willing to implement a seek function,
    you can even make stdio streams that are rewind()- and fseek()-able.
    (Any functions you leave out -- read, write, or seek -- cause the
    stream to be unreadable, unwritable, or unseekable, as appropriate.
    If you leave them all out, of course, you get nothing. :) )

    (There are fropen() and fwopen() interfaces for simpler, read-
    and write-only, streams.)

    They took my snprintf() -- complete with "proper" return value
    (some snprintf() variants return the number of bytes written, which
    leaves one guessing how many would have been written had the buffer
    been big enugh), but not my strsep(). I admit a certain degree
    of puzzlement at this, especially since snprintf() is not in the
    reserved namespace, while strsep() is. :)
    --
    In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
    Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
    email: forget about it http://67.40.109.61/torek/index.html (for the moment)
    Reading email is like searching for food in the garbage, thanks to spammers.
     
    Chris Torek, Jul 9, 2003
    #2
    1. Advertising

  3. Malcolm

    Guest

    Chris Torek <> wrote:
    >
    > I put a "functional" stdio function (funopen(); it takes pointers
    > to four functions -- read, write, seek, and close -- and a fifth
    > "cookie" pointer that it passes on to the other four) in the 4.xBSD
    > stdio back in 1990 or so, and the same idea now appears, in perhaps
    > slightly mutated forms, in versions of the GNU C library, including
    > those on Linux. So there was plenty of existing practice to draw
    > on for C99.


    Unfortunately, no one proposed it to the committee.

    -Larry Jones

    But Mom, frogs are our FRIENDS! -- Calvin
     
    , Jul 9, 2003
    #3
  4. Malcolm

    Dan Pop Guest

    In <> Larry Jones <> writes:

    >Dan Pop <> wrote:
    >>
    >> Wasn't the committee supposed to consist of *competent* professionals?

    >
    >No, it consists of people who care enough about C to spend time and
    >money working on standardizing it.


    Well, this explains the actual quality of the C99 standard and its
    current popularity in the computing industry ;-)

    >> Neither the BSD library nor the GNU C library are exotic things, used only
    >> by a couple of gurus on a remote island.

    >
    >They were (relatively speaking) when C99 was under development.


    4.4 BSD was a real thing years before the work on C9x even started.
    glibc2 was released (and immediately adopted by the Linux community) at
    least a couple of years before C99 was finalised.

    So, I'm afraid you're speaking in a far too relative manner.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
     
    Dan Pop, Jul 11, 2003
    #4
  5. Dan Pop wrote:
    > 4.4 BSD was a real thing years before the work on C9x even started.
    > glibc2 was released (and immediately adopted


    glibc2 was not *adopted*, it was a changeling left in the crib. And the
    source of umpteen binary compatibility problems; AAMOF Linux's own kind
    of "DLL Hell".

    > by the Linux community) at
    > least a couple of years before C99 was finalised.
    >
    > So, I'm afraid you're speaking in a far too relative manner.
    >
    > Dan



    --
    Michel Bardiaux
    Peaktime Belgium S.A. Bd. du Souverain, 191 B-1160 Bruxelles
    Tel : +32 2 790.29.41
     
    Michel Bardiaux, Jul 11, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Forty Two

    Can ASP.NET emulate a Telnet host?

    Forty Two, Dec 24, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    4,795
    Forty Two
    Dec 25, 2004
  2. Sathyaish

    char* gets(char* buffer)

    Sathyaish, Oct 5, 2004, in forum: C Programming
    Replies:
    9
    Views:
    442
    CBFalconer
    Oct 5, 2004
  3. lovecreatesbeauty
    Replies:
    1
    Views:
    1,132
    Ian Collins
    May 9, 2006
  4. Eugeny Myunster

    How can i emulate sizeof()

    Eugeny Myunster, Apr 30, 2008, in forum: C Programming
    Replies:
    13
    Views:
    581
    Kenneth Brody
    May 14, 2008
  5. xingye
    Replies:
    9
    Views:
    296
    Michael Lu
    Apr 19, 2004
Loading...

Share This Page