Re: [Libclc-developers] Re: contr.: string function ultostr()
Status: Planning
Brought to you by:
augestad
|
From: Hallvard B F. <h.b...@us...> - 2003-03-19 14:26:45
|
Jan Engelhardt writes: >>> What would happen if size were 2, 1, or even 0? Those are legitimate >>> values. >> >> 2 is OK with that code. 0 and 1 don't need to be, we can document >> that size must be at least 2 and add clc_assert_arg(ultostr, size>1). > > Since SIZE is the length of the /whole/ (incoming) string including \0 (hehe) > we need to substract 2. Which still makes 2 OK. >>I think the output argument should be first, followed by the size >>argument, similar to fread (and strcpy for the output argument). > > Play. Eh? Was that agreement or disagreement? >> You forgot to \0-terminate the output. > Did I? Possibly. I thought the user takes care of that: Oh. I think that's a very bad idea. All other string functions I know return a \0-terminated string, except strncpy which I think everyone agrees is an abomination. >> I'd prefer to get as few digits as possible returned instead of >> '0'-padding the output. Even though this means doing memmove() >> at the end. (Or we could return a pointer into the middle of the >> string, but that invites bugs in the user's program.) > > Strip preceding '0's, that is make them ' '. Otherwise, we would > need to allocate a buffer inside ultostr(), depending on how big > the output will be. No, we just need to do memmove like my posted code did. It writes at the end of the buffer at first, but moves it to the front before returning. This means that part of the buffer 'behind' the returned string in the output buffer is modified, but I don't care. If you don't like that, we can instead generate a reversed string at first (starting from the beginning of the buffer) and reverse it again before returning. >> It shuold fail if the output buffer is too small. >> ... fail with ERANGE? Or is this our chance to invent our first CLC_E* >> code - CLC_ENOSPC "not enough space"? > > ENOSPC is for writing files. CLC_ENOROOM? > Where is the point in choosing between ERANGE and CLC_ERANGE (if such > exists)... I totally wonder about the clc errno code though. I see no point in introducing CLC_ERANGE, since the standard specifies that ERANGE must exist. We only need CLC_ codes for meanings that the standard does not define. > BTW: Most mailing-list-readers (at least, mine) does, when I hit > reply, want to compose a message to the author who wrote it, plus a CC > to li...@sf.... I would like to send the msgs to li...@sf... only, If you mean the list should generate 'reply-to: <list>', I disagree. Then I can't easily sent private replies when that's what I want. > as otherwise I get 2x the same message for no reason. TIA Log in with [Edit Options] at the bottom of http://lists.sourceforge.net/lists/listinfo/libclc-developers with the address you are subscribed as, and turn off 'Receive posts you send to the list'. -- Hallvard |