1087 |
if (!out || !in) |
if (!out || !in) |
1088 |
imap4d_bye (ERR_NO_OFILE); |
imap4d_bye (ERR_NO_OFILE); |
1089 |
|
|
1090 |
|
setvbuf (in, NULL, _IOLBF, 0); |
1091 |
|
setvbuf (out, NULL, _IOLBF, 0); |
1092 |
if (stdio_stream_create (&istream, in, MU_STREAM_NO_CLOSE) |
if (stdio_stream_create (&istream, in, MU_STREAM_NO_CLOSE) |
1093 |
|| stdio_stream_create (&ostream, out, MU_STREAM_NO_CLOSE)) |
|| stdio_stream_create (&ostream, out, MU_STREAM_NO_CLOSE)) |
1094 |
imap4d_bye (ERR_NO_OFILE); |
imap4d_bye (ERR_NO_OFILE); |
1095 |
} |
} |
1096 |
|
|
1097 |
void |
void |
1098 |
|
util_get_input (stream_t *pstr) |
1099 |
|
{ |
1100 |
|
*pstr = istream; |
1101 |
|
} |
1102 |
|
|
1103 |
|
void |
1104 |
|
util_get_output (stream_t *pstr) |
1105 |
|
{ |
1106 |
|
*pstr = ostream; |
1107 |
|
} |
1108 |
|
|
1109 |
|
void |
1110 |
|
util_set_input (stream_t str) |
1111 |
|
{ |
1112 |
|
if (istream) |
1113 |
|
stream_destroy (istream, stream_get_owner (istream)); |
1114 |
|
istream = str; |
1115 |
|
} |
1116 |
|
|
1117 |
|
void |
1118 |
|
util_set_output (stream_t str) |
1119 |
|
{ |
1120 |
|
if (ostream) |
1121 |
|
stream_destroy (ostream, stream_get_owner (ostream)); |
1122 |
|
ostream = str; |
1123 |
|
} |
1124 |
|
|
1125 |
|
void |
1126 |
util_flush_output () |
util_flush_output () |
1127 |
{ |
{ |
1128 |
stream_flush (ostream); |
stream_flush (ostream); |
1165 |
} |
} |
1166 |
#endif /* WITH_TLS */ |
#endif /* WITH_TLS */ |
1167 |
|
|
1168 |
|
static list_t atexit_list; |
1169 |
|
|
1170 |
|
void |
1171 |
|
util_atexit (void (*fp) (void)) |
1172 |
|
{ |
1173 |
|
if (!atexit_list) |
1174 |
|
list_create (&atexit_list); |
1175 |
|
list_append (atexit_list, (void*)fp); |
1176 |
|
} |
1177 |
|
|
1178 |
|
static int |
1179 |
|
atexit_run (void *item, void *data) |
1180 |
|
{ |
1181 |
|
((void (*) (void)) item) (); |
1182 |
|
return 0; |
1183 |
|
} |
1184 |
|
|
1185 |
void |
void |
1186 |
util_bye () |
util_bye () |
1187 |
{ |
{ |
1188 |
if (istream == ostream) |
int rc = istream != ostream; |
1189 |
|
|
1190 |
|
stream_close (istream); |
1191 |
|
stream_destroy (&istream, stream_get_owner (istream)); |
1192 |
|
|
1193 |
|
if (rc) |
1194 |
{ |
{ |
1195 |
stream_close (istream); |
stream_close (ostream); |
1196 |
stream_destroy (&istream, stream_get_owner (istream)); |
stream_destroy (&ostream, stream_get_owner (ostream)); |
1197 |
} |
} |
1198 |
/* There's no reason closing in/out streams otherwise */ |
|
1199 |
#ifdef WITH_TLS |
list_do (atexit_list, atexit_run, 0); |
|
if (tls_available) |
|
|
mu_deinit_tls_libs (); |
|
|
#endif /* WITH_TLS */ |
|
1200 |
} |
} |
1201 |
|
|