]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - lib/ZGetWGPort.c
zephyr (2.1.20000421.SNAPSHOT-8) unstable; urgency=low
[1ts-debian.git] / 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: ZGetWGPort.c,v 1.11 1999/01/22 23:19:12 ghudson Exp $
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: ZGetWGPort.c,v 1.11 1999/01/22 23:19:12 ghudson Exp $";
15 #endif
16
17 #include <internal.h>
18
19 int ZGetWGPort()
20 {
21     char *envptr, name[128];
22     FILE *fp;
23     int wgport;
24         
25     envptr = getenv("WGFILE");
26     if (!envptr) {
27         (void) sprintf(name, "/tmp/wg.%d", getuid());
28         envptr = name;
29     } 
30     if (!(fp = fopen(envptr, "r")))
31         return (-1);
32
33     /* if fscanf fails, return -1 via wgport */
34     if (fscanf(fp, "%d", &wgport) != 1)
35             wgport = -1;
36
37     (void) fclose(fp);
38
39     return (wgport);
40 }