aboutsummaryrefslogtreecommitdiff
path: root/lib/fuse.c
diff options
context:
space:
mode:
authorGravatar Miklos Szeredi <miklos@szeredi.hu>2005-10-20 14:48:50 +0000
committerGravatar Miklos Szeredi <miklos@szeredi.hu>2005-10-20 14:48:50 +0000
commitc4c12ae295ca6f3fb02e12d3bad8f92fee4dfe3f (patch)
tree8887f82ce0c9ebfe2c6880bb028d5e4e1759c348 /lib/fuse.c
parentc9daeb1e8d724c9015c8b363975261cf9b0d2fdb (diff)
fix
Diffstat (limited to 'lib/fuse.c')
-rw-r--r--lib/fuse.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/fuse.c b/lib/fuse.c
index e44b9f2..b0cf553 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -103,6 +103,7 @@ struct fuse_dirhandle {
char *contents;
int allocated;
unsigned len;
+ unsigned size;
unsigned needlen;
int filled;
unsigned long fh;
@@ -1261,7 +1262,6 @@ static int fill_dir_common(struct fuse_dirhandle *dh, const char *name,
unsigned namelen = strlen(name);
unsigned entsize;
unsigned newlen;
- char *newptr;
if (statp)
stbuf = *statp;
@@ -1291,12 +1291,21 @@ static int fill_dir_common(struct fuse_dirhandle *dh, const char *name,
return 1;
}
- newptr = (char *) realloc(dh->contents, newlen);
- if (!newptr) {
- dh->error = -ENOMEM;
- return 1;
+ if (newlen > dh->size) {
+ char *newptr;
+
+ if (!dh->size)
+ dh->size = 1024;
+ while (newlen > dh->size)
+ dh->size *= 2;
+
+ newptr = (char *) realloc(dh->contents, dh->size);
+ if (!newptr) {
+ dh->error = -ENOMEM;
+ return 1;
+ }
+ dh->contents = newptr;
}
- dh->contents = newptr;
fuse_add_dirent(dh->contents + dh->len, name, &stbuf, off ? off : newlen);
dh->len = newlen;
return 0;