793846cbc64f4b86a67917574d40b77f0dcd0aa6
[openssl.git] / crypto / ui / ui_openssl.c
1 /* crypto/ui/ui_openssl.c -*- mode:C; c-file-style: "eay" -*- */
2 /* Written by Richard Levitte (richard@levitte.org) and others
3  * for the OpenSSL project 2001.
4  */
5 /* ====================================================================
6  * Copyright (c) 2001 The OpenSSL Project.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer. 
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. All advertising materials mentioning features or use of this
21  *    software must display the following acknowledgment:
22  *    "This product includes software developed by the OpenSSL Project
23  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24  *
25  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26  *    endorse or promote products derived from this software without
27  *    prior written permission. For written permission, please contact
28  *    openssl-core@openssl.org.
29  *
30  * 5. Products derived from this software may not be called "OpenSSL"
31  *    nor may "OpenSSL" appear in their names without prior written
32  *    permission of the OpenSSL Project.
33  *
34  * 6. Redistributions of any form whatsoever must retain the following
35  *    acknowledgment:
36  *    "This product includes software developed by the OpenSSL Project
37  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38  *
39  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50  * OF THE POSSIBILITY OF SUCH DAMAGE.
51  * ====================================================================
52  *
53  * This product includes cryptographic software written by Eric Young
54  * (eay@cryptsoft.com).  This product includes software written by Tim
55  * Hudson (tjh@cryptsoft.com).
56  *
57  */
58
59 /* The lowest level part of this file was previously in crypto/des/read_pwd.c,
60  * Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
61  * All rights reserved.
62  *
63  * This package is an SSL implementation written
64  * by Eric Young (eay@cryptsoft.com).
65  * The implementation was written so as to conform with Netscapes SSL.
66  * 
67  * This library is free for commercial and non-commercial use as long as
68  * the following conditions are aheared to.  The following conditions
69  * apply to all code found in this distribution, be it the RC4, RSA,
70  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
71  * included with this distribution is covered by the same copyright terms
72  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
73  * 
74  * Copyright remains Eric Young's, and as such any Copyright notices in
75  * the code are not to be removed.
76  * If this package is used in a product, Eric Young should be given attribution
77  * as the author of the parts of the library used.
78  * This can be in the form of a textual message at program startup or
79  * in documentation (online or textual) provided with the package.
80  * 
81  * Redistribution and use in source and binary forms, with or without
82  * modification, are permitted provided that the following conditions
83  * are met:
84  * 1. Redistributions of source code must retain the copyright
85  *    notice, this list of conditions and the following disclaimer.
86  * 2. Redistributions in binary form must reproduce the above copyright
87  *    notice, this list of conditions and the following disclaimer in the
88  *    documentation and/or other materials provided with the distribution.
89  * 3. All advertising materials mentioning features or use of this software
90  *    must display the following acknowledgement:
91  *    "This product includes cryptographic software written by
92  *     Eric Young (eay@cryptsoft.com)"
93  *    The word 'cryptographic' can be left out if the rouines from the library
94  *    being used are not cryptographic related :-).
95  * 4. If you include any Windows specific code (or a derivative thereof) from 
96  *    the apps directory (application code) you must include an acknowledgement:
97  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
98  * 
99  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
100  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
101  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
102  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
103  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
104  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
105  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
106  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
107  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
108  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
109  * SUCH DAMAGE.
110  * 
111  * The licence and distribution terms for any publically available version or
112  * derivative of this code cannot be changed.  i.e. this code cannot simply be
113  * copied and put under another distribution licence
114  * [including the GNU Public Licence.]
115  */
116
117
118 #include <openssl/e_os2.h>
119
120 #if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS)
121 # ifdef OPENSSL_UNISTD
122 #  include OPENSSL_UNISTD
123 # else
124 #  include <unistd.h>
125 # endif
126 /* If unistd.h defines _POSIX_VERSION, we conclude that we
127  * are on a POSIX system and have sigaction and termios. */
128 # if defined(_POSIX_VERSION)
129
130 #  define SIGACTION
131 #  if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
132 #   define TERMIOS
133 #  endif
134
135 # endif
136 #endif
137
138 #ifdef WIN16TTY
139 # undef OPENSSL_SYS_WIN16
140 # undef WIN16
141 # undef _WINDOWS
142 # include <graph.h>
143 #endif
144
145 /* 06-Apr-92 Luke Brennan    Support for VMS */
146 #include "ui_locl.h"
147 #include "cryptlib.h"
148 #include <signal.h>
149 #include <stdio.h>
150 #include <string.h>
151 #include <errno.h>
152
153 #ifdef OPENSSL_SYS_VMS          /* prototypes for sys$whatever */
154 # include <starlet.h>
155 # ifdef __DECC
156 #  pragma message disable DOLLARID
157 # endif
158 #endif
159
160 #ifdef WIN_CONSOLE_BUG
161 # include <windows.h>
162 # include <wincon.h>
163 #endif
164
165
166 /* There are 5 types of terminal interface supported,
167  * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
168  */
169
170 #if defined(__sgi) && !defined(TERMIOS)
171 # define TERMIOS
172 # undef  TERMIO
173 # undef  SGTTY
174 #endif
175
176 #if defined(linux) && !defined(TERMIO)
177 # undef  TERMIOS
178 # define TERMIO
179 # undef  SGTTY
180 #endif
181
182 #ifdef _LIBC
183 # undef  TERMIOS
184 # define TERMIO
185 # undef  SGTTY
186 #endif
187
188 #if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(MAC_OS_GUSI_SOURCE)
189 # undef  TERMIOS
190 # undef  TERMIO
191 # define SGTTY
192 #endif
193
194 #if defined(OPENSSL_SYS_VXWORKS)
195 #undef TERMIOS
196 #undef TERMIO
197 #undef SGTTY
198 #endif
199
200 #ifdef TERMIOS
201 # include <termios.h>
202 # define TTY_STRUCT             struct termios
203 # define TTY_FLAGS              c_lflag
204 # define TTY_get(tty,data)      tcgetattr(tty,data)
205 # define TTY_set(tty,data)      tcsetattr(tty,TCSANOW,data)
206 #endif
207
208 #ifdef TERMIO
209 # include <termio.h>
210 # define TTY_STRUCT             struct termio
211 # define TTY_FLAGS              c_lflag
212 # define TTY_get(tty,data)      ioctl(tty,TCGETA,data)
213 # define TTY_set(tty,data)      ioctl(tty,TCSETA,data)
214 #endif
215
216 #ifdef SGTTY
217 # include <sgtty.h>
218 # define TTY_STRUCT             struct sgttyb
219 # define TTY_FLAGS              sg_flags
220 # define TTY_get(tty,data)      ioctl(tty,TIOCGETP,data)
221 # define TTY_set(tty,data)      ioctl(tty,TIOCSETP,data)
222 #endif
223
224 #if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_SUNOS)
225 # include <sys/ioctl.h>
226 #endif
227
228 #ifdef OPENSSL_SYS_MSDOS
229 # include <conio.h>
230 #endif
231
232 #ifdef OPENSSL_SYS_VMS
233 # include <ssdef.h>
234 # include <iodef.h>
235 # include <ttdef.h>
236 # include <descrip.h>
237 struct IOSB {
238         short iosb$w_value;
239         short iosb$w_count;
240         long  iosb$l_info;
241         };
242 #endif
243
244 #ifdef OPENSSL_SYS_SUNOS
245         typedef int sig_atomic_t;
246 #endif
247
248 #if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE)
249 /*
250  * This one needs work. As a matter of fact the code is unoperational
251  * and this is only a trick to get it compiled.
252  *                                      <appro@fy.chalmers.se>
253  */
254 # define TTY_STRUCT int
255 #endif
256
257 #ifndef NX509_SIG
258 # define NX509_SIG 32
259 #endif
260
261
262 /* Define globals.  They are protected by a lock */
263 #ifdef SIGACTION
264 static struct sigaction savsig[NX509_SIG];
265 #else
266 static void (*savsig[NX509_SIG])(int );
267 #endif
268
269 #ifdef OPENSSL_SYS_VMS
270 static struct IOSB iosb;
271 static $DESCRIPTOR(terminal,"TT");
272 static long tty_orig[3], tty_new[3]; /* XXX   Is there any guarantee that this will always suffice for the actual structures? */
273 static long status;
274 static unsigned short channel = 0;
275 #else
276 #if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
277 static TTY_STRUCT tty_orig,tty_new;
278 #endif
279 #endif
280 static FILE *tty_in, *tty_out;
281 static int is_a_tty;
282
283 /* Declare static functions */
284 static void read_till_nl(FILE *);
285 static void recsig(int);
286 static void pushsig(void);
287 static void popsig(void);
288 #if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
289 static int noecho_fgets(char *buf, int size, FILE *tty);
290 #endif
291 static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl);
292
293 static int read_string(UI *ui, UI_STRING *uis);
294 static int write_string(UI *ui, UI_STRING *uis);
295
296 static int open_console(UI *ui);
297 static int echo_console(UI *ui);
298 static int noecho_console(UI *ui);
299 static int close_console(UI *ui);
300
301 static UI_METHOD ui_openssl =
302         {
303         "OpenSSL default user interface",
304         open_console,
305         write_string,
306         NULL,                   /* No flusher is needed for command lines */
307         read_string,
308         close_console,
309         NULL
310         };
311
312 /* The method with all the built-in thingies */
313 UI_METHOD *UI_OpenSSL(void)
314         {
315         return &ui_openssl;
316         }
317
318 /* The following function makes sure that info and error strings are printed
319    before any prompt. */
320 static int write_string(UI *ui, UI_STRING *uis)
321         {
322         switch (UI_get_string_type(uis))
323                 {
324         case UIT_ERROR:
325         case UIT_INFO:
326                 fputs(UI_get0_output_string(uis), tty_out);
327                 fflush(tty_out);
328                 break;
329         default:
330                 break;
331                 }
332         return 1;
333         }
334
335 static int read_string(UI *ui, UI_STRING *uis)
336         {
337         int ok = 0;
338
339         switch (UI_get_string_type(uis))
340                 {
341         case UIT_BOOLEAN:
342                 fputs(UI_get0_output_string(uis), tty_out);
343                 fputs(UI_get0_action_string(uis), tty_out);
344                 fflush(tty_out);
345                 return read_string_inner(ui, uis,
346                         UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 0);
347         case UIT_PROMPT:
348                 fputs(UI_get0_output_string(uis), tty_out);
349                 fflush(tty_out);
350                 return read_string_inner(ui, uis,
351                         UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1);
352         case UIT_VERIFY:
353                 fprintf(tty_out,"Verifying - %s",
354                         UI_get0_output_string(uis));
355                 fflush(tty_out);
356                 if ((ok = read_string_inner(ui, uis,
357                         UI_get_input_flags(uis) & UI_INPUT_FLAG_ECHO, 1)) <= 0)
358                         return ok;
359                 if (strcmp(UI_get0_result_string(uis),
360                         UI_get0_test_string(uis)) != 0)
361                         {
362                         fprintf(tty_out,"Verify failure\n");
363                         fflush(tty_out);
364                         return 0;
365                         }
366                 break;
367         default:
368                 break;
369                 }
370         return 1;
371         }
372
373
374 /* Internal functions to read a string without echoing */
375 static void read_till_nl(FILE *in)
376         {
377 #define SIZE 4
378         char buf[SIZE+1];
379
380         do      {
381                 fgets(buf,SIZE,in);
382                 } while (strchr(buf,'\n') == NULL);
383         }
384
385 static volatile sig_atomic_t intr_signal;
386
387 static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl)
388         {
389         static int ps;
390         int ok;
391         char result[BUFSIZ];
392         int maxsize = BUFSIZ-1;
393         char *p;
394
395 #ifndef OPENSSL_SYS_WIN16
396         intr_signal=0;
397         ok=0;
398         ps=0;
399
400         pushsig();
401         ps=1;
402
403         if (!echo && !noecho_console(ui))
404                 goto error;
405         ps=2;
406
407         result[0]='\0';
408 #ifdef OPENSSL_SYS_MSDOS
409         if (!echo)
410                 {
411                 noecho_fgets(result,maxsize,tty_in);
412                 p=result; /* FIXME: noecho_fgets doesn't return errors */
413                 }
414         else
415                 p=fgets(result,maxsize,tty_in);
416 #else
417         p=fgets(result,maxsize,tty_in);
418 #endif
419         if(!p)
420                 goto error;
421         if (feof(tty_in)) goto error;
422         if (ferror(tty_in)) goto error;
423         if ((p=(char *)strchr(result,'\n')) != NULL)
424                 {
425                 if (strip_nl)
426                         *p='\0';
427                 }
428         else
429                 read_till_nl(tty_in);
430         if (UI_set_result(ui, uis, result) >= 0)
431                 ok=1;
432
433 error:
434         if (intr_signal == SIGINT)
435                 ok=-1;
436         if (!echo) fprintf(tty_out,"\n");
437         if (ps >= 2 && !echo && !echo_console(ui))
438                 ok=0;
439
440         if (ps >= 1)
441                 popsig();
442 #else
443         ok=1;
444 #endif
445
446         memset(result,0,BUFSIZ);
447         return ok;
448         }
449
450
451 /* Internal functions to open, handle and close a channel to the console.  */
452 static int open_console(UI *ui)
453         {
454         CRYPTO_w_lock(CRYPTO_LOCK_UI);
455         is_a_tty = 1;
456
457 #if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS)
458         tty_in=stdin;
459         tty_out=stderr;
460 #else
461 #  ifdef OPENSSL_SYS_MSDOS
462 #    define DEV_TTY "con"
463 #  else
464 #    define DEV_TTY "/dev/tty"
465 #  endif
466         if ((tty_in=fopen(DEV_TTY,"r")) == NULL)
467                 tty_in=stdin;
468         if ((tty_out=fopen(DEV_TTY,"w")) == NULL)
469                 tty_out=stderr;
470 #endif
471
472 #if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
473         if (TTY_get(fileno(tty_in),&tty_orig) == -1)
474                 {
475 #ifdef ENOTTY
476                 if (errno == ENOTTY)
477                         is_a_tty=0;
478                 else
479 #endif
480 #ifdef EINVAL
481                 /* Ariel Glenn ariel@columbia.edu reports that solaris
482                  * can return EINVAL instead.  This should be ok */
483                 if (errno == EINVAL)
484                         is_a_tty=0;
485                 else
486 #endif
487                         return 0;
488                 }
489 #endif
490 #ifdef OPENSSL_SYS_VMS
491         status = sys$assign(&terminal,&channel,0,0);
492         if (status != SS$_NORMAL)
493                 return 0;
494         status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
495         if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
496                 return 0;
497 #endif
498         return 1;
499         }
500
501 static int noecho_console(UI *ui)
502         {
503 #ifdef TTY_FLAGS
504         memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
505         tty_new.TTY_FLAGS &= ~ECHO;
506 #endif
507
508 #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
509         if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
510                 return 0;
511 #endif
512 #ifdef OPENSSL_SYS_VMS
513         tty_new[0] = tty_orig[0];
514         tty_new[1] = tty_orig[1] | TT$M_NOECHO;
515         tty_new[2] = tty_orig[2];
516         status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
517         if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
518                 return 0;
519 #endif
520         return 1;
521         }
522
523 static int echo_console(UI *ui)
524         {
525 #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
526         memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
527         tty_new.TTY_FLAGS |= ECHO;
528 #endif
529
530 #if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
531         if (is_a_tty && (TTY_set(fileno(tty_in),&tty_new) == -1))
532                 return 0;
533 #endif
534 #ifdef OPENSSL_SYS_VMS
535         tty_new[0] = tty_orig[0];
536         tty_new[1] = tty_orig[1] & ~TT$M_NOECHO;
537         tty_new[2] = tty_orig[2];
538         status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
539         if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
540                 return 0;
541 #endif
542         return 1;
543         }
544
545 static int close_console(UI *ui)
546         {
547         if (tty_in != stderr) fclose(tty_in);
548         if (tty_out != stderr) fclose(tty_out);
549 #ifdef OPENSSL_SYS_VMS
550         status = sys$dassgn(channel);
551 #endif
552         CRYPTO_w_unlock(CRYPTO_LOCK_UI);
553
554         return 1;
555         }
556
557
558 /* Internal functions to handle signals and act on them */
559 static void pushsig(void)
560         {
561         int i;
562 #ifdef SIGACTION
563         struct sigaction sa;
564
565         memset(&sa,0,sizeof sa);
566         sa.sa_handler=recsig;
567 #endif
568
569         for (i=1; i<NX509_SIG; i++)
570                 {
571 #ifdef SIGUSR1
572                 if (i == SIGUSR1)
573                         continue;
574 #endif
575 #ifdef SIGUSR2
576                 if (i == SIGUSR2)
577                         continue;
578 #endif
579 #ifdef SIGKILL
580                 if (i == SIGKILL) /* We can't make any action on that. */
581                         continue;
582 #endif
583 #ifdef SIGACTION
584                 sigaction(i,&sa,&savsig[i]);
585 #else
586                 savsig[i]=signal(i,recsig);
587 #endif
588                 }
589
590 #ifdef SIGWINCH
591         signal(SIGWINCH,SIG_DFL);
592 #endif
593         }
594
595 static void popsig(void)
596         {
597         int i;
598
599         for (i=1; i<NX509_SIG; i++)
600                 {
601 #ifdef SIGUSR1
602                 if (i == SIGUSR1)
603                         continue;
604 #endif
605 #ifdef SIGUSR2
606                 if (i == SIGUSR2)
607                         continue;
608 #endif
609 #ifdef SIGACTION
610                 sigaction(i,&savsig[i],NULL);
611 #else
612                 signal(i,savsig[i]);
613 #endif
614                 }
615         }
616
617 static void recsig(int i)
618         {
619         intr_signal=i;
620         }
621
622 /* Internal functions specific for Windows */
623 #if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
624 static int noecho_fgets(char *buf, int size, FILE *tty)
625         {
626         int i;
627         char *p;
628
629         p=buf;
630         for (;;)
631                 {
632                 if (size == 0)
633                         {
634                         *p='\0';
635                         break;
636                         }
637                 size--;
638 #ifdef WIN16TTY
639                 i=_inchar();
640 #else
641                 i=getch();
642 #endif
643                 if (i == '\r') i='\n';
644                 *(p++)=i;
645                 if (i == '\n')
646                         {
647                         *p='\0';
648                         break;
649                         }
650                 }
651 #ifdef WIN_CONSOLE_BUG
652 /* Win95 has several evil console bugs: one of these is that the
653  * last character read using getch() is passed to the next read: this is
654  * usually a CR so this can be trouble. No STDIO fix seems to work but
655  * flushing the console appears to do the trick.
656  */
657                 {
658                         HANDLE inh;
659                         inh = GetStdHandle(STD_INPUT_HANDLE);
660                         FlushConsoleInputBuffer(inh);
661                 }
662 #endif
663         return(strlen(buf));
664         }
665 #endif