Commit ea8ae751 authored by Roshan Rabinarayan's avatar Roshan Rabinarayan

bug fix :killed the bug

parent 42ebcadf
...@@ -71,7 +71,7 @@ int file_get(char *key, char *value) ...@@ -71,7 +71,7 @@ int file_get(char *key, char *value)
/* Does not depend on key argument */ /* Does not depend on key argument */
int found =0; int found =0;
int index=modulus(key,256,setSize); int index=modulus(key,strlen(key),setSize);
lseek(fds[index],0,SEEK_SET); lseek(fds[index],0,SEEK_SET);
sem_wait(&readerLocks[index]); sem_wait(&readerLocks[index]);
readCounters[index]+=1; readCounters[index]+=1;
...@@ -122,6 +122,7 @@ off_t file_put(char *key,char *value) ...@@ -122,6 +122,7 @@ off_t file_put(char *key,char *value)
{ {
char *fkey=strtok(line,":"); char *fkey=strtok(line,":");
char *fvalue=strtok(NULL,":"); char *fvalue=strtok(NULL,":");
printf("key:(%s)(%s)\n",fkey,key);
if(strcmp(key,fkey)==0){ if(strcmp(key,fkey)==0){
if(strcmp(value,strtok(fvalue,"\n"))==0) if(strcmp(value,strtok(fvalue,"\n"))==0)
{ {
...@@ -131,11 +132,11 @@ off_t file_put(char *key,char *value) ...@@ -131,11 +132,11 @@ off_t file_put(char *key,char *value)
} }
else else
{ {
printf("key:(%s)(%s)\n",fkey,key);
printf("value:(%s)(%s)\n",fvalue,value); printf("value:(%s)(%s)\n",fvalue,value);
fflush(stdout); fflush(stdout);
fseek(fp,position,SEEK_SET); fseek(fp,position,SEEK_SET);
snprintf(lin, strlen(key)+strlen(value)+2,"%s:%s\n",key,value); snprintf(lin, sizeof(lin),"%s:%s\n",key,value);
if(fputs(lin,fp)<0) if(fputs(lin,fp)<0)
printf("\n[unable to perform file_put]\n"); printf("\n[unable to perform file_put]\n");
return 0; return 0;
...@@ -187,7 +188,9 @@ int main() ...@@ -187,7 +188,9 @@ int main()
readCounters[i]=0; readCounters[i]=0;
} }
//offset = file_put("24", "value245"); //offset = file_put("24", "value245");
offset = file_put("23", "value28"); offset = file_put("24", "value1");
file_put("29","update2");
file_put("28","update2");
//file_get(prevkey, value); // Doesnot depend on key arg, returns key and value at offset 0 //file_get(prevkey, value); // Doesnot depend on key arg, returns key and value at offset 0
//printf("(%s)", value); //printf("(%s)", value);
//file_del("29"); //file_del("29");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment