Imported Upstream version 0.1beta
[debian/yforth] / filee.c
1 /* yForth? - Written by Luca Padovani (C) 1996/97
2  * ------------------------------------------------------------------------
3  * This software is FreeWare as long as it comes with this header in each
4  * source file, anyway you can use it or any part of it whatever
5  * you want. It comes without any warranty, so use it at your own risk.
6  * ------------------------------------------------------------------------
7  * Module name: filee.c
8  * Abstract:    File extension word set
9  */
10
11 #include <stdio.h>
12 #include <string.h>
13 #include <malloc.h>
14 #include <errno.h>
15 #include "yforth.h"
16 #include "file.h"
17 #include "filee.h"
18
19 /**************************************************************************/
20 /* VARIABLES **************************************************************/
21 /**************************************************************************/
22
23 extern Char file_name[];
24
25 /**************************************************************************/
26 /* WORDS ******************************************************************/
27 /**************************************************************************/
28
29 void _file_status() {
30         register FILE *f;
31         get_file_name();
32         f = fopen(file_name, "rb");
33         *--sp = 0;
34         if (f) {
35                 *--sp = 0;
36                 fclose(f);
37         } else *--sp = errno;
38 }
39
40 void _flush_file() {
41         register FILE *f = (FILE *) *sp;
42         if (fflush(f)) sp[0] = errno;
43         else sp[0] = 0;
44 }
45
46 void _rename_file() {
47         register Char *file_name2;
48         get_file_name();
49         file_name2 = (Char *) malloc(strlen(file_name) + 1);
50         if (file_name2) {
51                 strcpy(file_name2, file_name);
52                 get_file_name();
53                 if (rename(file_name, file_name2)) *--sp = errno;
54                 else *--sp = 0;
55                 free(file_name2);
56         } else *--sp = errno;
57 }
58
59