Lines 38-45
Link Here
|
38 |
"$Id: utility.c,v 1.11 1999/12/12 14:59:45 dholland Exp $"; |
38 |
"$Id: utility.c,v 1.11 1999/12/12 14:59:45 dholland Exp $"; |
39 |
|
39 |
|
40 |
#define PRINTOPTIONS |
40 |
#define PRINTOPTIONS |
41 |
|
41 |
#define _GNU_SOURCE |
42 |
#include <stdarg.h> |
42 |
#include <stdarg.h> |
|
|
43 |
#include <stdio.h> |
43 |
#include <sys/utsname.h> |
44 |
#include <sys/utsname.h> |
44 |
|
45 |
|
45 |
#ifdef AUTHENTICATE |
46 |
#ifdef AUTHENTICATE |
Lines 52-57
Link Here
|
52 |
* utility functions performing io related tasks |
53 |
* utility functions performing io related tasks |
53 |
*/ |
54 |
*/ |
54 |
|
55 |
|
|
|
56 |
/* |
57 |
* This function appends data to nfrontp and advances nfrontp. |
58 |
* Returns the number of characters written altogether (the |
59 |
* buffer may have been flushed in the process). |
60 |
*/ |
61 |
|
62 |
int |
63 |
output_data(const char *format, ...) |
64 |
{ |
65 |
va_list args; |
66 |
int len; |
67 |
char *buf; |
68 |
|
69 |
va_start(args, format); |
70 |
if ((len = vasprintf(&buf, format, args)) == -1) |
71 |
return -1; |
72 |
output_datalen(buf, len); |
73 |
va_end(args); |
74 |
free(buf); |
75 |
return (len); |
76 |
} |
77 |
|
78 |
void |
79 |
output_datalen(const char *buf, int len) |
80 |
{ |
81 |
int remaining, copied; |
82 |
|
83 |
remaining = BUFSIZ - (nfrontp - netobuf); |
84 |
while (len > 0) { |
85 |
/* Free up enough space if the room is too low*/ |
86 |
if ((len > BUFSIZ ? BUFSIZ : len) > remaining) { |
87 |
netflush(); |
88 |
remaining = BUFSIZ - (nfrontp - netobuf); |
89 |
} |
90 |
|
91 |
/* Copy out as much as will fit */ |
92 |
copied = remaining > len ? len : remaining; |
93 |
memmove(nfrontp, buf, copied); |
94 |
nfrontp += copied; |
95 |
len -= copied; |
96 |
remaining -= copied; |
97 |
buf += copied; |
98 |
} |
99 |
return; |
100 |
} |
101 |
|
102 |
/** |
55 |
void |
103 |
void |
56 |
netoprintf(const char *fmt, ...) |
104 |
netoprintf(const char *fmt, ...) |
57 |
{ |
105 |
{ |
Lines 67-73
Link Here
|
67 |
va_end(ap); |
115 |
va_end(ap); |
68 |
|
116 |
|
69 |
if (len<0 || len==maxsize) { |
117 |
if (len<0 || len==maxsize) { |
70 |
/* didn't fit */ |
118 |
/ * did not fit * / |
71 |
netflush(); |
119 |
netflush(); |
72 |
} |
120 |
} |
73 |
else { |
121 |
else { |
Lines 76-81
Link Here
|
76 |
} |
124 |
} |
77 |
nfrontp += len; |
125 |
nfrontp += len; |
78 |
} |
126 |
} |
|
|
127 |
*/ |
79 |
|
128 |
|
80 |
/* |
129 |
/* |
81 |
* ttloop |
130 |
* ttloop |
Lines 273-282
Link Here
|
273 |
int n; |
322 |
int n; |
274 |
|
323 |
|
275 |
if ((n = nfrontp - nbackp) > 0) { |
324 |
if ((n = nfrontp - nbackp) > 0) { |
|
|
325 |
|
326 |
#if 0 |
327 |
/* XXX This causes output_data() to recurse and die */ |
276 |
DIAG(TD_REPORT, |
328 |
DIAG(TD_REPORT, |
277 |
{ netoprintf("td: netflush %d chars\r\n", n); |
329 |
{ netoprintf("td: netflush %d chars\r\n", n); |
278 |
n = nfrontp - nbackp; /* update count */ |
330 |
n = nfrontp - nbackp; /* update count */ |
279 |
}); |
331 |
}); |
|
|
332 |
#endif |
333 |
|
280 |
#if defined(ENCRYPT) |
334 |
#if defined(ENCRYPT) |
281 |
if (encrypt_output) { |
335 |
if (encrypt_output) { |
282 |
char *s = nclearto ? nclearto : nbackp; |
336 |
char *s = nclearto ? nclearto : nbackp; |
Lines 310-320
Link Here
|
310 |
} |
364 |
} |
311 |
} |
365 |
} |
312 |
} |
366 |
} |
313 |
if (n < 0) { |
367 |
|
314 |
if (errno == EWOULDBLOCK || errno == EINTR) |
368 |
if (n == -1) { |
315 |
return; |
369 |
if (errno == EWOULDBLOCK || errno == EINTR) |
316 |
cleanup(0); |
370 |
return; |
317 |
} |
371 |
cleanup(0); |
|
|
372 |
/* NOTREACHED */ |
373 |
} |
374 |
|
318 |
nbackp += n; |
375 |
nbackp += n; |
319 |
#if defined(ENCRYPT) |
376 |
#if defined(ENCRYPT) |
320 |
if (nbackp > nclearto) |
377 |
if (nbackp > nclearto) |
Lines 332-338
Link Here
|
332 |
return; |
389 |
return; |
333 |
} /* end of netflush */ |
390 |
} /* end of netflush */ |
334 |
|
391 |
|
335 |
|
392 |
#if 0 |
336 |
/* |
393 |
/* |
337 |
* writenet |
394 |
* writenet |
338 |
* |
395 |
* |
Lines 355-361
Link Here
|
355 |
nfrontp += len; |
412 |
nfrontp += len; |
356 |
|
413 |
|
357 |
} /* end of writenet */ |
414 |
} /* end of writenet */ |
358 |
|
415 |
#endif |
359 |
|
416 |
|
360 |
/* |
417 |
/* |
361 |
* miscellaneous functions doing a variety of little jobs follow ... |
418 |
* miscellaneous functions doing a variety of little jobs follow ... |