|
|
1.1 root 1: /* UNIX HEADER */
2: #include <stdio.h>
3:
4: /* COMMON SGS HEADERS */
5: #include "filehdr.h"
6: #include "ldfcn.h"
7: /* STRIP HEADER */
8: #include "defs.h"
9:
10:
11: /* copytmp(filename, filehead)
12: *
13: * copies file header in filehead back to original file and
14: * copies the rest of the stripped file from temporary back to original
15: *
16: * calls:
17: * - ignorsig( ) to turn off interrupts while recreating original file
18: * - resetsig( ) to turn signals back on after recreating original
19: * - error(file, string, level) if it cannot recreate original
20: *
21: * returns SUCCESS or FAILURE
22: */
23:
24:
25: int
26: copytmp(filename, filehead)
27:
28: char *filename;
29: FILHDR *filehead;
30:
31: {
32: /* UNIX FUNCTIONS CALLED */
33: extern int fread( ),
34: fwrite( );
35:
36: /* STRIP FUNCTIONS CALLED */
37: extern ignorsig( ),
38: resetsig( ),
39: error( );
40:
41: /* EXTERNAL VARIABLES USED */
42: extern FILE *strp1,
43: *strp2,
44: *stripout;
45: #if FLEXNAMES
46: extern long string_size;
47: extern char tmpnam5[];
48: #endif
49:
50: /* LOCAL VARIABLES */
51: char buffer[BUFSIZ];
52: int nitems;
53: #if FLEXNAMES
54: FILE *tmpfile;
55: #endif
56:
57:
58: ignorsig( );
59:
60: if (fwrite(filehead, FILHSZ, 1, stripout) != 1) {
61: error(filename, "cannot recreate fileheader", 5);
62: resetsig( );
63: return(FAILURE);
64: }
65:
66: while ((nitems = fread(buffer, sizeof (char), BUFSIZ, strp1)) != 0) {
67: if (fwrite(buffer, sizeof (char), nitems, stripout) != nitems) {
68: error(filename, "cannot recreate stripped file<tmp1>", 5);
69: resetsig( );
70: return(FAILURE);
71: }
72: }
73: while ((nitems = fread(buffer, sizeof (char), BUFSIZ, strp2)) != 0) {
74: if (fwrite(buffer, sizeof (char), nitems, stripout) != nitems) {
75: error(filename, "cannot recreate stripped file<tmp2>", 5);
76: resetsig( );
77: return(FAILURE);
78: }
79: }
80:
81: #if FLEXNAMES
82: if (string_size > 0L)
83: {
84: if ((tmpfile = fopen( tmpnam5, "r" )) == NULL)
85: {
86: fprintf( stderr, "cannot read temp file" );
87: resetsig( );
88: return( FAILURE );
89: }
90:
91: if (fwrite( &string_size, sizeof( long ), 1, stripout ) != 1)
92: {
93: error( filename, "cannot recreate stripped file", 5 );
94: resetsig( );
95: return( FAILURE );
96: }
97:
98: while ((nitems = fread( buffer, sizeof( char ), BUFSIZ, tmpfile)) != 0)
99: if (fwrite( buffer, sizeof( char ), nitems, stripout ) != nitems)
100: {
101: error( filename, "cannot recreate stripped file", 5 );
102: resetsig( );
103: return( FAILURE );
104: }
105:
106: fclose( tmpfile );
107: }
108: #endif
109:
110: resetsig( );
111: return(SUCCESS);
112: }
113: /*
114: * static char ID[] = "@(#) copytmp.c: 1.4 3/3/83";
115: */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.