mirror of https://git.qorg11.net/k9core.git
cat: ignore -u and - can be used for stdin
This commit is contained in:
parent
8627b3bf15
commit
36f49ec406
20
src/cat.c
20
src/cat.c
|
@ -6,17 +6,20 @@
|
|||
#include <string.h>
|
||||
|
||||
int
|
||||
cat(int fd,const char *filename)
|
||||
cat(int fd, const char *filename)
|
||||
{
|
||||
int c;
|
||||
char buf[8192];
|
||||
|
||||
if (filename[0] == '-')
|
||||
fd = 0;
|
||||
|
||||
if(fd != 0)
|
||||
fd = open(filename, O_RDONLY);
|
||||
|
||||
if (fd == -1)
|
||||
fprintf(stderr,"error opening %s: %s\n",filename,strerror(errno));
|
||||
|
||||
|
||||
while((c = read(fd,buf,sizeof(buf))) > 0)
|
||||
write(1,buf,c);
|
||||
close(fd);
|
||||
|
@ -25,14 +28,11 @@ cat(int fd,const char *filename)
|
|||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
if(argc == 1)
|
||||
cat(0,NULL);
|
||||
else for(int i = optind; i<argc;i++)
|
||||
{
|
||||
int c = getopt(argc, argv, "u");
|
||||
cat(1,argv[i]);
|
||||
}
|
||||
int c = getopt(argc,argv,"u");
|
||||
if (argc == optind)
|
||||
cat(0,"-");
|
||||
for(int i = optind; i<argc;i++)
|
||||
cat(1,argv[i]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue