Commit 4f004cad authored by Roshan Rabinarayan's avatar Roshan Rabinarayan

reset the file pointer to start

parent 2ac11a25
...@@ -33,7 +33,7 @@ unsigned modulus( unsigned char *num, size_t size, unsigned divisor) { ...@@ -33,7 +33,7 @@ unsigned modulus( unsigned char *num, size_t size, unsigned divisor) {
void file_del( char *key) void file_del( char *key)
{ {
int index=modulus(key,256,setSize); int index=modulus(key,256,setSize);
fflush(stdout); lseek(fds[index],0,SEEK_SET);
int length=0; int length=0;
sem_wait(&mutex[index]); sem_wait(&mutex[index]);
char blankspace[512]; char blankspace[512];
...@@ -66,7 +66,9 @@ int file_get(char *key, char *value) ...@@ -66,7 +66,9 @@ int file_get(char *key, char *value)
/* Gets the value stored at offset */ /* Gets the value stored at offset */
/* 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,256,setSize);
lseek(fds[index],0,SEEK_SET);
sem_wait(&readerLocks[index]); sem_wait(&readerLocks[index]);
readCounters[index]+=1; readCounters[index]+=1;
if(readCounters[index]==1) if(readCounters[index]==1)
...@@ -103,6 +105,7 @@ off_t file_put(char *key,char *value) ...@@ -103,6 +105,7 @@ off_t file_put(char *key,char *value)
if not present then search for empty line and insert there! if not present then search for empty line and insert there!
*/ */
unsigned int index=modulus(key,256,setSize); unsigned int index=modulus(key,256,setSize);
lseek(fds[index],0,SEEK_SET);
off_t position; off_t position;
//sem_wait(&mutex[index]); //sem_wait(&mutex[index]);
printf("[Write to File: %d]\n",index); printf("[Write to File: %d]\n",index);
...@@ -183,6 +186,11 @@ int main() ...@@ -183,6 +186,11 @@ int main()
//offset = file_put("40", "value28"); //offset = file_put("40", "value28");
//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");
file_get("24",value);
printf("(%s)\n", value);
memset(value,0,sizeof(value));
file_get("21",value);
printf("(%s)\n", value);
} }
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