|
|
Jump to this file's LXR Page |
|
|
File: [CENS] / misc / emlog / nbcat.c
(download)
/
(as text)
Revision: 1.1, Mon Aug 13 20:02:40 2001 UTC (8 years, 3 months ago) by jelson Branch: MAIN Added the new nbcat utility |
/*
* nbcat: a simple program similar to 'cat', but which uses
* nonblocking reads.
*
* This utility can be used to copy the current contents of an emlog
* device without blocking to wait for more input. For example:
*
* nbcat /var/log/emlog-device-instance > /tmp/saved-log-file
*
* ...will copy the current contents of the named emlog device to a
* file in /tmp.
*
* This code is freeware and may be distributed without restriction.
*
* Jeremy Elson <jelson@circlemud.org>
* August 11, 2001
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
int main(int argc, char *argv[])
{
int fd, retval;
char buf[4096];
if (argc != 2) {
fprintf(stderr, "usage: %s <filename>\n", argv[0]);
exit(1);
}
if ((fd = open(argv[1], O_RDONLY | O_NONBLOCK)) < 0) {
perror(argv[1]);
exit(1);
}
while ((retval = read(fd, buf, sizeof(buf))) > 0) {
if (write(STDOUT_FILENO, buf, retval) < 0) {
perror("writing to stdout");
break;
}
}
if (retval < 0 && errno != EAGAIN) {
perror(argv[1]);
exit(1);
}
return 0;
}
| CENS CVS Mailing List |
Powered by ViewCVS 0.9.2 |