1 /* util3.c
2 */
3 /* This software is copyrighted as detailed in the LICENSE file. */
4
5
6 #include <stdio.h>
7 #include "config.h"
8 #include "config2.h"
9 #include "typedef.h"
10 #include "EXTERN.h"
11 #include "config.h"
12 #include "config2.h"
13 #include "nntpclient.h"
14 #include "util2.h"
15 #include "INTERN.h"
16 #include "util3.h"
17
18 char* sh = NULL;
19 bool export_nntp_fds = FALSE;
20
21 #ifdef SUPPORT_NNTP
22 char* nntp_password;
23 #endif
24
25 int
doshell(sh,cmd)26 doshell(sh,cmd)
27 char* sh;
28 char* cmd;
29 {
30 return system(cmd);
31 }
32
33 void
finalize(num)34 finalize(num)
35 int num;
36 {
37 #ifdef SUPPORT_NNTP
38 nntp_close(TRUE);
39 #endif
40 exit(num);
41 }
42
43 static char nomem[] = "trn: out of memory!\n";
44
45 /* paranoid version of malloc */
46
47 #ifndef USE_DEBUGGING_MALLOC
48 char*
safemalloc(size)49 safemalloc(size)
50 MEM_SIZE size;
51 {
52 char* ptr;
53
54 ptr = malloc(size ? size : (MEM_SIZE)1);
55 if (!ptr) {
56 fputs(nomem,stdout);
57 finalize(1);
58 }
59 return ptr;
60 }
61 #endif
62
63 /* paranoid version of realloc. If where is NULL, call malloc */
64
65 #ifndef USE_DEBUGGING_MALLOC
66 char*
saferealloc(where,size)67 saferealloc(where,size)
68 char* where;
69 MEM_SIZE size;
70 {
71 char* ptr;
72
73 ptr = realloc(where, size ? size : (MEM_SIZE)1);
74 if (!ptr) {
75 fputs(nomem,stdout);
76 finalize(1);
77 }
78 return ptr;
79 }
80 #endif
81
82 char*
dointerp(dest,destsize,pattern,stoppers,cmd)83 dointerp(dest, destsize, pattern, stoppers, cmd)
84 char* dest;
85 int destsize;
86 char* pattern;
87 char* stoppers;
88 char* cmd;
89 {
90 extern char* dotdir;
91 if (*pattern == '%' && pattern[1] == '.') {
92 int len = strlen(dotdir);
93 safecpy(dest, dotdir, destsize);
94 if (len < destsize)
95 safecpy(dest+len, pattern+2, destsize - len);
96 }
97 else
98 safecpy(dest, pattern, destsize);
99 return stoppers; /* This is wrong on purpose */
100 }
101
102 #ifdef SUPPORT_NNTP
103 int
nntp_handle_nested_lists()104 nntp_handle_nested_lists()
105 {
106 fputs("Programming error! Nested NNTP calls detected.\n",stderr);
107 return -1;
108 }
109 #endif
110
111 #ifdef SUPPORT_NNTP
112 char*
get_auth_user()113 get_auth_user()
114 {
115 extern char* nntp_auth_file;
116 return read_auth_file(nntp_auth_file, &nntp_password);
117 }
118 #endif
119
120 #ifdef SUPPORT_NNTP
121 char*
get_auth_pass()122 get_auth_pass()
123 {
124 return nntp_password;
125 }
126 #endif
127
128 #if defined(USE_GENAUTH) && defined(SUPPORT_NNTP)
129 char*
get_auth_command()130 get_auth_command()
131 {
132 return NULL;
133 }
134 #endif
135