Squash commits for public release
This commit is contained in:
5
userland/utilities/cat/.info.mk
Normal file
5
userland/utilities/cat/.info.mk
Normal file
@@ -0,0 +1,5 @@
|
||||
APPS += CAT
|
||||
|
||||
CAT_NAME = cat
|
||||
CAT_LIBS = c
|
||||
CAT_INSTALL_PATH = bin/
|
||||
8
userland/utilities/cat/BUILD.gn
Normal file
8
userland/utilities/cat/BUILD.gn
Normal file
@@ -0,0 +1,8 @@
|
||||
import("//build/userland/TEMPLATE.gni")
|
||||
|
||||
xOS_executable("cat") {
|
||||
install_path = "bin/"
|
||||
sources = [ "main.c" ]
|
||||
configs = [ "//build/userland:userland_flags" ]
|
||||
deplibs = [ "libc" ]
|
||||
}
|
||||
37
userland/utilities/cat/main.c
Normal file
37
userland/utilities/cat/main.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define BUF_SIZE 512
|
||||
char buf[BUF_SIZE];
|
||||
|
||||
void cat(int fd)
|
||||
{
|
||||
int n = 0;
|
||||
while ((n = read(fd, buf, sizeof(buf))) > 0) {
|
||||
if (fwrite(buf, n, 1, stdout) != n) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int fd, i;
|
||||
|
||||
if (argc <= 1) {
|
||||
cat(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if ((fd = open(argv[i], O_RDONLY)) < 0) {
|
||||
printf("cat: cannot open %s\n", argv[i]);
|
||||
return 1;
|
||||
}
|
||||
cat(fd);
|
||||
close(fd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user