add directory study

This commit is contained in:
gohigh
2024-02-19 00:25:23 -05:00
parent b1306b38b1
commit f3774e2f8c
4001 changed files with 2285787 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
/* f c l o s e */
#include "stdiolib.h"
/*LINTLIBRARY*/
int fclose F1(register FILE *, fp)
{
register FILE **sp; /* stream chain */
FILE *p; /* stream chain */
/* Stream descriptor yet to be inserted */
if (TESTFLAG(fp, _IOINSERT)) {
CLEARFLAG(fp, _IOINSERT);
FINSERT(fp);
}
/* Find the file descriptor */
for (sp = &__iop; (p = *sp) != NULL && p != fp; sp = &p->__next)
;
/* Shutdown */
if (p == NULL || (fileno(fp) >= 0 && (FFLUSH(fp) || close(fileno(fp)))))
return EOF;
/* Free allocated buffer */
__freebuf(fp);
/* Unlink from list or indicate that it's unused */
if (TESTFLAG(fp, _IOSTDX))
fp->__flag &= _IORETAIN;
else {
*sp = fp->__next;
free((void *) fp);
}
return 0;
}