|
我搞了一段helloworld的驱动,在linux下能加载成功,下面是测试驱动的代码
#include
#include
#include
#include
#include
#include
#include
int main()
{printf("Content-type:text/html\n\n");
int fd,i,nwrite,nread;
char *buf="hello\n";
char read_buf[6]={0};
fd=open("/dev/qudong",O_RDWR);
printf("%d",fd); //输出结果为3
if(fd<=0)
{perror("open");exit(1);}
else
printf("open success\n");
nwrite=write(fd,buf,strlen(buf));
printf("%d",nwrite); //输出结果为6
if(nwrite<0)
{perror("write");
exit(1);}
nread=read(fd,read_buf,6);
if(nread<0){perror("read");exit(1);}
else
printf("read is %s\n",read_buf);
close(fd);
exit(0);
}最后运行结果为:3open success 6 read is hello
我想把这段程序编译成cgi程序:
#include
#include
#include
#include
#include
#include
#include
int main()
{printf("Content-type:text/html\n\n");
int fd,i,nwrite,nread;
char *buf="hello\n";
char read_buf[6]={0};
printf("");
fd=open("/dev/qudong",O_RDWR);
printf("%d",fd); //在网页中输出为-1
if(fd<=0)
{perror("open");exit(1);}
else
printf("open success\n");
nwrite=write(fd,buf,strlen(buf));
printf("%d",nwrite); //在网页中输出为-1
if(nwrite==-1)nwrite=6;
if(nwrite<0)
{perror("write");
exit(1);}
nread=read(fd,read_buf,6);
if(nread<0){perror("read");exit(1);}
else
printf("read is %s\n",read_buf);
close(fd);
printf("");
exit(0);
}
放到服务器boa后在网页中输出的是:-1
执行./*.cgi时输出的内容和测试时一样
哪位高手给指点下啊~~~~~~~~~
|
|