Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #15370
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Ian Collins <ian-news@hotmail.com> |
| Newsgroups | comp.lang.c++ |
| Subject | Re: Best Way to Handle Unknown Data Sizes? |
| Date | Sat, 14 Apr 2012 12:20:41 +1200 |
| Lines | 29 |
| Message-ID | <9uru6qFjbhU6@mid.individual.net> (permalink) |
| References | <MPG.29f25082df0f84119896fd@news.eternal-september.org> <Jeff-Relf.Me@2012_Apr.13^4.04^PM> <Jeff-Relf.Me@2012_Apr.13^5.16^PM> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Trace | individual.net fizi3YCV5xEBUtAc1e/f4gTXZkpsKyLEnlqk+b0wSs09uB/S91 |
| Cancel-Lock | sha1:9hRUNV5ZJ0P5BuGO/R7cko3KAC8= |
| User-Agent | Mozilla/5.0 (X11; SunOS i86pc; rv:7.0.1) Gecko/20111228 Thunderbird/7.0.1 |
| In-Reply-To | <Jeff-Relf.Me@2012_Apr.13^5.16^PM> |
| Xref | csiph.com comp.lang.c++:15370 |
Show key headers only | View raw
On 04/14/12 12:16 PM, @Jeff-Relf.Me wrote:
> [ Reposting; this one uses free(), not realloc() ]
>
> char* Up⋅To⋅LF( char *B⁰ ) {
> // From (B⁰), return a string up to,
> // but not including, any LineFeed ( 10 ).
> //
> // If possible, rewrite this using a temporary heap;
> // so the heap can be destroyed,
> // instead of calling free() and/or realloc().
>
> static int Sz⋅Buff = 1024 ; static char *B¹ ; char *LF; int Len;
>
> if ( LF = strchr( B⁰, 10 ), !LF ) // Do nothing.
> return B⁰ ;
>
> if ( Len = LF - B⁰ + 1, Len > Sz⋅Buff )
> // Free the old buffer, alloc a larger one.
> Sz⋅Buff = Len, free( B¹ ), B¹ = 0 ;
>
> if ( !B¹ ) // Create the buffer.
> B¹ = (char*)malloc( Sz⋅Buff );
>
> sprintf( B¹, "%.*s", --Len, B⁰ ); return B¹; }
What is this nonsense?
--
Ian Collins
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
Best Way to Handle Unknown Data Sizes? mrc2323@cox.net (Mike Copeland) - 2012-04-13 15:03 -0700
Re: Best Way to Handle Unknown Data Sizes? Ian Collins <ian-news@hotmail.com> - 2012-04-14 10:21 +1200
Re: Best Way to Handle Unknown Data Sizes? copx <copx@gazeta.pl> - 2012-04-14 00:38 +0200
Re: Best Way to Handle Unknown Data Sizes? Paavo Helde <myfirstname@osa.pri.ee> - 2012-04-13 17:39 -0500
Re: Best Way to Handle Unknown Data Sizes? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-04-13 22:42 +0000
Re: Best Way to Handle Unknown Data Sizes? red floyd <no.spam.here@its.invalid> - 2012-04-13 16:44 -0700
Best Way to Handle Unknown Data Sizes? @Jeff-Relf.Me - 2012-04-13 16:04 -0700
Best Way to Handle Unknown Data Sizes? @Jeff-Relf.Me - 2012-04-13 17:16 -0700
Re: Best Way to Handle Unknown Data Sizes? Ian Collins <ian-news@hotmail.com> - 2012-04-14 12:20 +1200
csiph-web