]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/lib/ZGetWGPort.c
r4254@bucket (orig r244): kcr | 2008-01-20 14:40:42 -0500
[1ts-debian.git] / zephyr / lib / ZGetWGPort.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It contains source for the ZGetWGPort function.
3  *
4  *      Created by:     Robert French
5  *
6  *      $Id$
7  *
8  *      Copyright (c) 1987 by the Massachusetts Institute of Technology.
9  *      For copying and distribution information, see the file
10  *      "mit-copyright.h". 
11  */
12
13 #ifndef lint
14 static char rcsid_ZGetWGPort_c[] = "$Id$";
15 #endif
16
17 #include <internal.h>
18
19 int
20 ZGetWGPort(void)
21 {
22     char *envptr, name[128];
23     FILE *fp;
24     int wgport;
25         
26     envptr = getenv("WGFILE");
27     if (!envptr) {
28         (void) sprintf(name, "/tmp/wg.%d", getuid());
29         envptr = name;
30     } 
31     if (!(fp = fopen(envptr, "r")))
32         return (-1);
33
34     /* if fscanf fails, return -1 via wgport */
35     if (fscanf(fp, "%d", &wgport) != 1)
36             wgport = -1;
37
38     (void) fclose(fp);
39
40     return (wgport);
41 }