Files
uiuc-ece391-mp3/syscalls/ece391cat.c
ece391staff 7fc79b62ed MP3 Release
2018-10-15 13:22:04 -05:00

33 lines
612 B
C

#include <stdint.h>
#include "ece391support.h"
#include "ece391syscall.h"
int main ()
{
int32_t fd, cnt;
uint8_t buf[1024];
if (0 != ece391_getargs (buf, 1024)) {
ece391_fdputs (1, (uint8_t*)"could not read arguments\n");
return 3;
}
if (-1 == (fd = ece391_open (buf))) {
ece391_fdputs (1, (uint8_t*)"file not found\n");
return 2;
}
while (0 != (cnt = ece391_read (fd, buf, 1024))) {
if (-1 == cnt) {
ece391_fdputs (1, (uint8_t*)"file read failed\n");
return 3;
}
if (-1 == ece391_write (1, buf, cnt))
return 3;
}
return 0;
}