Commit 4e04511c authored by Samarth Joshi's avatar Samarth Joshi
parents 20c2bcf6 3353b49b
......@@ -51,7 +51,7 @@ void file_del(off_t offset, char *key)
sem_post(&mutex[index]);
}
void file_get(off_t offset, char *key, char *value)
void file_get(char *key, char *value)
{
/* Gets the value stored at offset */
/* Does not depend on key argument */
......@@ -62,25 +62,24 @@ void file_get(off_t offset, char *key, char *value)
if(readCounters[index]==1)
sem_wait(&mutex[index]);
sem_post(&readerLocks[index]);
lseek(fds[index], offset, SEEK_SET);
char line[10];
char *line;
//FILE *fp =fdopen(fds[index],"r+");
// fseek(fp, offset,SEEK_SET);
size_t len=0;
char ch;
int k=-1;
while(read(fds[index], &ch,sizeof(ch))!=-1 && ch!='\n')
{
if(k>=0)
{
value[k++]=ch;
}
if(ch==':')
{
k=0;
FILE *fp=fdopen(fds[index],"r+");
while ((getline(&line, &len, fp)) != -1)
{
char *fkey=strtok(line,":");
char *fvalue=strtok(NULL,":");
if(strcmp(key,fkey)==0){
memcpy(value,fvalue,strlen(fvalue));
break;
}
}
sem_wait(&readerLocks[index]);
readCounters[index]-=1;
......@@ -107,6 +106,13 @@ off_t file_put(char *key,char *value) {
sem_post(&mutex[index]);
return position;
}
void file_search(char *key,char *value)
{
int index=modulus(key,256,setSize);
}
int main()
{
......@@ -146,8 +152,8 @@ int main()
offset = file_put(prevkey, "value1");
offset = file_put(key, value);
file_get(9, 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\n", value);
file_del(offset, prevkey);
//file_del(offset, prevkey);
}
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