void client_open(response_t* response,client_t* c,char* name){ int index; pthread_mutex_lock( c->new_account_lock_mutex_ptr); if(*c->accounts_no_ptr == MAX_ACCOUNT){ form_response(response,CANNOT_OPEN,"Database is full."); pthread_mutex_unlock(c->new_account_lock_mutex_ptr); return; }else{ index = search_account(c->accounts,*c->accounts_no_ptr,name); if(index == -1){ account_open(&c->accounts[0],name); }else if(index <= *c->accounts_no_ptr -1){ form_response(response,CANNOT_OPEN,"Account's already created."); pthread_mutex_unlock(c->new_account_lock_mutex_ptr); return; }else{ account_open(&c->accounts[index],name); } (*c->accounts_no_ptr)++; } pthread_mutex_unlock(c->new_account_lock_mutex_ptr); char message [200]; sprintf(message,"Account %s opened",name); form_response(response,SUCCESS,message); }
int getfd(const char *fname) { static char prevfname[PATH_MAX]; static int prevfd = -1; int fd; u64 t1; int onoatime = o_noatime ? O_NOATIME : 0; if(!strcmp(fname, prevfname)) return prevfd; if(o_time) t1 = rtc(); if((fd = open(fname, O_RDONLY|onoatime)) == -1) die("%s: %s\n", fname, strerror(errno)); if(o_time) account_open(t1, rtc()); if(prevfd > 0) close(prevfd); prevfd = fd; strncpy(prevfname, fname, PATH_MAX); return fd; }