[Libsysio-commit] HEAD: libsysio/src file.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2004-07-28 14:57:01
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25262/src Modified Files: file.c Log Message: Two changes: Fixed a bug in how fd_grow was called. It was always called with the desired index of the file table instead of desired size -- Thanks Ruth. Also, fd_grow was *very* aggressive when asked to grow the table. Now, it only grows to what is ever only actually required. We still do not trim the table though. Index: file.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/file.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -w -b -B -p -r1.15 -r1.16 --- file.c 27 Jul 2004 15:00:43 -0000 1.15 +++ file.c 28 Jul 2004 14:56:52 -0000 1.16 @@ -118,29 +118,27 @@ _sysio_fcompletio(struct ioctx *ioctx, s static int fd_grow(size_t n) { - int fd; size_t count; struct file **noftab, **filp; /* * Sanity check the new size. */ - fd = (int )n; - if ((size_t )fd != n) + if ((int )n < 0) return -EMFILE; - if (n < 8) - n = 8; - if (n >= _sysio_oftab_size && n - _sysio_oftab_size < _sysio_oftab_size) - n = (n + 1) * 2; + /* + * We never shrink the table. + */ + if (n <= _sysio_oftab_size) + return 0; + noftab = realloc(_sysio_oftab, n * sizeof(struct file *)); if (!noftab) return -ENOMEM; _sysio_oftab = noftab; count = _sysio_oftab_size; _sysio_oftab_size = n; - if (n < count) - return 0; filp = _sysio_oftab + count; n -= count; while (n--) @@ -176,7 +174,7 @@ find_free_fildes(int low) if (n < 0) return -ENFILE; if ((unsigned )n >= _sysio_oftab_size) { - err = fd_grow((size_t )n); + err = fd_grow((unsigned )n + 1); if (err) return err; filp = &_sysio_oftab[n]; @@ -240,7 +238,7 @@ _sysio_fd_set(struct file *fil, int fd, } if ((unsigned )fd >= _sysio_oftab_size) { - err = fd_grow(fd); + err = fd_grow((unsigned )fd + 1); if (err) return err; } |