Re: [dev] [sbase] printf(1)

From: William Giokas <>
Date: Wed, 18 Dec 2013 21:06:08 -0600

On Wed, Dec 18, 2013 at 11:36:12PM +0100, Maurice Quennet wrote:
> Hello dev_AT_,
> I was searching for a programming project so I looked into TODO and
> picked printf. I hacked something up a few weeks ago, but I didn't
> publish it until now, since I didn't have a man page yet and I was a
> little busy (a patch follows at the end of the mail).
> In the following I will tell a little bit about my implementation and
> point out differences to OpenBSD's printf implementation (since I am a
> OpenBSD user):
> First for my `algorithm': There is nothing much to say. My
> implementation simply skips through the format string until it finds a
> '\' or a '%' and prints everything before that character. If a '\' was
> found, the appropriate escape sequence is printed. If a '%' was found,
> it skips forward until it finds a supported conversion specifier, and
> passes everything starting from the '%' up until that point to printf(3)
> (plus the approprietly converted command line argument).
> And now for the differences: For a large part my implementation is
> similar to OpenBSD's version. Both support the same escape sequences,
> flags and conversion specifiers (which, as far as tested, behave the
> same). The major difference is error handling. While OpenBSD's version
> prints a warning to stderr and continues parsing its input, my version
> exits immediately. Also, my implementation does not check the syntax of
> the conversion specifier flags, but simply skips over them.
> This is for the following two reasons:
> 1.) printf(1) is mostly used for shell scripting, so I think it is ok to
> expect the user to pass a well formed format string and to check his
> arguments. Even if using a POSIX compliant printf(1), if you put in
> garbage you will in return get garbage (or at least not what you
> expected to get).
> 2.) This way of error handling makes the code simpler/shorter.
> For the man page: well, I really suck at writing man pages, especially
> since my english is quite shaky. Also, while writing the man page, I
> was wondering if it wasn't possible to simply use OpenBSD's man page
> (with a few modifications) since both implementations seem to be largely
> equivalent.
> I have the feeling that I forgot to mention something, but, well, it
> probably will come up again. Anyways I hope you like it.
> Best regards,
> Maurice Quennet

People on this list need to learn about 'git format-patch' and 'git

William Giokas | KaiSforza |
GnuPG Key: 0x73CD09CF
Fingerprint: F73F 50EF BBE2 9846 8306  E6B8 6902 06D8 73CD 09CF

Received on Thu Dec 19 2013 - 04:06:08 CET

This archive was generated by hypermail 2.3.0 : Thu Dec 19 2013 - 04:12:08 CET