CGIコンパイルができない
Posted: 2012年2月02日(木) 13:08
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
#include <time.h>
void showimg(char []);
int main(void)
{
int no;
char *imgfile[] = {"img1.jpg","img2.jpg","img3.jpg"};
srand((unsigned int)time(NULL));
no = rand() % 3;
printf("Content-type: image/jpeg\n\n");
showimg(imgfile[no]);
return 0;
}
void showimg(char imgfile[])
{
FILE *fp;
char buf[1024];
int i, size;
fp = fopen(imgfile, "rb");
if(fp != NULL) {
_setmode(_fileno(stdout), _O_BINARY);
while((size = fread( buf, sizeof(unsigned char), 1024, fp )) != 0) {
for(i = 0 ; i < size ; i++) {
printf("%c", buf);
}
}
fclose(fp);
fflush(stdout);
_setmode(_fileno(stdout), _O_TEXT);
}
}
画像をランダムに表示させるCGIでコンパイルをしたのですがio.hが見当たらないとエラーが出てします。コンパイルはsentOSで画像などもカレントディレクトリにちゃんと入ってあります。
おそらくio.hが通ってない、存在しないからだと思います、io.hを使わないで実行ファイルを作りたいのですがいろいろやってみてダメでした。
半分あきらめモードですがどなたかお教えください
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
#include <time.h>
void showimg(char []);
int main(void)
{
int no;
char *imgfile[] = {"img1.jpg","img2.jpg","img3.jpg"};
srand((unsigned int)time(NULL));
no = rand() % 3;
printf("Content-type: image/jpeg\n\n");
showimg(imgfile[no]);
return 0;
}
void showimg(char imgfile[])
{
FILE *fp;
char buf[1024];
int i, size;
fp = fopen(imgfile, "rb");
if(fp != NULL) {
_setmode(_fileno(stdout), _O_BINARY);
while((size = fread( buf, sizeof(unsigned char), 1024, fp )) != 0) {
for(i = 0 ; i < size ; i++) {
printf("%c", buf);
}
}
fclose(fp);
fflush(stdout);
_setmode(_fileno(stdout), _O_TEXT);
}
}
画像をランダムに表示させるCGIでコンパイルをしたのですがio.hが見当たらないとエラーが出てします。コンパイルはsentOSで画像などもカレントディレクトリにちゃんと入ってあります。
おそらくio.hが通ってない、存在しないからだと思います、io.hを使わないで実行ファイルを作りたいのですがいろいろやってみてダメでした。
半分あきらめモードですがどなたかお教えください