Issue
I'm trying to implement ps command in xv6 (adding system call), I have followed the process of making one and in the end while using the command "make qemu-nox" to finally test the system call i get the following errors
gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie -no-pie -c -o cat.o cat.c
cat.c: In function ‘cps’:
cat.c:9:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
9 | {
| ^
cat.c:23:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
23 | {
| ^
In file included from cat.c:3:
user.h:26:5: error: old-style parameter declarations in prototyped function definition
26 | int cps(void)
| ^~~
cat.c:40: error: expected ‘{’ at end of input
40 | }
|
cat.c:40: error: control reaches end of non-void function [-Werror=return-type]
40 | }
|
cc1: all warnings being treated as errors
make: *** [<builtin>: cat.o] Error 1
This is the cat.c file, everything seems fine but i don't understand why is it showing errors
#include "types.h"
#include "stat.h"
#include "user.h"
char buf[512];
void
cat(int fd)
{
int n;
while((n = read(fd, buf, sizeof(buf))) > 0) {
if (write(1, buf, n) != n) {
printf(1, "cat: write error\n");
exit();
}
}
if(n < 0){
printf(1, "cat: read error\n");
exit();
}
}
int
main(int argc, char *argv[])
{
int fd, i;
if(argc <= 1){
cat(0);
exit();
}
for(i = 1; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
printf(1, "cat: cannot open %s\n", argv[i]);
exit();
}
cat(fd);
close(fd);
}
exit();
}
Solution
The compiler is claiming that you're in a function named "cps()" on line 9 of your file cat.c, which is obviously not what that function is named. It's also complaining about an issue in user.h itself. This is the clue that the problem is not directly in your cat.c file, but somewhere in the headers it is including (probably in user.h).
Answered By - Peter Maydell
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.