1 /* vinit.c
2 Initialize for reading V2 configuration files.
3
4 Copyright (C) 1992 Ian Lance Taylor
5
6 This file is part of the Taylor UUCP uuconf library.
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License
10 as published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21
22 The author of the program may be contacted at ian@airs.com.
23 */
24
25 #include "uucnfi.h"
26
27 #if USE_RCS_ID
28 const char _uuconf_vinit_rcsid[] = "$FreeBSD$";
29 #endif
30
31 #include <errno.h>
32
33 static int ivinlib P((struct sglobal *qglobal, const char *z, size_t csize,
34 char **pz));
35
36 /* Return an allocated buffer holding a file name in OLDCONFIGLIB.
37 The c argument is the size of z including the trailing null byte,
38 since this is convenient for both the caller and this function. */
39
40 static int
ivinlib(qglobal,z,c,pz)41 ivinlib (qglobal, z, c, pz)
42 struct sglobal *qglobal;
43 const char *z;
44 size_t c;
45 char **pz;
46 {
47 char *zalc;
48
49 zalc = uuconf_malloc (qglobal->pblock, sizeof OLDCONFIGLIB - 1 + c);
50 if (zalc == NULL)
51 {
52 qglobal->ierrno = errno;
53 return UUCONF_MALLOC_FAILED | UUCONF_ERROR_ERRNO;
54 }
55
56 memcpy ((pointer) zalc, (pointer) OLDCONFIGLIB,
57 sizeof OLDCONFIGLIB - 1);
58 memcpy ((pointer) (zalc + sizeof OLDCONFIGLIB - 1), (pointer) z, c);
59
60 *pz = zalc;
61
62 return UUCONF_SUCCESS;
63 }
64
65 /* Initialize the routines which read V2 configuration files. The
66 only thing we do here is allocate the file names. */
67
68 int
uuconf_v2_init(ppglobal)69 uuconf_v2_init (ppglobal)
70 pointer *ppglobal;
71 {
72 struct sglobal **pqglobal = (struct sglobal **) ppglobal;
73 int iret;
74 struct sglobal *qglobal;
75 char *zdialcodes;
76
77 if (*pqglobal == NULL)
78 {
79 iret = _uuconf_iinit_global (pqglobal);
80 if (iret != UUCONF_SUCCESS)
81 return iret;
82 }
83
84 qglobal = *pqglobal;
85
86 iret = ivinlib (qglobal, V2_SYSTEMS, sizeof V2_SYSTEMS,
87 &qglobal->qprocess->zv2systems);
88 if (iret != UUCONF_SUCCESS)
89 return iret;
90 iret = ivinlib (qglobal, V2_DEVICES, sizeof V2_DEVICES,
91 &qglobal->qprocess->zv2devices);
92 if (iret != UUCONF_SUCCESS)
93 return iret;
94 iret = ivinlib (qglobal, V2_USERFILE, sizeof V2_USERFILE,
95 &qglobal->qprocess->zv2userfile);
96 if (iret != UUCONF_SUCCESS)
97 return iret;
98 iret = ivinlib (qglobal, V2_CMDS, sizeof V2_CMDS,
99 &qglobal->qprocess->zv2cmds);
100 if (iret != UUCONF_SUCCESS)
101 return iret;
102
103 iret = ivinlib (qglobal, V2_DIALCODES, sizeof V2_DIALCODES,
104 &zdialcodes);
105 if (iret != UUCONF_SUCCESS)
106 return iret;
107
108 return _uuconf_iadd_string (qglobal, zdialcodes, FALSE, FALSE,
109 &qglobal->qprocess->pzdialcodefiles,
110 qglobal->pblock);
111 }
112