[haiku-commits] Re: r37697 - in haiku/trunk: headers/os/locale src/kits/locale

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 22 Jul 2010 20:37:52 +0200

On 2010-07-22 at 18:36:37 [+0200], pulkomandy@xxxxxxxxxxxxxxxxx wrote:
> -void
> +status_t
>  BCountry::FormatDate(char* string, size_t maxSize, time_t time, bool 
>  longFormat)
>  {
>      BString fullString;
> -    FormatDate(&fullString, time, longFormat);
> -    strncpy(string, fullString.String(), maxSize);
> +    status_t returnCode;
> +    returnCode = FormatDate(&fullString, time, longFormat);
> +    if (returnCode == B_OK)
> +        strncpy(string, fullString.String(), maxSize);
> +    return returnCode;
>  }

That seems a bit unhandy to use. I guess it would be nicer to always return 
some string -- possibly an unlocalized one or, when running out of options, 
an empty one -- so that the caller doesn't have to do error handling in 
cases where nothing else can be done anyway (e.g. when displaying the 
string in a GUI).

strncpy() has a suboptimal semantics and strlcpy() should be used instead. 
That aside, how about a ByteSink that directly uses the provided buffer? 
That would make the allocation of the BString superfluous.

CU, Ingo

Other related posts: