由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - How difficult is it to write your own sprintf ?
相关主题
fread/fwrite有big/small endian问题吗?下面的code怎么样improve?
大家在linux下面用什么C++的IDE呢?Linus在狗狗能干过jeff dean,我看不一定。。。
准备面试一个java-based position,有什么书推荐一下?groupon都把自己的logo放到vert.x 3的网页上去了
A questionubuntu on windows
Google员工给的api talkBSD expr和GNU expr的不同
bad news:Oracle wins, Google loses in copyright ruling on J (转载)c, socket 问题
选择 WCF 还是 ASP.NET WebApi[转载] 在CGI程序中有何好方法返回HTML
Linux GNU C, readlink问题网络程序问题
相关话题的讨论汇总
话题: sprintf话题: buffered话题: bsd话题: libc话题: write
进入Programming版参与讨论
1 (共1页)
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 ?

1 (共1页)
进入Programming版参与讨论
相关主题
网络程序问题Google员工给的api talk
Refactoring long class step by step (1)bad news:Oracle wins, Google loses in copyright ruling on J (转载)
How to minitor all windows API call for w3wp.exe of IIS?选择 WCF 还是 ASP.NET WebApi
Windows Thread APILinux GNU C, readlink问题
fread/fwrite有big/small endian问题吗?下面的code怎么样improve?
大家在linux下面用什么C++的IDE呢?Linus在狗狗能干过jeff dean,我看不一定。。。
准备面试一个java-based position,有什么书推荐一下?groupon都把自己的logo放到vert.x 3的网页上去了
A questionubuntu on windows
相关话题的讨论汇总
话题: sprintf话题: buffered话题: bsd话题: libc话题: write