Add support for tab-completion when selecting by rule
[alpine.git] / pith / osdep / canonicl.c
blob187f398df8745209aea3e386408cc67017a52db1
1 /*
2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006 University of Washington
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
15 #include "../../c-client/mail.h"
16 extern unsigned char *lcase(unsigned char *);
18 #ifdef _WINDOWS
19 /* wingdi.h uses ERROR (!) and we aren't using the c-client ERROR so... */
20 #undef ERROR
21 #endif
23 #include <system.h>
25 #include "canonicl.h"
28 /*----------------------------------------------------------------------
29 Return canonical form of host name ala c-client (UNIX version).
31 Args: host -- The host name
33 Result: Canonical form, or input argument (worst case)
35 You can call it twice without worrying about copying
36 the results, but not more than twice.
37 ----*/
38 char *
39 canonical_name(char *host)
41 struct hostent *hent;
42 char tmp[MAILTMPLEN];
43 static int whichbuf = 0;
44 static char buf[2][NETMAXHOST+1];
45 char *b;
47 whichbuf = (whichbuf + 1) % 2;
48 b = buf[whichbuf];
50 /* domain literal is easy */
51 if (host[0] == '[' && host[(strlen (host))-1] == ']')
52 strncpy(b, host, NETMAXHOST);
53 else{
54 strncpy(tmp, host, sizeof(tmp)-1);
55 tmp[sizeof(tmp)-1] = '\0';
57 hent = gethostbyname((char *) lcase((unsigned char *) tmp));
58 if(hent && hent->h_name)
59 strncpy(b, hent->h_name, NETMAXHOST);
60 else
61 strncpy(b, host, NETMAXHOST);
64 b[NETMAXHOST] = '\0';
65 return(b);