On Friday 28 March 2008 20:03, James Simmons wrote:
> 
> Hi!
> 
>   I needed cat to read until a eof or read would block. I have a 
> patch that does a work around but I don't feel that is the right
> approach. Especially since it is not a standard cat option.
> Anyway to have that happen?

blocking.c
==========
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
        fcntl(0, F_SETFL, fcntl(0, F_GETFL) & ~O_NONBLOCK);
        return 0;
}

nonblocking.c
=============
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
        fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
        return 0;
}

Usage:

# { echo TEST; sleep 1; } | { ./nonblocking; cat; ./blocking; } >result
cat: read error: Resource temporarily unavailable

and file "result" contains "TEST", as expected.
--
vda
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to