Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/gen/getmntinfo.c
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | getmntinfo(struct statfs **mntbufp, int mode) | ||||
static int mntsize; | static int mntsize; | ||||
static long bufsize; | static long bufsize; | ||||
unsigned tries = 0; | unsigned tries = 0; | ||||
if (mntsize <= 0 && (mntsize = getfsstat(0, 0, MNT_NOWAIT)) < 0) | if (mntsize <= 0 && (mntsize = getfsstat(0, 0, MNT_NOWAIT)) < 0) | ||||
return (0); | return (0); | ||||
if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, mode)) < 0) | if (bufsize > 0 && (mntsize = getfsstat(mntbuf, bufsize, mode)) < 0) | ||||
return (0); | return (0); | ||||
while (tries++ < MAX_TRIES && bufsize <= mntsize * sizeof(*mntbuf)) { | while (tries++ < MAX_TRIES && | ||||
(size_t)bufsize <= mntsize * sizeof(*mntbuf)) { | |||||
bufsize = (mntsize * SCALING_FACTOR) * sizeof(*mntbuf); | bufsize = (mntsize * SCALING_FACTOR) * sizeof(*mntbuf); | ||||
if ((mntbuf = reallocf(mntbuf, bufsize)) == NULL) | if ((mntbuf = reallocf(mntbuf, bufsize)) == NULL) | ||||
return (0); | return (0); | ||||
if ((mntsize = getfsstat(mntbuf, bufsize, mode)) < 0) | if ((mntsize = getfsstat(mntbuf, bufsize, mode)) < 0) | ||||
return (0); | return (0); | ||||
} | } | ||||
*mntbufp = mntbuf; | *mntbufp = mntbuf; | ||||
if (mntsize > (bufsize / sizeof(*mntbuf))) | if ((unsigned long)mntsize > (bufsize / sizeof(*mntbuf))) | ||||
return (bufsize / sizeof(*mntbuf)); | return (bufsize / sizeof(*mntbuf)); | ||||
return (mntsize); | return (mntsize); | ||||
} | } |