Convert Sigalgs processing to use ints
[openssl.git] / crypto / ui / ui_openssl.c
1 /*
2  * Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #include <openssl/e_os2.h>
11 #include <openssl/err.h>
12
13 /*
14  * need for #define _POSIX_C_SOURCE arises whenever you pass -ansi to gcc
15  * [maybe others?], because it masks interfaces not discussed in standard,
16  * sigaction and fileno included. -pedantic would be more appropriate for the
17  * intended purposes, but we can't prevent users from adding -ansi.
18  */
19 #if defined(OPENSSL_SYS_VXWORKS)
20 # include <sys/types.h>
21 #endif
22
23 #if !defined(_POSIX_C_SOURCE) && defined(OPENSSL_SYS_VMS)
24 # ifndef _POSIX_C_SOURCE
25 #  define _POSIX_C_SOURCE 2
26 # endif
27 #endif
28 #include <signal.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <errno.h>
32
33 #if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS)
34 # ifdef OPENSSL_UNISTD
35 #  include OPENSSL_UNISTD
36 # else
37 #  include <unistd.h>
38 # endif
39 /*
40  * If unistd.h defines _POSIX_VERSION, we conclude that we are on a POSIX
41  * system and have sigaction and termios.
42  */
43 # if defined(_POSIX_VERSION)
44
45 #  define SIGACTION
46 #  if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
47 #   define TERMIOS
48 #  endif
49
50 # endif
51 #endif
52
53 /* 06-Apr-92 Luke Brennan    Support for VMS */
54 #include "ui_locl.h"
55 #include "internal/cryptlib.h"
56
57 #ifdef OPENSSL_SYS_VMS          /* prototypes for sys$whatever */
58 # include <starlet.h>
59 # ifdef __DECC
60 #  pragma message disable DOLLARID
61 # endif
62 #endif
63
64 #ifdef WIN_CONSOLE_BUG
65 # include <windows.h>
66 # ifndef OPENSSL_SYS_WINCE
67 #  include <wincon.h>
68 # endif
69 #endif
70
71 /*
72  * There are 6 types of terminal interface supported, TERMIO, TERMIOS, VMS,
73  * MSDOS, WIN32 Console and SGTTY.
74  *
75  * If someone defines one of the macros TERMIO, TERMIOS or SGTTY, it will
76  * remain respected.  Otherwise, we default to TERMIOS except for a few
77  * systems that require something different.
78  *
79  * Note: we do not use SGTTY unless it's defined by the configuration.  We
80  * may eventually opt to remove it's use entirely.
81  */
82
83 #if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
84
85 # if defined(_LIBC)
86 #  undef  TERMIOS
87 #  define TERMIO
88 #  undef  SGTTY
89 /*
90  * We know that VMS, MSDOS, VXWORKS, use entirely other mechanisms.
91  */
92 # elif !defined(OPENSSL_SYS_VMS) \
93         && !defined(OPENSSL_SYS_MSDOS) \
94         && !defined(OPENSSL_SYS_VXWORKS)
95 #  define TERMIOS
96 #  undef  TERMIO
97 #  undef  SGTTY
98 # endif
99
100 #endif
101
102 #ifdef TERMIOS
103 # include <termios.h>
104 # define TTY_STRUCT             struct termios
105 # define TTY_FLAGS              c_lflag
106 # define TTY_get(tty,data)      tcgetattr(tty,data)
107 # define TTY_set(tty,data)      tcsetattr(tty,TCSANOW,data)
108 #endif
109
110 #ifdef TERMIO
111 # include <termio.h>
112 # define TTY_STRUCT             struct termio
113 # define TTY_FLAGS              c_lflag
114 # define TTY_get(tty,data)      ioctl(tty,TCGETA,data)
115 # define TTY_set(tty,data)      ioctl(tty,TCSETA,data)
116 #endif
117
118 #ifdef SGTTY
119 # include <sgtty.h>
120 # define TTY_STRUCT             struct sgttyb
121 # define TTY_FLAGS              sg_flags
122 # define TTY_get(tty,data)      ioctl(tty,TIOCGETP,data)
123 # define TTY_set(tty,data)      ioctl(tty,TIOCSETP,data)
124 #endif
125
126 #if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS)
127 # include <sys/ioctl.h>
128 #endif
129
130 #ifdef OPENSSL_SYS_MSDOS
131 # include <conio.h>
132 #endif
133
134 #ifdef OPENSSL_SYS_VMS
135 # include <ssdef.h>
136 # include <iodef.h>
137 # include <ttdef.h>
138 # include <descrip.h>
139 struct IOSB {
140     short iosb$w_value;
141     short iosb$w_count;
142     long iosb$l_info;
143 };
144 #endif
145
146 #ifndef NX509_SIG
147 # define NX509_SIG 32
148 #endif
149
150 /* Define globals.  They are protected by a lock */
151 #ifdef SIGACTION
152 static struct sigaction savsig[NX509_SIG];
153 #else
154 static void (*savsig[NX509_SIG]) (int);
155 #endif
156
157 #ifdef OPENSSL_SYS_VMS
158 static struct IOSB iosb;
159 static $DESCRIPTOR(terminal, "TT");
160 static long tty_orig[3], tty_new[3]; /* XXX Is there any guarantee that this
161                                       * will always suffice for the actual
162                                       * structures? */
163 static long status;
164 static unsigned short channel = 0;
165 #elif defined(_WIN32) && !defined(_WIN32_WCE)
166 static DWORD tty_orig, tty_new;
167 #else
168 # if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
169 static TTY_STRUCT tty_orig, tty_new;
170 # endif
171 #endif
172 static FILE *tty_in, *tty_out;
173 static int is_a_tty;
174
175 /* Declare static functions */
176 #if !defined(OPENSSL_SYS_WINCE)
177 static int read_till_nl(FILE *);
178 static void recsig(int);
179 static void pushsig(void);
180 static void popsig(void);
181 #endif
182 #if defined(OPENSSL_SYS_MSDOS) && !defined(_WIN32)
183 static int noecho_fgets(char *buf, int size, FILE *tty);
184 #endif
185 static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl);
186
187 static int read_string(UI *ui, UI_STRING *uis);
188 static int write_string(UI *ui, UI_STRING *uis);
189
190 static int open_console(UI *ui);
191 static int echo_console(UI *ui);
192 static int noecho_console(UI *ui);
193 static int close_console(UI *ui);
194
195 static UI_METHOD ui_openssl = {
196     "OpenSSL default user interface",
197     open_console,
198     write_string,
199     NULL,                       /* No flusher is needed for command lines */
200     read_string,
201     close_console,
202     NULL
203 };
204
205 /* The method with all the built-in thingies */
206 UI_METHOD *UI_OpenSSL(void)
207 {
208     return &ui_openssl;
209 }
210
211 /*
212  * The following function makes sure that info and error strings are printed
213  * before any prompt.
214  */
215 static int write_string(UI *ui, UI_STRING *uis)
216 {
217     switch (UI_get_string_type(uis)) {
218     case UIT_ERROR:
219     case UIT_INFO:
220         fputs(UI_get0_output_string(uis), tty_out);
221         fflush(tty_out);
222         break;
223     case UIT_NONE:
224     case UIT_PROMPT:
225     case UIT_VERIFY:
226     case UIT_BOOLEAN:
227         break;
228     }
229     return 1;
230 }
231
232 static int read_string(UI *ui, UI_STRING *uis)
233 {
234     int ok = 0;
235
236     switch (UI_get_string_type(uis)) {
237     case UIT_BOOLEAN:
238         fputs(UI_get0_output_string(uis), tty_out);
239         fputs(UI_get0_action_string(uis), tty_out);
240         fflush(tty_out);
241         return read_string_inner(ui, uis,
242                                  UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO,
243                                  0);
244     case UIT_PROMPT:
245         fputs(UI_get0_output_string(uis), tty_out);
246         fflush(tty_out);
247         return read_string_inner(ui, uis,
248                                  UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO,
249                                  1);
250     case UIT_VERIFY:
251         fprintf(tty_out, "Verifying - %s", UI_get0_output_string(uis));
252         fflush(tty_out);
253         if ((ok = read_string_inner(ui, uis,
254                                     UI_get_input_flags(uis) &
255                                     UI_INPUT_FLAG_ECHO, 1)) <= 0)
256             return ok;
257         if (strcmp(UI_get0_result_string(uis), UI_get0_test_string(uis)) != 0) {
258             fprintf(tty_out, "Verify failure\n");
259             fflush(tty_out);
260             return 0;
261         }
262         break;
263     case UIT_NONE:
264     case UIT_INFO:
265     case UIT_ERROR:
266         break;
267     }
268     return 1;
269 }
270
271 #if !defined(OPENSSL_SYS_WINCE)
272 /* Internal functions to read a string without echoing */
273 static int read_till_nl(FILE *in)
274 {
275 # define SIZE 4
276     char buf[SIZE + 1];
277
278     do {
279         if (!fgets(buf, SIZE, in))
280             return 0;
281     } while (strchr(buf, '\n') == NULL);
282     return 1;
283 }
284
285 static volatile sig_atomic_t intr_signal;
286 #endif
287
288 static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
289 {
290     static int ps;
291     int ok;
292     char result[BUFSIZ];
293     int maxsize = BUFSIZ - 1;
294 #if !defined(OPENSSL_SYS_WINCE)
295     char *p = NULL;
296     int echo_eol = !echo;
297
298     intr_signal = 0;
299     ok = 0;
300     ps = 0;
301
302     pushsig();
303     ps = 1;
304
305     if (!echo && !noecho_console(ui))
306         goto error;
307     ps = 2;
308
309     result[0] = '\0';
310 # if defined(_WIN32)
311     if (is_a_tty) {
312         DWORD numread;
313 #  if defined(CP_UTF8)
314         if (GetEnvironmentVariableW(L"OPENSSL_WIN32_UTF8", NULL, 0) != 0) {
315             WCHAR wresult[BUFSIZ];
316
317             if (ReadConsoleW(GetStdHandle(STD_INPUT_HANDLE),
318                          wresult, maxsize, &numread, NULL)) {
319                 if (numread >= 2 &&
320                     wresult[numread-2] == L'\r' &&
321                     wresult[numread-1] == L'\n') {
322                     wresult[numread-2] = L'\n';
323                     numread--;
324                 }
325                 wresult[numread] = '\0';
326                 if (WideCharToMultiByte(CP_UTF8, 0, wresult, -1,
327                                         result, sizeof(result), NULL, 0) > 0)
328                     p = result;
329
330                 OPENSSL_cleanse(wresult, sizeof(wresult));
331             }
332         } else
333 #  endif
334         if (ReadConsoleA(GetStdHandle(STD_INPUT_HANDLE),
335                          result, maxsize, &numread, NULL)) {
336             if (numread >= 2 &&
337                 result[numread-2] == '\r' && result[numread-1] == '\n') {
338                 result[numread-2] = '\n';
339                 numread--;
340             }
341             result[numread] = '\0';
342             p = result;
343         }
344     } else
345 # elif defined(OPENSSL_SYS_MSDOS)
346     if (!echo) {
347         noecho_fgets(result, maxsize, tty_in);
348         p = result;             /* FIXME: noecho_fgets doesn't return errors */
349     } else
350 # endif
351     p = fgets(result, maxsize, tty_in);
352     if (p == NULL)
353         goto error;
354     if (feof(tty_in))
355         goto error;
356     if (ferror(tty_in))
357         goto error;
358     if ((p = (char *)strchr(result, '\n')) != NULL) {
359         if (strip_nl)
360             *p = '\0';
361     } else if (!read_till_nl(tty_in))
362         goto error;
363     if (UI_set_result(ui, uis, result) >= 0)
364         ok = 1;
365
366  error:
367     if (intr_signal == SIGINT)
368         ok = -1;
369     if (echo_eol)
370         fprintf(tty_out, "\n");
371     if (ps >= 2 && !echo && !echo_console(ui))
372         ok = 0;
373
374     if (ps >= 1)
375         popsig();
376 #else
377     ok = 1;
378 #endif
379
380     OPENSSL_cleanse(result, BUFSIZ);
381     return ok;
382 }
383
384 /* Internal functions to open, handle and close a channel to the console.  */
385 static int open_console(UI *ui)
386 {
387     CRYPTO_THREAD_write_lock(ui->lock);
388     is_a_tty = 1;
389
390 #if defined(OPENSSL_SYS_VXWORKS)
391     tty_in = stdin;
392     tty_out = stderr;
393 #elif defined(_WIN32) && !defined(_WIN32_WCE)
394     if ((tty_out = fopen("conout$", "w")) == NULL)
395         tty_out = stderr;
396
397     if (GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &tty_orig)) {
398         tty_in = stdin;
399     } else {
400         is_a_tty = 0;
401         if ((tty_in = fopen("conin$", "r")) == NULL)
402             tty_in = stdin;
403     }
404 #else
405 # ifdef OPENSSL_SYS_MSDOS
406 #  define DEV_TTY "con"
407 # else
408 #  define DEV_TTY "/dev/tty"
409 # endif
410     if ((tty_in = fopen(DEV_TTY, "r")) == NULL)
411         tty_in = stdin;
412     if ((tty_out = fopen(DEV_TTY, "w")) == NULL)
413         tty_out = stderr;
414 #endif
415
416 #if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
417     if (TTY_get(fileno(tty_in), &tty_orig) == -1) {
418 # ifdef ENOTTY
419         if (errno == ENOTTY)
420             is_a_tty = 0;
421         else
422 # endif
423 # ifdef EINVAL
424             /*
425              * Ariel Glenn ariel@columbia.edu reports that solaris can return
426              * EINVAL instead.  This should be ok
427              */
428         if (errno == EINVAL)
429             is_a_tty = 0;
430         else
431 # endif
432 # ifdef ENODEV
433             /*
434              * MacOS X returns ENODEV (Operation not supported by device),
435              * which seems appropriate.
436              */
437         if (errno == ENODEV)
438             is_a_tty = 0;
439         else
440 # endif
441             {
442                 char tmp_num[10];
443                 BIO_snprintf(tmp_num, sizeof(tmp_num) - 1, "%d", errno);
444                 UIerr(UI_F_OPEN_CONSOLE, UI_R_UNKNOWN_TTYGET_ERRNO_VALUE);
445                 ERR_add_error_data(2, "errno=", tmp_num);
446
447                 return 0;
448             }
449     }
450 #endif
451 #ifdef OPENSSL_SYS_VMS
452     status = sys$assign(&terminal, &channel, 0, 0);
453
454     /* if there isn't a TT device, something is very wrong */
455     if (status != SS$_NORMAL) {
456         char tmp_num[12];
457
458         BIO_snprintf(tmp_num, sizeof(tmp_num) - 1, "%%X%08X", status);
459         UIerr(UI_F_OPEN_CONSOLE, UI_R_SYSASSIGN_ERROR);
460         ERR_add_error_data(2, "status=", tmp_num);
461         return 0;
462     }
463
464     status = sys$qiow(0, channel, IO$_SENSEMODE, &iosb, 0, 0, tty_orig, 12,
465                       0, 0, 0, 0);
466
467     /* If IO$_SENSEMODE doesn't work, this is not a terminal device */
468     if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
469         is_a_tty = 0;
470 #endif
471     return 1;
472 }
473
474 static int noecho_console(UI *ui)
475 {
476 #ifdef TTY_FLAGS
477     memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));
478     tty_new.TTY_FLAGS &= ~ECHO;
479 #endif
480
481 #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
482     if (is_a_tty && (TTY_set(fileno(tty_in), &tty_new) == -1))
483         return 0;
484 #endif
485 #ifdef OPENSSL_SYS_VMS
486     if (is_a_tty) {
487         tty_new[0] = tty_orig[0];
488         tty_new[1] = tty_orig[1] | TT$M_NOECHO;
489         tty_new[2] = tty_orig[2];
490         status = sys$qiow(0, channel, IO$_SETMODE, &iosb, 0, 0, tty_new, 12,
491                           0, 0, 0, 0);
492         if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) {
493             char tmp_num[2][12];
494
495             BIO_snprintf(tmp_num[0], sizeof(tmp_num[0]) - 1, "%%X%08X",
496                          status);
497             BIO_snprintf(tmp_num[1], sizeof(tmp_num[1]) - 1, "%%X%08X",
498                          iosb.iosb$w_value);
499             UIerr(UI_F_NOECHO_CONSOLE, UI_R_SYSQIOW_ERROR);
500             ERR_add_error_data(5, "status=", tmp_num[0],
501                                ",", "iosb.iosb$w_value=", tmp_num[1]);
502             return 0;
503         }
504     }
505 #endif
506 #if defined(_WIN32) && !defined(_WIN32_WCE)
507     if (is_a_tty) {
508         tty_new = tty_orig;
509         tty_new &= ~ENABLE_ECHO_INPUT;
510         SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), tty_new);
511     }
512 #endif
513     return 1;
514 }
515
516 static int echo_console(UI *ui)
517 {
518 #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
519     memcpy(&(tty_new), &(tty_orig), sizeof(tty_orig));
520     tty_new.TTY_FLAGS |= ECHO;
521 #endif
522
523 #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
524     if (is_a_tty && (TTY_set(fileno(tty_in), &tty_new) == -1))
525         return 0;
526 #endif
527 #ifdef OPENSSL_SYS_VMS
528     if (is_a_tty) {
529         tty_new[0] = tty_orig[0];
530         tty_new[1] = tty_orig[1] & ~TT$M_NOECHO;
531         tty_new[2] = tty_orig[2];
532         status = sys$qiow(0, channel, IO$_SETMODE, &iosb, 0, 0, tty_new, 12,
533                           0, 0, 0, 0);
534         if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL)) {
535             char tmp_num[2][12];
536
537             BIO_snprintf(tmp_num[0], sizeof(tmp_num[0]) - 1, "%%X%08X",
538                          status);
539             BIO_snprintf(tmp_num[1], sizeof(tmp_num[1]) - 1, "%%X%08X",
540                          iosb.iosb$w_value);
541             UIerr(UI_F_ECHO_CONSOLE, UI_R_SYSQIOW_ERROR);
542             ERR_add_error_data(5, "status=", tmp_num[0],
543                                ",", "iosb.iosb$w_value=", tmp_num[1]);
544             return 0;
545         }
546     }
547 #endif
548 #if defined(_WIN32) && !defined(_WIN32_WCE)
549     if (is_a_tty) {
550         tty_new = tty_orig;
551         tty_new |= ENABLE_ECHO_INPUT;
552         SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), tty_new);
553     }
554 #endif
555     return 1;
556 }
557
558 static int close_console(UI *ui)
559 {
560     if (tty_in != stdin)
561         fclose(tty_in);
562     if (tty_out != stderr)
563         fclose(tty_out);
564 #ifdef OPENSSL_SYS_VMS
565     status = sys$dassgn(channel);
566     if (status != SS$_NORMAL) {
567         char tmp_num[12];
568
569         BIO_snprintf(tmp_num, sizeof(tmp_num) - 1, "%%X%08X", status);
570         UIerr(UI_F_CLOSE_CONSOLE, UI_R_SYSDASSGN_ERROR);
571         ERR_add_error_data(2, "status=", tmp_num);
572         return 0;
573     }
574 #endif
575     CRYPTO_THREAD_unlock(ui->lock);
576
577     return 1;
578 }
579
580 #if !defined(OPENSSL_SYS_WINCE)
581 /* Internal functions to handle signals and act on them */
582 static void pushsig(void)
583 {
584 # ifndef OPENSSL_SYS_WIN32
585     int i;
586 # endif
587 # ifdef SIGACTION
588     struct sigaction sa;
589
590     memset(&sa, 0, sizeof(sa));
591     sa.sa_handler = recsig;
592 # endif
593
594 # ifdef OPENSSL_SYS_WIN32
595     savsig[SIGABRT] = signal(SIGABRT, recsig);
596     savsig[SIGFPE] = signal(SIGFPE, recsig);
597     savsig[SIGILL] = signal(SIGILL, recsig);
598     savsig[SIGINT] = signal(SIGINT, recsig);
599     savsig[SIGSEGV] = signal(SIGSEGV, recsig);
600     savsig[SIGTERM] = signal(SIGTERM, recsig);
601 # else
602     for (i = 1; i < NX509_SIG; i++) {
603 #  ifdef SIGUSR1
604         if (i == SIGUSR1)
605             continue;
606 #  endif
607 #  ifdef SIGUSR2
608         if (i == SIGUSR2)
609             continue;
610 #  endif
611 #  ifdef SIGKILL
612         if (i == SIGKILL)       /* We can't make any action on that. */
613             continue;
614 #  endif
615 #  ifdef SIGACTION
616         sigaction(i, &sa, &savsig[i]);
617 #  else
618         savsig[i] = signal(i, recsig);
619 #  endif
620     }
621 # endif
622
623 # ifdef SIGWINCH
624     signal(SIGWINCH, SIG_DFL);
625 # endif
626 }
627
628 static void popsig(void)
629 {
630 # ifdef OPENSSL_SYS_WIN32
631     signal(SIGABRT, savsig[SIGABRT]);
632     signal(SIGFPE, savsig[SIGFPE]);
633     signal(SIGILL, savsig[SIGILL]);
634     signal(SIGINT, savsig[SIGINT]);
635     signal(SIGSEGV, savsig[SIGSEGV]);
636     signal(SIGTERM, savsig[SIGTERM]);
637 # else
638     int i;
639     for (i = 1; i < NX509_SIG; i++) {
640 #  ifdef SIGUSR1
641         if (i == SIGUSR1)
642             continue;
643 #  endif
644 #  ifdef SIGUSR2
645         if (i == SIGUSR2)
646             continue;
647 #  endif
648 #  ifdef SIGACTION
649         sigaction(i, &savsig[i], NULL);
650 #  else
651         signal(i, savsig[i]);
652 #  endif
653     }
654 # endif
655 }
656
657 static void recsig(int i)
658 {
659     intr_signal = i;
660 }
661 #endif
662
663 /* Internal functions specific for Windows */
664 #if defined(OPENSSL_SYS_MSDOS) && !defined(_WIN32)
665 static int noecho_fgets(char *buf, int size, FILE *tty)
666 {
667     int i;
668     char *p;
669
670     p = buf;
671     for (;;) {
672         if (size == 0) {
673             *p = '\0';
674             break;
675         }
676         size--;
677 # if defined(_WIN32)
678         i = _getch();
679 # else
680         i = getch();
681 # endif
682         if (i == '\r')
683             i = '\n';
684         *(p++) = i;
685         if (i == '\n') {
686             *p = '\0';
687             break;
688         }
689     }
690 # ifdef WIN_CONSOLE_BUG
691     /*
692      * Win95 has several evil console bugs: one of these is that the last
693      * character read using getch() is passed to the next read: this is
694      * usually a CR so this can be trouble. No STDIO fix seems to work but
695      * flushing the console appears to do the trick.
696      */
697     {
698         HANDLE inh;
699         inh = GetStdHandle(STD_INPUT_HANDLE);
700         FlushConsoleInputBuffer(inh);
701     }
702 # endif
703     return (strlen(buf));
704 }
705 #endif