1 #include "stdio_impl.h" 2 #include <stdlib.h> 3 dummy(FILE * f)4static void dummy(FILE *f) { } 5 weak_alias(dummy, __unlist_locked_file); 6 __fclose(FILE * f)7int __fclose(FILE *f) 8 { 9 int r; 10 11 FLOCK(f); 12 r = fflush(f); 13 r |= f->close(f); 14 FUNLOCK(f); 15 16 /* Past this point, f is closed and any further explict access 17 * to it is undefined. However, it still exists as an entry in 18 * the open file list and possibly in the thread's locked files 19 * list, if it was closed while explicitly locked. Functions 20 * which process these lists must tolerate dead FILE objects 21 * (which necessarily have inactive buffer pointers) without 22 * producing any side effects. */ 23 24 if (f->flags & F_PERM) return r; 25 26 FILE **head = __ofl_lock(); 27 if (f->prev) f->prev->next = f->next; 28 if (f->next) f->next->prev = f->prev; 29 if (*head == f) *head = f->next; 30 __ofl_unlock(); 31 32 pthread_mutex_destroy(f->lock); 33 34 free(f->getln_buf); 35 free(f); 36 37 return r; 38 } 39 weak_alias(__fclose, fclose); 40 __wrap_fclose(FILE * f)41int __wrap_fclose(FILE *f) 42 { 43 return __fclose(f); 44 } 45 46