musl/src/stdio/fclose.c
Rich Felker a617a8e2ad fix more unused variable warnings
some of these were coming from stdio functions locking files without
unlocking them. I believe it's useful for this to throw a warning, so
I added a new macro that's self-documenting that the file will never
be unlocked to avoid the warning in the few places where it's wrong.
2012-11-01 23:46:39 -04:00

25 lines
395 B
C

#include "stdio_impl.h"
int fclose(FILE *f)
{
int r;
int perm;
FFINALLOCK(f);
if (!(perm = f->flags & F_PERM)) {
OFLLOCK();
if (f->prev) f->prev->next = f->next;
if (f->next) f->next->prev = f->prev;
if (libc.ofl_head == f) libc.ofl_head = f->next;
OFLUNLOCK();
}
r = fflush(f);
r |= f->close(f);
if (f->getln_buf) free(f->getln_buf);
if (!perm) free(f);
return r;
}