|
- 这是主函数:
- #include <fcntl.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- int
- main(void)
- {
- int fd;
- ssize_t n;
- char buf[MAXLINE];
- fd=Open("/etc/fstab",O_RDONLY);
- n=Read(fd,buf,MAXLINE);
- Write(stdout,buf,n);
- return(0);
- }
- 以下是Open.c Read.c Write.c 子函数。
- # cat Open.c
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- int
- Open(const char *path,int flags)
- {
- int fd;
- if((fd=open(path,flags))<0) {
- printf("open error\n");
- return(1);
- }
- return(fd);
- }
- # cat Read.c
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #define MAXLINE 8192
- ssize_t
- Read(int fd, void * buf,ssize_t n)
- {
- if((n=read(fd,buf,MAXLINE)) != n ) {
- printf("read error\n");
- return(-1);
- }
- return(n);
- }
- # cat Write.c
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- ssize_t
- Write(int fd,const char *buf,ssize_t n)
- {
- if((n=write(fd,buf,n)) != n) {
- printf("write to stdout error\n");
- return(1);
- }
- return(0);
- }
- 这是Makefile
- # cat Makefile
- f: f.o Open.o Read.o Write.o
- cc f.o Open.o Read.o Write.o -o f
- Open.o: Open.c
- cc -c Open.c
- Read.o: Read.c
- cc -c Read.c
- Write.o: Write.c
- cc -c Write.c
复制代码
以下是出错的信息:
- "Makefile" ,line 2 : Need an operator
- "Makefile" ,line 4 : Need an operator
- "Makefile" ,line 6 : Need an operator
- "Makefile" ,line 8 : Need an operator
- make : fatal errors encountered -- can not conintue
复制代码
是我的程序写错了还是Makfile错了,请指教!谢谢。 |
|