主程序main.c:
#include "myfile.h"
#include <errno.h>
int isLogin;
int main()
{
char resbuf[20],ubuf[20],pbuf[20],upath[50];
printf("------File system------\n");
while(!isLogin)
{
printf("1:login form: login [username] [password]\n");
printf("2:regist form: regist [username] [password]\n");
printf("please enter the command:");
scanf("%s %s %s",resbuf,ubuf,pbuf);
if(strcmp(resbuf,"login") == 0)
{
int lres = login(ubuf,pbuf);
if(lres == -1)
{
printf("the user'%s'doesn't exist,please check the information or register\n",ubuf);
continue;
}
else if(lres == 0)
{
printf("password is wrong\n",);
continue;
}
else
{
printf("login successful\n");
isLogin = 1;
sprintf(upath,"/home/lhx/study/kefile/%s/",ubuf);
lres = chdir(ubuf);
if(lres!=0)
{
printf("enter failure\n");
printf("Error:%s\n",strerror(errno));
}
else
{
printf("current directory:%s\n",upath);
}
system("clear");
}
}
else if(strcmp(resbuf,"regist") == 0)
{
int rres = regist(ubuf,pbuf);
if(rres == -1)
{
printf("Registration failed,pleasr try again\n");
}
else
{
printf("Registration success\n");
mkdir(ubuf,