git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Usermode/init - Fixed bad stderr for 'exec' commands
[tpg/acess2.git]
/
Usermode
/
Applications
/
cat_src
/
main.c
diff --git
a/Usermode/Applications/cat_src/main.c
b/Usermode/Applications/cat_src/main.c
index
9877628
..
45a8d1b
100644
(file)
--- a/
Usermode/Applications/cat_src/main.c
+++ b/
Usermode/Applications/cat_src/main.c
@@
-1,38
+1,38
@@
/*
* Acess2 CAT command
*/
/*
* Acess2 CAT command
*/
-#include <acess/sys.h>
#include <stdlib.h>
#include <stdio.h>
#define BUF_SIZE 1024
#include <stdlib.h>
#include <stdio.h>
#define BUF_SIZE 1024
+/**
+ * \fn int main(int argc, char *argv[])
+ * \brief Entrypoint
+ */
int main(int argc, char *argv[])
{
int main(int argc, char *argv[])
{
- int fd;
- int num;
- char buf[BUF_SIZE+1];
+ size_t num;
+ char buf[BUF_SIZE];
if(argc < 2) {
printf("Usage: cat <file>\n");
return -1;
}
if(argc < 2) {
printf("Usage: cat <file>\n");
return -1;
}
- printf("Contents of `%s'\n", argv[1]);
- fd = open(argv[1], OPENFLAG_READ);
- if(fd == -1) {
+ FILE *fp = fopen(argv[1], "r");
+ if(!fp) {
printf("Unable to open '%s' for reading\n", argv[1]);
return -1;
}
do {
printf("Unable to open '%s' for reading\n", argv[1]);
return -1;
}
do {
- num = read(fd, BUF_SIZE, buf);
- printf("num = %i\n", num);
- buf[num] = '\0';
- printf("%s", buf);
+ num = fread(buf, 1, BUF_SIZE, fp);
+ if(num <= 0) break;
+ fwrite(buf, 1, num, stdout);
} while(num == BUF_SIZE);
} while(num == BUF_SIZE);
-
close(fd
);
+
fclose(fp
);
printf("\n");
return 0;
printf("\n");
return 0;
UCC
git Repository :: git.ucc.asn.au