-
Notifications
You must be signed in to change notification settings - Fork 59
/
dat1_alloc_lcp.c
134 lines (107 loc) · 6.12 KB
/
dat1_alloc_lcp.c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <string.h>
#include <stdlib.h>
#include "star/mem.h"
#include "ems.h" /* EMS error reporting routines */
#include "hds1.h" /* Global definitions for HDS */
#include "rec.h" /* Public rec_ definitions */
#include "dat1.h" /* Internal dat_ definitions */
#include "dat_err.h" /* DAT__ error code definitions */
int dat1_alloc_lcp( struct LOC **loc, struct LCP **lcp )
{
/*+ */
/* Name: */
/* dat1_alloc_lcp */
/* Purpose: */
/* Allocate a Locator Control Packet and initialise a locator. */
/* Invocation: */
/* dat1_alloc_lcp( loc, lcp ) */
/* Description: */
/* This function allocates a new Locator Control Packet (LCP) to control */
/* user access to an HDS object and initialises a locator, thereby */
/* associating it with the allocated LCP. */
/* Parameters: */
/* struct LOC **loc */
/* Pointer to a pointer to a struct LOC that is to be filled with the */
/* locator information. Will be malloced by this routine and freed */
/* with a datAnnul. *loc Must be NULL on entry. */
/* struct LCP **lcp */
/* Pointer to a pointer which will be set to identify the */
/* newly-allocated LCP. A null pointer will be returned in *lcp if */
/* this routine is invoked with the global status set, or if it */
/* should fail for any reason. */
/* Returned Value: */
/* int dat1_alloc_lcp */
/* The global status value current on exit. */
/* Notes: */
/* The returned LCP will have its data fields and "primary locator" flag */
/* initialised to zero. Its sequence number will be set to match that of */
/* the locator. */
/* Copyright: */
/* Copyright (C) 1992 Science & Engineering Research Council */
/* Copyright (C) 2005-2006 Particle Physics and Astronomy Research Council */
/* Authors: */
/* RFWS: R.F. Warren-Smith (STARLINK) */
/* TIMJ: T. Jenness (JAC, Hawaii) */
/* {@enter_new_authors_here@} */
/* History: */
/* 14-OCT-1992 (RFWS): */
/* Substantially new routine based on old original. */
/* 15-NOV-2005 (TIMJ): */
/* Change API to use the struct LOC explcitly */
/* 23-FEB-2006 (TIMJ): */
/* use rec_alloc_mem */
/* {@enter_changes_here@} */
/* Bugs: */
/* {@note_any_bugs_here@} */
/*- */
/* Local Variables: */
/*. */
/* Set an initial null value for the returned LCP pointer. */
*lcp = NULL;
/* Check the inherited global status. */
if ( !_ok( hds_gl_status ) ) return hds_gl_status;
/* Check that the locator is NULL */
if (*loc != NULL ) {
hds_gl_status = DAT__LOCIN;
emsRep( "DAT1_ALLOC_LCP",
"Supplied locator is not a NULL pointer (Possible programming error)",
&hds_gl_status);
return hds_gl_status;
}
/* Ensure that HDS has been initialised. */
if ( !hds_gl_active )
{
dat1_init( );
}
/* If the Free Locator Queue is empty, then refill it. */
if ( dat_ga_flq == NULL )
{
dau_refill_flq( );
}
/* Allocate a new LCP from the free queue. */
if( _ok( hds_gl_status ) )
{
*lcp = dat_ga_flq;
_remque( *lcp, dat_ga_flq );
/* Clear the LCP data fields and the primary LCP flag. */
(void) memset( (void *) &(*lcp)->data, 0, sizeof( struct LCP_DATA ) );
(*lcp)->primary = 0;
/* Insert the LCP at the head of the Working Locator Queue and increment */
/* the Queue size. */
_insque( *lcp, dat_ga_wlq );
dat_gl_wlqsize++;
/* Initialise the locator information, including the locator sequence */
/* number which is duplicated in the LCP. */
if (rec_alloc_mem( sizeof(struct LOC), (void**)loc ) == DAT__OK) {
(*loc)->hds_version = 4;
(*loc)->check = DAT__LOCCHECK;
(*loc)->lcp = *lcp;
(*loc)->seqno = (*lcp)->seqno = ++hds_gl_locseq;
}
}
/* Exit the routine. */
return hds_gl_status;
}