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 /* we'll need this for the SMTP forwarding target and error messages */
59 if (gethostname(tmpbuf, sizeof(tmpbuf)))
61 fprintf(stderr, "%s: can't determine your host!", program_name);
64 #ifdef HAVE_GETHOSTBYNAME
68 /* in case we got a basename (as we do in Linux) make a FQDN of it */
69 hp = gethostbyname(tmpbuf);
70 if (hp == (struct hostent *) NULL)
72 /* exit with error message */
73 fprintf(stderr, "gethostbyname failed for %s", tmpbuf);
76 strcpy(tmpbuf, hp->h_name);
78 #endif /* HAVE_GETHOSTBYNAME */
79 fetchmailhost = xstrdup(tmpbuf);
81 #define RCFILE_NAME ".fetchmailrc"
82 rcfile = (char *) xmalloc(strlen(home)+strlen(RCFILE_NAME)+2);
85 strcat(rcfile, RCFILE_NAME);
88 char *showproto(int proto)
89 /* protocol index to protocol name mapping */
93 case P_AUTO: return("auto"); break;
95 case P_POP2: return("POP2"); break;
96 #endif /* POP2_ENABLE */
97 case P_POP3: return("POP3"); break;
98 case P_IMAP: return("IMAP"); break;
99 case P_IMAP_K4: return("IMAP-K4"); break;
100 case P_APOP: return("APOP"); break;
101 case P_RPOP: return("RPOP"); break;
102 case P_ETRN: return("ETRN"); break;
103 default: return("unknown?!?"); break;
107 char *visbuf(const char *buf)
108 /* visibilize a given string */
110 static char vbuf[BUFSIZ];
115 if (isprint(*buf) || *buf == ' ')
117 else if (*buf == '\n')
119 *tp++ = '\\'; *tp++ = 'n';
122 else if (*buf == '\r')
124 *tp++ = '\\'; *tp++ = 'r';
127 else if (*buf == '\b')
129 *tp++ = '\\'; *tp++ = 'b';
134 *tp++ = '\\'; *tp++ = '^'; *tp++ = '@' + *buf;
139 (void) sprintf(tp, "\\0x%02x", *buf++);
147 /* env.c ends here */