|
|
1.1 root 1: /* taylor.c: This file opens the sys file and looks for the specific system
2: * name supplied by the user. A 1 is returned for success and 0
3: * for failure. Id the sys file is empty, the program will exit.
4: */
5:
6: #include <stdio.h>
7: #include <fcntl.h>
8:
9: #define SYSFILE "/usr/lib/uucp/sys"
10:
11: check_sys_file(sysname)
12: char * sysname; /* system name to look for */
13: {
14: int x = 0;
15: FILE * configfile;
16:
17: if ( (configfile = fopen(SYSFILE,"r")) == NULL){
18: printf("Error opening %s.\n",SYSFILE);
19: exit(1);
20: }
21:
22:
23: /* file exists, but is empty */
24: x = read_entries(configfile, sysname);
25:
26: if(x == -1){
27: fclose(configfile);
28: printf("File /usr/lib/uucp/sys is empty.\n");
29: exit(1);
30: }
31:
32: fclose(configfile);
33: return(x);
34:
35: }
36:
37:
38: /* read the information from the specified file. We want to keep track of the
39: * port, system or dialer name we have read, the line we began reading it
40: * on and the total number of entries read;
41: */
42:
43:
44: read_entries(configfile, sysname)
45: FILE * configfile; /* pointer to our configuration file */
46: char * sysname; /* name of system we are looking for */
47: {
48:
49: int x = 0; /* counter of lines read */
50:
51: char buffer[256];
52: char lookfor[8];
53:
54: strcpy(lookfor,"system");
55:
56: while(fgets(buffer,sizeof(buffer) -1, configfile) != NULL){
57: x++;
58:
59: /* skip commented lines */
60:
61: if(buffer[0] == '#')
62: continue;
63:
64: /* found first line of a configuration entry, copy name and
65: * the line number we found it on.
66: */
67:
68: if(strstr(buffer,lookfor) && strstr(buffer, sysname))
69: return(1);
70: }
71:
72: if(x == 0)
73: return(-1);
74:
75: return(0);
76: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.