Subject: RE: ber_printf's return type in the C API

From: Gil Kirkpatrick <[email-masked]>
Date: Thu, 5 Aug 1999 17:00:10 -0700

Mark,

There's a coding idion for sprintf() that looks something like this:

char* p = malloc( BIG_ENOUGH );

for( int i = 0; i < 10; i++ )
{
	p += sprintf( p, "%s %d", "foo", i );
}	

I'ts a concise way to effectively concatenate the results of several
sprintfs(). Given that ber_printf() returns -1 instead of 0 on error reduces
the utility of this scheme.

-gil

Gil Kirkpatrick
NetPro
"Kick it, Funky Snowman!" - Calef Brown

> -----Original Message-----
> From:	Hallvard B Furuseth [SMTP:[email-masked]]
> Sent:	Thursday, August 05, 1999 3:32 PM
> To:	Mark Smith
> Cc:	[email-masked]
> Subject:	Re: ber_printf's return type in the C API
> 
> Mark Smith writes:
> > Unless I missed it, the current draft only requires that "ber_printf()
> > returns -1 if there is an error during encoding and a positive number if
> > successful."  Therefore, it is okay to leave the return type as int.  Is
> > it important for the caller to know how many octets were output?
> 
> No, like I said: personally I don't care.
> 
> I was wondering if someone _else_ care, namely the people objected to
> giving ber_printf and ber_scanf the same way to report success/error
> because their used the returned values for something internally in their
> software.  (In fact, that may have been you Netscape people - I don't
> quite remember.)
> 
> -- 
> Hallvard

---

From: [email-masked] (Mark C Smith)
Date: Fri, 06 Aug 1999 10:43:26 -0400

> the utility of this scheme.

I am not sure why it would help much to return 0 instead of -1 on error
(you still need to check for errors, right?).  Anyway, you don't need to
implement a scheme like this with ber_printf() because the current
encoding position and all of the details of memory allocation, etc. are
handled internally by the API implementation.  You can just do something
like this:

    BerElement *ber = ber_alloc_t( LBER_USE_DER );
    if ( NULL == ber ) {
        return( -1 );		/* allocation error */
    } else {
        for ( int i = 0; i < 10; i++ ) {
            if ( ber_printf( ber, "si", "foo", i ) == -1 ) {
                ber_free( ber, 1 );
                return( -1 );   /* encoding error  */
            }
        }
    }
    ...

-- 
Mark Smith
iPlanet Directory Architect / Sun-Netscape Alliance
My words are my own, not my employer's.   Got LDAP?