Date: Fri, 1 Sep 2006 13:54:29 -0700 From: Ted Faber <faber@ISI.EDU> To: Julian Elischer <julian@elischer.org> Cc: freebsd-current@freebsd.org, Oliver Fromme <olli@lurza.secnetix.de> Subject: Re: suggested addition to 'date' Message-ID: <20060901205429.GF20006@hut.isi.edu> In-Reply-To: <44F892AE.8040409@elischer.org> References: <200609011707.k81H7Ych050627@lurza.secnetix.de> <44F892AE.8040409@elischer.org>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --] On Fri, Sep 01, 2006 at 01:06:06PM -0700, Julian Elischer wrote: > Oliver Fromme wrote: > > >Julian Elischer wrote: > >> Oliver Fromme wrote: > >> > John Baldwin wrote: > >> > > Oliver Fromme wrote: > >> > > > There's another possibility, which doesn't require a new > >> > > > option letter at all. You could add a new escape sequence > >> > > > to the format string, e.g. "%*". Whenever date(1) is > >> > > > called with a format string containing that sequence, it > >> > > > goes into filter mode and replaces the sequence with the > >> > > > current line. That would also enable you to be more > >> > > > flexible with the placement of the timestamps. > >> > > > For example: > >> > > > > >> > > > $ printf 'foo\nbar\nbaz\n' | date +'%H:%M:%S %*' > >> > > > 16:39:58 foo > >> > > > 16:39:58 bar > >> > > > 16:39:58 baz > >> > > > >> > > I prefer this of all the suggestions so far. > >> > > >> > It's not very difficult, so I created a patch which does > >> > exactly that (includes an addition for the manpage, too). > >> > I've submitted it as bin/102609: > >> > > >> > http://www.freebsd.org/cgi/query-pr.cgi?pr=102609 > >> > >> A couple of comments: > >> > >> you don't need to run strftime for each line if the time hasn't changed. > >> (My original patch checks this) > > > >Good idea. I'll update the patch. > > > >> What is the effective maximum line length for a single fgetln? > > > >It's unlimited. fgetln() allocates sufficient amount of > >memory dynamically, that's why I used it instead of fgets(). > >It avoids reinventing the wheel. > > > > > > NOTHING is unlimitted. > what happens with a 3GB sequence of characters with no newlines? $ man fgetln [ ... ] The fgetln() function may also fail and set errno for any of the errors specified for the routines fflush(3), malloc(3), read(2), stat(2), or realloc(3). [...] Looking at realloc, it sounds like you'll either get a 3GB string or NULL and ENOMEM in errno. -- Ted Faber http://www.isi.edu/~faber PGP: http://www.isi.edu/~faber/pubkeys.asc Unexpected attachment on this mail? See http://www.isi.edu/~faber/FAQ.html#SIG [-- Attachment #2 --] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (FreeBSD) iD8DBQFE+J4EaUz3f+Zf+XsRAu4/AKDSp2uRCEp1g32e2sOgKOa/grh/DACghkWg jO4PYBn50HBE0Ow88B0zzhA= =pFp9 -----END PGP SIGNATURE-----help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060901205429.GF20006>
