2 * env.c -- small service routines
4 * For license terms, see the file COPYING in this directory.
11 #if defined(STDC_HEADERS)
14 #if defined(HAVE_UNISTD_H)
20 #ifdef HAVE_GETHOSTBYNAME
22 #endif /* HAVE_GETHOSTBYNAME */
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) */
34 if ((program_name = strrchr(argv[0], '/')) != NULL)
37 program_name = argv[0];
39 if ((user = getenv("USER")) == (char *)NULL)
40 user = getenv("LOGNAME");
42 if ((user == (char *)NULL) || (home = getenv("HOME")) == (char *)NULL)
44 if ((pw = getpwuid(getuid())) != NULL)
52 "%s: can't find your name and home directory!\n",
58 #define RCFILE_NAME ".fetchmailrc"
59 rcfile = (char *) xmalloc(strlen(home)+strlen(RCFILE_NAME)+2);
60 /* avoid //.fetchmailrc */
61 if (strcmp(home, "/") != 0) {
67 strcat(rcfile, RCFILE_NAME);
71 /* get the FQDN of the machine we're running */
73 char tmpbuf[HOSTLEN+1];
75 if (gethostname(tmpbuf, sizeof(tmpbuf)))
77 fprintf(stderr, "%s: can't determine your host!",
81 #ifdef HAVE_GETHOSTBYNAME
82 /* if we got a . in the hostname assume it is a FQDN */
83 if (strchr(tmpbuf, '.') == NULL)
87 /* if we got a basename (as we do in Linux) make a FQDN of it */
88 hp = gethostbyname(tmpbuf);
89 if (hp == (struct hostent *) NULL)
91 /* exit with error message */
93 "gethostbyname failed for %s\n", tmpbuf);
96 return(xstrdup(hp->h_name));
99 #endif /* HAVE_GETHOSTBYNAME */
100 return(xstrdup(tmpbuf));
104 char *showproto(int proto)
105 /* protocol index to protocol name mapping */
109 case P_AUTO: return("auto"); break;
111 case P_POP2: return("POP2"); break;
112 #endif /* POP2_ENABLE */
113 case P_POP3: return("POP3"); break;
114 case P_IMAP: return("IMAP"); break;
115 case P_IMAP_K4: return("IMAP-K4"); break;
117 case P_IMAP_GSS: return("IMAP-GSS"); break;
119 case P_APOP: return("APOP"); break;
120 case P_RPOP: return("RPOP"); break;
121 case P_ETRN: return("ETRN"); break;
122 default: return("unknown?!?"); break;
126 char *visbuf(const char *buf)
127 /* visibilize a given string */
129 static char vbuf[BUFSIZ];
136 *tp++ = '\\'; *tp++ = '"';
139 else if (isprint(*buf) || *buf == ' ')
141 else if (*buf == '\n')
143 *tp++ = '\\'; *tp++ = 'n';
146 else if (*buf == '\r')
148 *tp++ = '\\'; *tp++ = 'r';
151 else if (*buf == '\b')
153 *tp++ = '\\'; *tp++ = 'b';
158 *tp++ = '\\'; *tp++ = '^'; *tp++ = '@' + *buf;
163 (void) sprintf(tp, "\\0x%02x", *buf++);
171 /* env.c ends here */