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

« back to all changes in this revision

Viewing changes to .pc/dummy-writable_malloc-in-tkMain.c/o/unixsave.c

  • Committer: Package Import Robot
  • Author(s): Camm Maguire
  • Date: 2014-04-21 14:09:37 UTC
  • mfrom: (13.1.109 sid)
  • Revision ID: package-import@ubuntu.com-20140421140937-dlz68m10fzssuhbv
Tags: 2.6.10-8
2.6.11preĀ testĀ 7

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
static void
 
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
extern void _cleanup();
 
142
 
 
143
LFD(Lsave)()
 
144
{
 
145
        char filename[256];
 
146
 
 
147
        check_arg(1);
 
148
        check_type_or_pathname_string_symbol_stream(&vs_base[0]);
 
149
        coerce_to_filename(vs_base[0], filename);
 
150
 
 
151
        _cleanup();
 
152
/*
 
153
        {
 
154
                FILE *p;
 
155
                int nfile;
 
156
 
 
157
 
 
158
                nfile = NUMBER_OPEN_FILES;
 
159
 
 
160
                for (p = &_iob[3];  p < &_iob[nfile];  p++)
 
161
                        fclose(p);
 
162
        }
 
163
*/
 
164
        memory_save(kcl_self, filename);
 
165
/*
 
166
        _exit(0);
 
167
*/
 
168
        exit(0);
 
169
        /*  no return  */
 
170
}
 
171
 
 
172
#endif /* UNIXSAVE include */
 
173
 
 
174
void
 
175
gcl_init_unixsave(void)
 
176
{
 
177
        make_function("SAVE", Lsave);
 
178
}
 
179