blob: 2953ed76ddab4624d68ebc34df99275f6f4356d3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
*/
#define import_spp
#define import_libc
#define import_xnames
#include <iraf.h>
/*
** SPF.C -- String spoolfile utility package. Used to capture in a string
** buffer the output of a routine set up to write to a file.
**
** Example:
**
** fd = spf_open (buf, maxch)
** fprop (pp, fdopen(fd,"w"));
** spf_close (fd);
**
** leaves the output of the fprop() function in the user buffer "buf".
*/
static XCHAR *spf_buf;
static char *spf_userbuf;
static int spf_maxch;
/* SPF_OPEN -- Spoolfile open. Open a string spoolfile to be written into as
** a file, using ordinary file i/o. Only one such file can be open at a time.
*/
int
spf_open (
char *buf, /* user string buffer */
int maxch /* max chars of storage */
)
{
XINT x_maxch = maxch, x_mode = NEW_FILE;
char *malloc();
spf_userbuf = buf;
spf_maxch = maxch;
/* Malloc always returns a buffer which aligned to at least XCHAR. */
spf_buf = (XCHAR *) malloc ((maxch + 1) * sizeof(XCHAR));
return (STROPEN (spf_buf, &x_maxch, &x_mode));
}
/* SPF_CLOSE -- Close the spoolfile string, which should have been written
** into via file i/o while the string was open. This leaves SPP chars in
** the string; pack the string and return a pointer to the string.
*/
void
spf_close (
XINT fd /* file descriptor of stringbuf */
)
{
XINT x_fd = fd;
CLOSE (&x_fd);
c_strpak (spf_buf, spf_userbuf, spf_maxch);
free ((char *)spf_buf);
}
|