forked from himcc/cchttpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Init.cpp
41 lines (40 loc) · 828 Bytes
/
Init.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include"Init.h"
void getport(char * s)
{
sscanf(s,"%d",&port);
if(port<=0)
{
printf("port error\n");
exit(0);
}
}
void getpwd(char * s)
{
if(s[0]!='/')
sprintf(pwd,"%s/%s",getenv("PWD"),s);
else sprintf(pwd,"%s",s);
File f(pwd);
if( f.fok && f.rok && f.xok && (!f.isfile)) return;
strcpy(pwd,getenv("PWD"));
}
void getnotf(char * s)
{
if(s[0]!='/')
sprintf(notf,"%s/%s",getenv("PWD"),s);
else sprintf(notf,"%s",s);
File f(notf);
if( f.fok && f.xok && f.isfile) return;
notf[0]=0;
}
void init(int argc,char ** argv)
{
port=pwd[0]=notf[0]=0;
strcpy(pwd,getenv("PWD"));
if(argv[0][0]!='/')
sprintf(order,"%s/%s",pwd,argv[0]);
else sprintf(order,"%s",argv[0]);
if(argc==1) {printf("port error\n");exit(0);}
if(argc>=2) getport(argv[1]);
if(argc>=3) getpwd(argv[2]);
if(argc>=4) getnotf(argv[3]);
}