CS350 COS
COS
Loading...
Searching...
No Matches
cat.c
Go to the documentation of this file.
1
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <time.h>
6
7// Castor Only
8#include <syscall.h>
9#include <sys/syscall.h>
10#include <sys/dirent.h>
11
12int
13main(int argc, const char *argv[])
14{
15 int i;
16 int status, fd;
17 struct stat sb;
18 char buf[256];
19
20 if (argc < 2) {
21 fputs("Requires an argument\n", stdout);
22 return 1;
23 }
24
25 if (argc > 2) {
26 fputs("Too many arguments, expected one\n", stdout);
27 return 1;
28 }
29
30 status = OSStat(argv[1], &sb);
31 if (status != 0) {
32 fputs("Cannot stat file\n", stdout);
33 return 0;
34 }
35 fd = OSOpen(argv[1], 0);
36 for (i = 0; i < sb.st_size; i += 256) {
37 int len = (sb.st_size - i > 256) ? 256 : (sb.st_size - i);
38
39 OSRead(fd, &buf, i, len);
40 OSWrite(1, &buf, 0, len);
41 }
42
43 return 0;
44}
45
int main(int argc, const char *argv[])
Definition: cat.c:13
static char buf[4096]
Definition: ethdump.c:10
int OSRead(uint64_t fd, void *addr, uint64_t off, uint64_t length)
Definition: syscall.c:59
uint64_t OSOpen(const char *path, uint64_t flags)
Definition: syscall.c:77
int OSWrite(uint64_t fd, const void *addr, uint64_t off, uint64_t length)
Definition: syscall.c:65
int OSStat(const char *path, struct stat *sb)
Definition: syscall.c:89
uint64_t len
Definition: multiboot.h:2
off_t st_size
Definition: stat.h:11
Definition: stat.h:5
int fputs(const char *str, FILE *fh)
Definition: file.c:132
FILE * stdout
Definition: file.c:16