Re: Built-in printf Sits Awkwardly with UDP.

2011-07-25 Thread Chet Ramey
On 7/25/11 8:49 AM, Ralph Corderoy wrote: > I also get, with vanilla 4.2 built from source, > > $ ./install/bin/bash -c "printf '%*q.\n' 10 foo -20 bar 0x8000" >foo. > bar . > Segmentation fault (core dumped) > $ Thanks for the report. That's a d

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-25 Thread Ralph Corderoy
Hi Chet, > On 7/22/11 10:38 AM, Ralph Corderoy wrote: > > On a related note, I can't interrupt this, e.g. Ctrl-C. > > > > printf '%-92233720368547758q.\n' foo > > That's interesting, since the fieldwidth (and precision) end up > getting set to 0 if they overflow INT_MAX, at least on my machi

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-24 Thread Chet Ramey
On 7/22/11 10:38 AM, Ralph Corderoy wrote: >> OK, well for %b and %q bash's built-in printf calls it's own >> printstr() and that does do things like `fw = -fw' without checking if >> fw was already the largest negative. > > On a related note, I can't interrupt this, e.g. Ctrl-C. > > printf '

Re: bug#9129: Built-in printf Sits Awkwardly with UDP.

2011-07-24 Thread Chet Ramey
On 7/22/11 12:32 PM, Ralph Corderoy wrote: > Hi Jim, > >>> On 07/20/2011 07:34 AM, Ralph Corderoy wrote: BTW, the code for the built-in printf has a bug. For negative field-widths it negates a negative integer without checking it will fit. E.g. on this 64-bit machine

Re: bug#9129: Built-in printf Sits Awkwardly with UDP.

2011-07-22 Thread Ralph Corderoy
Hi Jim, > > On 07/20/2011 07:34 AM, Ralph Corderoy wrote: > > > BTW, the code for the built-in printf has a bug. For negative > > > field-widths it negates a negative integer without checking it > > > will fit. E.g. on this 64-bit machine > > > > > > $ printf '%-9223372036854775808s.\n' foo

Re: bug#9129: Built-in printf Sits Awkwardly with UDP.

2011-07-22 Thread Jim Meyering
retitle 9129 printf: RFE: reject field width larger than INT_MAX tags 9129 notabug thanks Eric Blake wrote: > [adding coreutils] > > On 07/20/2011 07:34 AM, Ralph Corderoy wrote: >> BTW, the code for the built-in printf has a bug. For negative >> field-widths it negates a negative integer without

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-22 Thread Ralph Corderoy
> OK, well for %b and %q bash's built-in printf calls it's own > printstr() and that does do things like `fw = -fw' without checking if > fw was already the largest negative. On a related note, I can't interrupt this, e.g. Ctrl-C. printf '%-92233720368547758q.\n' foo Cheers, Ralph. P.S. Pl

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-22 Thread Ralph Corderoy
Hi André, > > When printf is finished the buffer is flushed, e.g. if there's > > anything in it then write(2) is called. > > If standard output is a log file, log entries could remain latent for > a very long time. I don't see why. I'm not asking for buffering across multiple calls to the built

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-21 Thread Ben Pfaff
Andre Majorel writes: > On 2011-07-20 14:34 +0100, Ralph Corderoy wrote: > If standard output is a log file, log entries could remain > latent for a very long time. > > The buffering mode we really want is buffered with a forced > flush at reasonable intervals, E.G. one second after the last > wr

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-21 Thread Andre Majorel
On 2011-07-20 14:34 +0100, Ralph Corderoy wrote: > No. Here's my understanding of how it currently works. The built-in > printf works out a character to print at a time; no foresight needed or > used. It asks the C library to print it with putchar(3). The C library > can implement buffering t

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-20 Thread Ralph Corderoy
Hi Eric, > > $ printf '%-9223372036854775808s.\n' foo > > foo. > > $ > > Coreutils' printf shares this misfortune. Sadly, it might even be a > bug in the underlying glibc printf(), although I haven't tried to > write a test program to check that, yet. OK, well for %b and %q bash'

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-20 Thread Eric Blake
[adding coreutils] On 07/20/2011 07:34 AM, Ralph Corderoy wrote: BTW, the code for the built-in printf has a bug. For negative field-widths it negates a negative integer without checking it will fit. E.g. on this 64-bit machine $ printf '%-9223372036854775808s.\n' foo foo. $ C

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-20 Thread Ralph Corderoy
Hi Bob, > Ralph Corderoy wrote: > > ... But a regular file ./foo on disk does look different and it > > still seems odd that > > printf '\n\n\n\n\n\n\n\n\n\n\n\n' >foo > > does a dozen one-byte write(2)s. > > But the only reason you know that there is a long string of newlines > is that your

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-19 Thread Bob Proulx
Ralph Corderoy wrote: > ... But a regular file ./foo on disk does look different and it > still seems odd that > printf '\n\n\n\n\n\n\n\n\n\n\n\n' >foo > does a dozen one-byte write(2)s. But the only reason you know that there is a long string of newlines is that your eye is looking over the

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-19 Thread Chet Ramey
> > Almost exactly right, except replace "unbuffered" with "line-buffered > > output". Bash uses stdio and sets stdout and stderr to line-buffered. > > The advantage of fully-buffered mode shows itself when writing large > > amounts of data, which the shell does not do very often. The > > advanta

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-19 Thread Ralph Corderoy
Hi Chet, > > I see why it's line-buffered when writing to a terminal, but when > > bash changes where stdout points it has the option to setvbuf(3) or > > similar too based on what it knows about the destination, e.g. > > /dev/pts/3 versus /tmp/foo versus /dev/udp/0x7f01/4242. Does it > > nev

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-18 Thread Ralph Corderoy
Hi Chet, > > On 7/18/2011 10:14 AM, Ralph Corderoy wrote: > > > Is this happening because the built-in printf is using putchar(3) > > > in the PC() macro and stdio thinks file descriptor 1 is still to a > > > tty so it's persisting in line buffering? It would seem nicer if > > > fewer write(2)s w

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-18 Thread Chet Ramey
On 7/18/11 10:46 AM, Steven W. Orr wrote: > On 7/18/2011 10:14 AM, Ralph Corderoy wrote: >> Hi, >> >> (I'm not subscribed to the list so please keep me CC'd.) >> >> Consider >> >> printf 'foo bar\n'>/dev/udp/localhost/4242 >> >> with bash's printf built-in, it works fine. One packet is sent.

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-18 Thread Sven Mascheck
On Mon, Jul 18, 2011 at 10:46:19AM -0400, Steven W. Orr wrote: > On 7/18/2011 10:14 AM, Ralph Corderoy wrote: >> printf 'foo\nbar\n'>/dev/udp/localhost/4242 >> >> and two packets are sent, one per line. If the aim is to send a string >> of data in one packet this causes problems. >> >> Using

Re: Built-in printf Sits Awkwardly with UDP.

2011-07-18 Thread Steven W. Orr
On 7/18/2011 10:14 AM, Ralph Corderoy wrote: Hi, (I'm not subscribed to the list so please keep me CC'd.) Consider printf 'foo bar\n'>/dev/udp/localhost/4242 with bash's printf built-in, it works fine. One packet is sent. However, make that two lines printf 'foo\nbar\n'>/dev/udp/l

Built-in printf Sits Awkwardly with UDP.

2011-07-18 Thread Ralph Corderoy
Hi, (I'm not subscribed to the list so please keep me CC'd.) Consider printf 'foo bar\n' >/dev/udp/localhost/4242 with bash's printf built-in, it works fine. One packet is sent. However, make that two lines printf 'foo\nbar\n' >/dev/udp/localhost/4242 and two packets are sent, one pe