This is unixsave.c in view mode; [Download] [Up]
/* (c) Copyright Taiichi Yuasa and Masami Hagiya, 1984. All rights reserved. Copying of this file is authorized to users who have executed the true and proper "License Agreement for Kyoto Common LISP" with SIGLISP. */ /* unixsave.c */ #ifndef FIRSTWORD #include "include.h" #endif #ifdef UNIXSAVE #include UNIXSAVE #else #ifdef HAVE_FCNTL #include <fcntl.h> #else #include <sys/file.h> #endif #ifdef HAVE_AOUT #undef BSD #undef ATT #define BSD #endif #ifdef BSD #include <a.out.h> #endif #ifdef ATT #include <filehdr.h> #include <aouthdr.h> #include <scnhdr.h> #endif #ifdef E15 #include <a.out.h> extern etext; #endif filecpy(to, from, n) FILE *to, *from; register int n; { char buffer[BUFSIZ]; for (;;) if (n > BUFSIZ) { fread(buffer, BUFSIZ, 1, from); fwrite(buffer, BUFSIZ, 1, to); n -= BUFSIZ; } else if (n > 0) { fread(buffer, 1, n, from); fwrite(buffer, 1, n, to); break; } else break; } memory_save(original_file, save_file) char *original_file, *save_file; { MEM_SAVE_LOCALS; char *data_begin, *data_end; int original_data; FILE *original, *save; register int n; register char *p; extern char *sbrk(); extern char stdin_buf[BUFSIZ], stdout_buf[BUFSIZ]; fclose(stdin); original = fopen(original_file, "r"); if (stdin != original || original->_file != 0) { fprintf(stderr, "Can't open the original file.\n"); exit(1); } setbuf(original, stdin_buf); fclose(stdout); unlink(save_file); n = open(save_file, O_CREAT|O_WRONLY, 0777); if (n != 1 || (save = fdopen(n, "w")) != stdout) { fprintf(stderr, "Can't open the save file.\n"); exit(1); } setbuf(save, stdout_buf); READ_HEADER; FILECPY_HEADER; for (n = header.a_data, p = data_begin; ; n -= BUFSIZ, p += BUFSIZ) if (n > BUFSIZ) fwrite(p, BUFSIZ, 1, save); else if (n > 0) { fwrite(p, 1, n, save); break; } else break; fseek(original, original_data, 1); COPY_TO_SAVE; fclose(original); fclose(save); } Lsave() { char filename[256]; check_arg(1); check_type_or_pathname_string_symbol_stream(&vs_base[0]); coerce_to_filename(vs_base[0], filename); _cleanup(); /* { FILE *p; int nfile; nfile = NUMBER_OPEN_FILES; for (p = &_iob[3]; p < &_iob[nfile]; p++) fclose(p); } */ memory_save(kcl_self, filename); /* _exit(0); */ exit(0); /* no return */ } #endif /* UNIXSAVE include */ init_unixsave() { make_function("SAVE", Lsave); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.