⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login_assist.c

📁 多用户银行系统
💻 C
字号:
#include <sys/ipc.h>#include <sys/mman.h>#include <sys/sem.h>#include <unistd.h>#include <sys/types.h>#include <signal.h>#include <stdio.h>#include <stddef.h>#include "../include/stddef.h"#include "../include/structs.h"#include "../include/tools.h"SHM *shm;//void init_semaphore_struct(struct sembuf *sem,int semnum,//int semop,int semflg)//{	/* ........ *///	sem->sem_num=semnum;//	sem->sem_op=semop;//	sem->sem_flg=semflg;//}/*int getInput(USER *user){	char *s;		char c;	char *p;	int i = 0;	p = user->name;	while(1){  		system("clear");		printf("Name :");		while(1){			if( ((c = getchar()) != '\n') && ((p - user->name) < MAX_SIZE) ){				*p ++ = c;				continue;			}			break;		}		*p = '\0';		s = getpass("Password:");		p = user->pwd;		while(1){			if( i < strlen(s) && ((p - user->pwd) < MAX_SIZE)){				*(p + i) = *(s + i); 				i ++;				continue;			}			break;		}		*(p + i + 1) = '\0';		break;	}	printf("getinput() is over ... \n");			return OK;};*/int getInput(USER *user){	system("clear");	printf("Name : ");	scanf("%s" , user->name);	printf("Passwd : ");	scanf("%s" , user->pwd);			getchar();	return OK;};int readFile(char *guibuf){	FILE *fp;	char c;	int i = 0;	//fp = fopen(GUIFILE , "r");		fp = fopen("/home/lastbank/file/guifile" , "r");	if(!fp){				printf("file error!\n");		return EFILE;		}	while((c = fgetc(fp)) != EOF){		*(guibuf + i) = c;				i ++;	}	*(guibuf + i + 1) = '\0';	printf("after readFile...\n");	fclose(fp);	return OK;};int showGUI(char *guibuf){	printf("%s\n" , guibuf);		return OK;};/*void * getSHM(){	void *p;	void *tmp;	key_t key;	int shmid;			key = KEY;	shmid = shmget(key , 0 , 0);	p = shmat(shmid , NULL , 0);	tmp = p;	while(1){		if(p - tmp >= SHM_SIZE)return NULL;			if(*((int *)p) == 0){			*((int *)p) = 1;			p += sizeof(int);			return (void *)p;			}if(*((int*)p) == 1){			p += sizeof(int);			p += sizeof(SHM);				continue;		}	}	};int freeSHM(void *p){	*( (int *)(p - sizeof(int)) ) = 0;	return 1;};*/int getChoice(char *oper){	char *s = oper;	char c;	printf("please intput your choice : ");	while(1){		c = getchar();		if( c != '\n' && ((s - oper) < OPER_SIZE)){			*s ++ = c;				continue;		}else{			if(c  == '\n'){				break;					}			else {				continue;			}		}	}		*s = '\0';	return OK;};int getInfo(char *oper){	if(strcmp(oper , "changpwd") == 0){		//_changepwd();	}if(strcmp(oper , "save") == 0){		//_save();		}if(strcmp(oper , "transfer") == 0){		//!trans();		}if(strcmp(oper , "draw") == 0){		//_draw();		}	return OK;	};/*int execute_(char *oper){	extern SHM *shm;	char *s;	s = (char *)malloc(sizeof(char) * 11);	char c;	int i = 0;	if(strcmp(oper , "save") == 0){		strcpy(shm->mark , "save");		printf("input your name :");		while(1){			c = getchar();			if( c != '\n' && i < 10){				*s ++ = c;				continue;					}else{				if(c == '\n')break;				else continue;				}				}		*s = '\0';		//scanf("%s" , s);		strcpy(shm->chara , s);		printf("input your password :");		//	scanf("%s" , s);		i = 0;		while(1){			c = getchar();			if( c != '\n' && i < 10){				*s ++ = c;				continue;			}else{				if(c == '\n')break;				else continue;			}		}		*s = '\0';		strcpy(shm->charb , s);				printf("shm->spid : %d\n" , shm->spid);		//kill(28543 , SIGRQST);		kill(shm->spid , SIGRQST);		//sigqueue(shm->spid , SIGRQST , sv.sival_int);				printf("have send signal to server ...\n");	}	};*/int getStr(char *str , int max){	char *s;	char c;	int i = 0;	s = str;		while(1){		c = getchar();		if(c != '\n' && i < max - 1){			*s ++ = c;			continue;			}else{			if(c == '\n')break;			else continue;			}			*s = '\0';	}	return OK;};int execute(int index , char *oper){		union sigval mysigval;	if(strcmp(oper , "quit") == 0 || strcmp(oper , "exit") == 0){		freeSHM(index);		exit(0);			system("logout");	}	getInfo(oper);// get user's input	mysigval.sival_int = index;	if(sigqueue((shm->swap_arr)[0].swap.spid,SIGRQST,mysigval)==-1)		printf("send error\n");	return OK;	};int identify(USER *user){        USER usr;        FILE *fp;        if( (fp = fopen("/home/lastbank/pwdfile", "r")) == NULL){                printf("pwdfile open error....\n");                exit(0);        }        while(! fread(&usr, sizeof(USER), 1, fp)){		if(strcmp(usr.name , user->name) == 0){			if(strcmp(usr.pwd , user->pwd) == 0)				return OK;			else{				return EPWD;				}			}	}	return ENAME;};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -