Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion A good gets()
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
CBFalconer  
View profile  
 More options Jun 25 2002, 9:36 pm
Newsgroups: comp.lang.c
From: CBFalconer <cbfalco...@yahoo.com>
Date: Wed, 26 Jun 2002 01:36:42 GMT
Local: Tues, Jun 25 2002 9:36 pm
Subject: Re: A good gets()

Pat Foley wrote:

> CBFalconer <cbfalco...@yahoo.com> writes:

... snip ...

> See, I dunno -- you're trying to devise a library function that's
> idiot-proof? No way. I think you've just replaced one POLA violation
> with another: gets() will cheerfully overrun the buffer passed to it;
> your ggets() will cheerfully use whatever memory it can get its hands
> on. When a simple library function does that I think something's
> wrong.

There is no such thing.  Idiots can always find a way :-)

> [snip]
> > Experiment at your console.  Just hold down some key for input,
> > and see how long a line you can generate from the keyboard.  I am
> > morally certain you will find a limit.

> > /* FILE longline.c */
> > #include <stdio.h>
> > #include <string.h>
> > #include "ggets.h"

> > int main(void)
> > {
> >   char * ln;

> >   ln = ggets();
> >   printf("\nlinelength was %d\n", (int)strlen(ln));
> >   return 0;
> > }

> > On my machine this spat out 127.  First there was much beeping and
> > input was rejected until I finally hit return.  From a file things
> > can get much longer.  When I made a file with 530 a's and a
> > newline, I got back 530 with "longline <longline.txt".  I also
> > tried it on 4 binaries, and never got anything over 5.

> Dude, tell me this is not how you've tested this?! It makes me wonder
> if you've ever actually executed the code for when memory runs out...

Of course not.  That was just something I threw together to
respond to you.  The first level of testing is the design.  After
that - well you can see what I ran if you download the package -
see my website in the sig, download section.

I am planning to change the interface slightly - see Doug Gwynns
comments in c.l.c.moderated.  This will give more detailed error
status and remove the temptation to lose the returned pointer.

    int fggets(char* *line, FILE *f);

with a normal 0 returned, otherwise EOF or positive error
indicator.

... snip ...

> If your argument is that there's almost always a newline at some
> point, all you need is to pass a big enough buffer to gets().

No, that WILL use up all the memory and fail at points that could
have been handled.  There is no such thing as a big enough gets
buffer.  Any machinery is finite and will fail at some point - the
point is how will it fail and what will it take with it.

... snip ...

> I've compiled it & tested it a little, but don't have time at the
> moment to do a proper job. Did you test on files or input with no
> newlines at all? I got no output back at all from tggets. None at
> all. But figuring out why will have to wait until later tonight...

> (I'll also test on input bigger than available memory, so we can
> compare to other approaches.)

See above on the tests.  I welcome the thrashings.

--
Chuck F (cbfalco...@yahoo.com) (cbfalco...@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.