~ubuntu-branches/ubuntu/vivid/gcl/vivid

« back to all changes in this revision

Viewing changes to o/unixsave.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2002-03-04 14:29:59 UTC
  • Revision ID: james.westby@ubuntu.com-20020304142959-dey14w08kr7lldu3
Tags: upstream-2.5.0.cvs20020219
ImportĀ upstreamĀ versionĀ 2.5.0.cvs20020219

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 Copyright (C) 1994 M. Hagiya, W. Schelter, T. Yuasa
 
3
 
 
4
This file is part of GNU Common Lisp, herein referred to as GCL
 
5
 
 
6
GCL is free software; you can redistribute it and/or modify it under
 
7
the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
 
8
the Free Software Foundation; either version 2, or (at your option)
 
9
any later version.
 
10
 
 
11
GCL is distributed in the hope that it will be useful, but WITHOUT
 
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public 
 
14
License for more details.
 
15
 
 
16
You should have received a copy of the GNU Library General Public License 
 
17
along with GCL; see the file COPYING.  If not, write to the Free Software
 
18
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 
 
20
*/
 
21
 
 
22
/*
 
23
        unixsave.c
 
24
*/
 
25
 
 
26
#define IN_UNIXSAVE
 
27
#ifndef FIRSTWORD
 
28
#include "include.h"
 
29
#endif
 
30
 
 
31
#ifdef UNIXSAVE
 
32
#include UNIXSAVE
 
33
#else
 
34
 
 
35
#ifdef HAVE_FCNTL
 
36
#include <fcntl.h>
 
37
#else
 
38
#include <sys/file.h>
 
39
#endif
 
40
 
 
41
#ifdef HAVE_AOUT
 
42
#undef BSD
 
43
#undef ATT
 
44
#define BSD
 
45
#endif
 
46
 
 
47
 
 
48
 
 
49
#ifdef BSD
 
50
#include HAVE_AOUT
 
51
#endif
 
52
 
 
53
#ifdef DOS
 
54
void 
 
55
binary_file_mode()
 
56
{_fmode = O_BINARY;}
 
57
#endif
 
58
 
 
59
 
 
60
#ifdef ATT
 
61
#include <filehdr.h>
 
62
#include <aouthdr.h>
 
63
#include <scnhdr.h>
 
64
#endif
 
65
 
 
66
#ifdef E15
 
67
#include <a.out.h>
 
68
extern  char etext;
 
69
#endif
 
70
 
 
71
 
 
72
filecpy(to, from, n)
 
73
FILE *to, *from;
 
74
register int n;
 
75
{
 
76
        char buffer[BUFSIZ];
 
77
 
 
78
        for (;;)
 
79
                if (n > BUFSIZ) {
 
80
                        fread(buffer, BUFSIZ, 1, from);
 
81
                        fwrite(buffer, BUFSIZ, 1, to);
 
82
                        n -= BUFSIZ;
 
83
                } else if (n > 0) {
 
84
                        fread(buffer, 1, n, from);
 
85
                        fwrite(buffer, 1, n, to);
 
86
                        break;
 
87
                } else
 
88
                        break;
 
89
}
 
90
 
 
91
 
 
92
memory_save(original_file, save_file)
 
93
char *original_file, *save_file;
 
94
{       MEM_SAVE_LOCALS;
 
95
        char *data_begin, *data_end;
 
96
        int original_data;
 
97
        FILE *original, *save;
 
98
        register int n;
 
99
        register char *p;
 
100
        extern char *sbrk();
 
101
 
 
102
        original = freopen(original_file,"r",stdin);
 
103
/*      fclose(stdin); 
 
104
        original = fopen(original_file, "r");
 
105
*/      
 
106
 
 
107
        if (stdin != original || original->_file != 0) {
 
108
                fprintf(stderr, "Can't open the original file.\n");
 
109
                exit(1);
 
110
        }
 
111
        setbuf(original, stdin_buf);
 
112
        fclose(stdout);
 
113
        unlink(save_file);
 
114
        n = open(save_file, O_CREAT|O_WRONLY, 0777);
 
115
        if (n != 1 || (save = fdopen(n, "w")) != stdout) {
 
116
                fprintf(stderr, "Can't open the save file.\n");
 
117
                exit(1);
 
118
        }
 
119
        setbuf(save, stdout_buf);
 
120
 
 
121
        READ_HEADER;
 
122
        FILECPY_HEADER;
 
123
 
 
124
        for (n = header.a_data, p = data_begin;  ;  n -= BUFSIZ, p += BUFSIZ)
 
125
                if (n > BUFSIZ)
 
126
                        fwrite(p, BUFSIZ, 1, save);
 
127
                else if (n > 0) {
 
128
                        fwrite(p, 1, n, save);
 
129
                        break;
 
130
                } else
 
131
                        break;
 
132
 
 
133
        fseek(original, original_data, 1);
 
134
 
 
135
        COPY_TO_SAVE;
 
136
 
 
137
        fclose(original);
 
138
        fclose(save);
 
139
}
 
140
 
 
141
Lsave()
 
142
{
 
143
        char filename[256];
 
144
 
 
145
        check_arg(1);
 
146
        check_type_or_pathname_string_symbol_stream(&vs_base[0]);
 
147
        coerce_to_filename(vs_base[0], filename);
 
148
 
 
149
        _cleanup();
 
150
/*
 
151
        {
 
152
                FILE *p;
 
153
                int nfile;
 
154
 
 
155
 
 
156
                nfile = NUMBER_OPEN_FILES;
 
157
 
 
158
                for (p = &_iob[3];  p < &_iob[nfile];  p++)
 
159
                        fclose(p);
 
160
        }
 
161
*/
 
162
        memory_save(kcl_self, filename);
 
163
/*
 
164
        _exit(0);
 
165
*/
 
166
        exit(0);
 
167
        /*  no return  */
 
168
}
 
169
 
 
170
#endif /* UNIXSAVE include */
 
171
 
 
172
init_unixsave()
 
173
{
 
174
        make_function("SAVE", Lsave);
 
175
}
 
176