Browse Source

Fix little bug, close() must mark a file as closed!

release-1.5.4.branch
Vreixo Formoso 14 years ago
parent
commit
100919a5cb
  1. 14
      src/fs_local.c
  2. 9
      src/stream.h
  3. 4
      test/cat.c
  4. 6
      test/lsl.c

14
src/fs_local.c

@ -151,6 +151,7 @@ int lfs_open(IsoFileSource *src)
static
int lfs_close(IsoFileSource *src)
{
int ret;
_LocalFsFileSource *data;
if (src == NULL) {
@ -160,12 +161,19 @@ int lfs_close(IsoFileSource *src)
data = src->data;
switch(data->openned) {
case 1: /* not dir */
return close(data->info.fd) == 0 ? ISO_SUCCESS : ISO_FILE_ERROR;
ret = close(data->info.fd) == 0 ? ISO_SUCCESS : ISO_FILE_ERROR;
break;
case 2: /* directory */
return closedir(data->info.dir) == 0 ? ISO_SUCCESS : ISO_FILE_ERROR;
ret = closedir(data->info.dir) == 0 ? ISO_SUCCESS : ISO_FILE_ERROR;
break;
default:
return ISO_FILE_NOT_OPENNED;
ret = ISO_FILE_NOT_OPENNED;
break;
}
if (ret == ISO_SUCCESS) {
data->openned = 0;
}
return ret;
}
static

9
src/stream.h

@ -29,16 +29,17 @@ struct Iso_Stream
/**
* Close the Stream.
* @return 1 on success, < 0 on error
*/
void (*close)(IsoStream *stream);
int (*close)(IsoStream *stream);
// Stream should read in 2k blocks!
//...
int refcount;
void *data;
}
#endif /*STREAM_H_*/

4
test/cat.c

@ -67,6 +67,8 @@ int main(int argc, char **argv)
}
file->close(file);
}
iso_file_source_unref(file);
iso_filesystem_unref(fs);
return 0;
}

6
test/lsl.c

@ -111,6 +111,7 @@ int main(int argc, char **argv)
while (dir->readdir(dir, &file) == 1) {
print_file_src(file);
iso_file_source_unref(file);
}
res = dir->close(dir);
@ -121,7 +122,8 @@ int main(int argc, char **argv)
} else {
print_file_src(dir);
}
iso_file_source_unref(dir);
iso_filesystem_unref(fs);
return 0;
}
Loading…
Cancel
Save