client/profile.c
int login_profile(char *pass, struct profile *prof) {
	int exist = user_exist();
	if(exist == -1) {
		perror("error finding user file");
		return -1;
	}
	if(exist == 0) {
		return register_profile(pass, prof);
	}

	int prmpt_ps = 0;

	if(pass == NULL) {
		prmpt_ps = 1;
		pass = line_prompt("password", NULL, 1);
		if(pass == NULL) {
			perror("failed to read password");
			return -1;
		}
	}

	if(prmpt_ps) {
		prof->pass = pass;
	} else {
		prof->pass = strdup(pass);
		if(prof->pass == NULL) {
			perror("failed to duplicate password");
			return -1;
		}
	}

	int ret;
	if((ret = read_userfile(prof)) != 0) {
		ERR("failed to read userfile: %d", ret);
		goto err;
	}

	return 0;
err:
	zfree(prof->pass, strlen(prof->pass));
	return -1;
}
/* the pointers can be left as null to prompt for them */
the pointers can be left as null to prompt for them
the pointers can be left as null to prompt for them
int login_profile(char *pass, struct profile *prof) {
	int exist = user_exist();
	if(exist == -1) {
		perror("error finding user file");
		return -1;
	}
	if(exist == 0) {
		return register_profile(pass, prof);
	}
	int prmpt_ps = 0;
	if(pass == NULL) {
		prmpt_ps = 1;
		pass = line_prompt("password", NULL, 1);
		if(pass == NULL) {
			perror("failed to read password");
			return -1;
		}
	}
	if(prmpt_ps) {
		prof->pass = pass;
	} else {
		prof->pass = strdup(pass);
		if(prof->pass == NULL) {
			perror("failed to duplicate password");
			return -1;
		}
	}
	int ret;
	if((ret = read_userfile(prof)) != 0) {
		ERR("failed to read userfile: %d", ret);
		goto err;
	}
	return 0;
err:
	zfree(prof->pass, strlen(prof->pass));
	return -1;
}
int login_profile ( char * pass , struct profile * prof ) { int exist = user_exist ( ) ; if ( exist == -1 ) { perror ( " " ) ; return -1 ; } if ( exist == 0 ) { return register_profile ( pass , prof ) ; } int prmpt_ps = 0 ; if ( pass == NULL ) { prmpt_ps = 1 ; pass = line_prompt ( " " , NULL , 1 ) ; if ( pass == NULL ) { perror ( " " ) ; return -1 ; } } if ( prmpt_ps ) { prof -> pass = pass ; } else { prof -> pass = strdup ( pass ) ; if ( prof -> pass == NULL ) { perror ( " " ) ; return -1 ; } } int ret ; if ( ( ret = read_userfile ( prof ) ) != 0 ) { ERR ( " " , ret ) ; goto err ; } return 0 ; err : zfree ( prof -> pass , strlen ( prof -> pass ) ) ; return -1 ; }
the pointers can be left as null to prompt for them
the pointers can be left as null to prompt for them