[AUDIT]
[reactos.git] / reactos / lib / crt / stdio / rmtmp.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/msvcrt/stdio/rmtmp.c
5 * PURPOSE: remove temporary files in current directory
6 * PROGRAMMER: Ariadne
7 * UPDATE HISTORY:
8 * Created 19/01/99
9 * NOTE Not tested.
10 */
11 #include <precomp.h>
12
13 // should be replace by a closure of the tmp files
14 extern __file_rec *__file_rec_list;
15
16 int _rmtmp( void )
17 {
18 /*
19 loop files and check for _tmpfname
20 */
21 __file_rec *fr = __file_rec_list;
22 __file_rec **last_fr = &__file_rec_list;
23
24 int total_closed = 0;
25 int i = 0;
26 char temp_name[260];
27
28 /* Try to find an empty slot */
29 while (fr)
30 {
31 last_fr = &(fr->next);
32
33 /* If one of the existing slots is available, return it */
34 for (i=0; i<fr->count; i++) {
35 if (fr->files[i]->_tmpfname != NULL) {
36 if ( _access(fr->files[i]->_tmpfname ,W_OK) ) {
37 strcpy(temp_name,fr->files[i]->_tmpfname );
38 fclose(fr->files[i]);
39 remove(temp_name);
40 total_closed++;
41 }
42 }
43 }
44
45 /* If this one is full, go to the next */
46 if (fr->count == __FILE_REC_MAX)
47 fr = fr->next;
48 else
49 /* it isn't full, we can add to it */
50 break;
51 }
52 return total_closed;
53 }