Date: Sat, 12 Aug 2006 07:56:22 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Julian Elischer <julian@elischer.org> Cc: current@freebsd.org Subject: Re: suggested addition to 'date' Message-ID: <20060812045622.GA84354@gothmog.pc> In-Reply-To: <44DD5992.5080409@elischer.org> References: <44DD4510.5070002@elischer.org> <20060812033607.GB80768@gothmog.pc> <44DD50FF.5040406@elischer.org> <20060812041535.GA82669@gothmog.pc> <44DD5992.5080409@elischer.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2006-08-11 21:31, Julian Elischer <julian@elischer.org> wrote: >Giorgos Keramidas wrote: >>On 2006-08-11 20:54, Julian Elischer <julian@elischer.org> wrote: >>> Yes I said I hacked it in :-) >>> In my app you will never have such long lines.. >>> basically you need something that reads lines and tells you how much it >>> read.. >>> (I have no idea WHY fgets need sto return the START.. you already KNOW >>> that!) >>> it'd be nice if you didn't have to to a strlen() on each line. >> >> Perhaps the solution Sam proposed is much better then? >> >>To read one >>character at-a-time and only special-case the '\n' characters? > > I didn't see that being mentionned anywhere, but I guess compared to > running date once for every line > I could live with a strlen(). :-) > it'd probably be more efficient than doing it one char at a time. > > >Maybe something like this? > > > > if (sflag) { > > > > > > > [...] > > > otval = tval; > > } > > (void)printf("%s", buf); > > if (fflush(stdout)) > > > > > > wonder if it would want to be flushed less often if stdout was a file.. > I think stdio would do the right thing in most cases so I guess teh > fflush woudl only be needed at the end, after the last file, > or maybe just on a signal handler so it flushes out the last buffer on ^C IIRC, stdio can buffer more than one line, so now that you mention it, maybe it is a good idea to flush at every '\n' character to make output appear every time there's a complete line ready. I'm too sleepy to run tests now, but if you still want something inside date(1) -- which is probably the only logical place to put it (to let us leverage the date/time formatting code date(1) already has) -- then I can run a few tests during the weekend and see which approach works better, for some definition of `better' :-)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060812045622.GA84354>