2 * env.c -- small service routines
4 * For license terms, see the file COPYING in this directory.
10 #if defined(STDC_HEADERS)
13 #if defined(HAVE_UNISTD_H)
19 #ifdef HAVE_GETHOSTBYNAME
21 #endif /* HAVE_GETHOSTBYNAME */
22 #include "fetchmail.h"
24 extern char *getenv(); /* needed on sysV68 R3V7.1. */
26 extern char *program_name;
28 void envquery(int argc, char **argv)
29 /* set up basic stuff from the environment (including the rc file name) */
33 if ((program_name = strrchr(argv[0], '/')) != NULL)
36 program_name = argv[0];
38 if ((user = getenv("USER")) == (char *)NULL)
39 user = getenv("LOGNAME");
41 if ((user == (char *)NULL) || (home = getenv("HOME")) == (char *)NULL)
43 if ((pw = getpwuid(getuid())) != NULL)
51 "%s: can't find your name and home directory!\n",
57 #define RCFILE_NAME ".fetchmailrc"
58 rcfile = (char *) xmalloc(strlen(home)+strlen(RCFILE_NAME)+2);
59 /* avoid //.fetchmailrc */
60 if (strcmp(home, "/") != 0) {
66 strcat(rcfile, RCFILE_NAME);
70 /* get the FQDN of the machine we're running */
72 char tmpbuf[HOSTLEN+1];
74 if (gethostname(tmpbuf, sizeof(tmpbuf)))
76 fprintf(stderr, "%s: can't determine your host!",
80 #ifdef HAVE_GETHOSTBYNAME
81 /* if we got a . in the hostname assume it is a FQDN */
82 if (strchr(tmpbuf, '.') == NULL)
86 /* if we got a basename (as we do in Linux) make a FQDN of it */
87 hp = gethostbyname(tmpbuf);
88 if (hp == (struct hostent *) NULL)
90 /* exit with error message */
92 "gethostbyname failed for %s\n", tmpbuf);
95 return(xstrdup(hp->h_name));
98 #endif /* HAVE_GETHOSTBYNAME */
99 return(xstrdup(tmpbuf));
103 const char *showproto(int proto)
104 /* protocol index to protocol name mapping */
108 case P_AUTO: return("auto"); break;
110 case P_POP2: return("POP2"); break;
111 #endif /* POP2_ENABLE */
112 case P_POP3: return("POP3"); break;
113 case P_IMAP: return("IMAP"); break;
114 case P_IMAP_K4: return("IMAP-K4"); break;
116 case P_IMAP_GSS: return("IMAP-GSS"); break;
118 case P_APOP: return("APOP"); break;
119 case P_RPOP: return("RPOP"); break;
120 case P_ETRN: return("ETRN"); break;
121 default: return("unknown?!?"); break;
125 char *visbuf(const char *buf)
126 /* visibilize a given string */
128 static char vbuf[BUFSIZ];
135 *tp++ = '\\'; *tp++ = '"';
138 else if (isprint(*buf) || *buf == ' ')
140 else if (*buf == '\n')
142 *tp++ = '\\'; *tp++ = 'n';
145 else if (*buf == '\r')
147 *tp++ = '\\'; *tp++ = 'r';
150 else if (*buf == '\b')
152 *tp++ = '\\'; *tp++ = 'b';
157 *tp++ = '\\'; *tp++ = '^'; *tp++ = '@' + *buf;
162 (void) sprintf(tp, "\\0x%02x", *buf++);
170 /* env.c ends here */