s*****w 发帖数: 1527 | 1 i have the task to write the c runtime at work, funny, right ?
anyway, the sprintf() in BSD is way to complicated.
if i write sprintf("%d"), just find the 1st digit, then keep on going.
for %f, i break into 2 parts, say 3.14
1. print 3,
2. for 0.14, i found it has 2 digits after the 0.
so *100, make it 14, then print 14
for %e, can convert to %f
....
what else am i missing ?
why do i need to worry about the buffered io, non-buffered io ?
thanks ! | t****t 发帖数: 6806 | 2 what prevents you from peeking at glibc source?
you don't have to copy it, you can just check what you have missed and/or
what dumb thing you have done.
and why do you care io buffering? for sprintf, you are printing to string.
【在 s*****w 的大作中提到】 : i have the task to write the c runtime at work, funny, right ? : anyway, the sprintf() in BSD is way to complicated. : if i write sprintf("%d"), just find the 1st digit, then keep on going. : for %f, i break into 2 parts, say 3.14 : 1. print 3, : 2. for 0.14, i found it has 2 digits after the 0. : so *100, make it 14, then print 14 : for %e, can convert to %f : .... : what else am i missing ?
| s*****w 发帖数: 1527 | 3 1. i'm trying to port the BSD c runtime to windows,
2 weeks already passed, but no big progress yet.
Too many files. And i only have 4 weeks.
2. From BSD code, i saw the line buffered, fully buffered, none
buffered. So ...
and/or
string.
【在 t****t 的大作中提到】 : what prevents you from peeking at glibc source? : you don't have to copy it, you can just check what you have missed and/or : what dumb thing you have done. : and why do you care io buffering? for sprintf, you are printing to string.
| t****t 发帖数: 6806 | 4 for sprintf, why do you care whether it's BSD or gnu?
for sprintf, why do you care line buffered, fully buffered, non buffered?
the underlying FILE* interface do that.
【在 s*****w 的大作中提到】 : 1. i'm trying to port the BSD c runtime to windows, : 2 weeks already passed, but no big progress yet. : Too many files. And i only have 4 weeks. : 2. From BSD code, i saw the line buffered, fully buffered, none : buffered. So ... : : and/or : string.
| s*****w 发帖数: 1527 | 5 well, this is a commercial product at work, BSD licence is better.
i don't care about if buffered or not, if i can easily port the code to
windows. But remember the file structure etc. is totally different from
unix to windows, so i have to pray to make the file APIs to work in
windows.
Otherwise i want to modify the BSD code to make sprintf to work, in
which case need to understand the code, that brings in the buffered or
not question.
all i given is 4 weeks to port the whole BSD CRT, i wonder how many ppl
can do that, at least i cannot.
buffered?
【在 t****t 的大作中提到】 : for sprintf, why do you care whether it's BSD or gnu? : for sprintf, why do you care line buffered, fully buffered, non buffered? : the underlying FILE* interface do that.
| t****t 发帖数: 6806 | 6 make up your mind first. it seems you are not clear what you are doing.
(a) if you just want to port, or simplify, sprintf() itself, let me reassure
you it is unrelated to buffer, period. no matter what port you use. it does
not even use a FILE*.
(b) if you want to port BSD libc, that's a different story. libc essentially
has two parts: libc(3) and libc(2). libc(2) is kernel API, it's different
from OS to OS. usually each call is a wrapper to corresponding kernel API.
obviously you have to find a similar windows API, and make proxy call; or
you just simulate it. for libc(3), you should be able to use them directly,
minimum porting is needed. sprintf is one of libc(3). you can just copy the
source and it should work. i don't expect you need to "modify" it at all.
(c) if you REALLY want to write your own sprintf (although windows does have
it), and not sure what you have missed (the question in your OP), you can
read (not copy) source from either BSD or GNU to check it. that's unrelated
to license.
(d) PS: the buffered I/O (FILE* interface) is part of libc(3). you can just
use the source and it should work with minimum change, provided you already
ported libc(2).
【在 s*****w 的大作中提到】 : well, this is a commercial product at work, BSD licence is better. : i don't care about if buffered or not, if i can easily port the code to : windows. But remember the file structure etc. is totally different from : unix to windows, so i have to pray to make the file APIs to work in : windows. : Otherwise i want to modify the BSD code to make sprintf to work, in : which case need to understand the code, that brings in the buffered or : not question. : all i given is 4 weeks to port the whole BSD CRT, i wonder how many ppl : can do that, at least i cannot.
| s*****w 发帖数: 1527 | 7 thanks very much for the details !
doing.
reassure
it does
essentially
different
kernel API.
call; or
directly,
copy the
【在 t****t 的大作中提到】 : make up your mind first. it seems you are not clear what you are doing. : (a) if you just want to port, or simplify, sprintf() itself, let me reassure : you it is unrelated to buffer, period. no matter what port you use. it does : not even use a FILE*. : (b) if you want to port BSD libc, that's a different story. libc essentially : has two parts: libc(3) and libc(2). libc(2) is kernel API, it's different : from OS to OS. usually each call is a wrapper to corresponding kernel API. : obviously you have to find a similar windows API, and make proxy call; or : you just simulate it. for libc(3), you should be able to use them directly, : minimum porting is needed. sprintf is one of libc(3). you can just copy the
| j*******d 发帖数: 8834 | 8 time is running short and you're about to get fired....
subcontract the work to me. i can port all func/apis libc(3) for ya for a
fixed $
【在 s*****w 的大作中提到】 : i have the task to write the c runtime at work, funny, right ? : anyway, the sprintf() in BSD is way to complicated. : if i write sprintf("%d"), just find the 1st digit, then keep on going. : for %f, i break into 2 parts, say 3.14 : 1. print 3, : 2. for 0.14, i found it has 2 digits after the 0. : so *100, make it 14, then print 14 : for %e, can convert to %f : .... : what else am i missing ?
|
|