BarryServer : Git

All the code for all my projects
// BarryServer : Git / OrionUserland / blob / f8ba6df5ab36d7554d045837b3f053ab6db75e5d / cat / main.c

// Related

OrionUserland

Barry Removing binaries f8ba6df (2 years, 4 months ago)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include <dirent.h>

#define BUF_SIZE (4096 * 4)

/* Main function */
int
main(int argc, char *argv[])
{
	int fd, sz, i;
	char buf[BUF_SIZE];

	if (argc < 2) {
		printf("Usage: %s <file> [<file>...]\n");
		return 0;
	}

	for (i = 1; i < argc; i++) {
		fd = open(argv[i], O_RDONLY);
		if (fd < 0) {
			printf("%s: %s: ", argv[0], argv[i]);
			perror(NULL);
			continue;
		}

		while ((sz = read(fd, buf, sizeof(buf))) > 0) {
			if (write(STDOUT_FILENO, buf, sz) < 0) {
				printf("%s: write: ", argv[0]);
				perror(NULL);
			}
		}
		if (sz < 0) {
			printf("%s: read: ", argv[0]);
			perror(NULL);
		}

		close(fd);
	}

	return 0;
}