home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- FRIENDS 1.0
-
- friends - which of your friends are on-line?
-
- Written by: Grant Boggs (boggs@a.cs.okstate.edu)
- Date : 12/3/92
-
- Permission granted to freely copy and distribute.
- ******************************************************************************/
-
- #include <stdio.h>
- #include <sys/types.h>
- #include <fcntl.h>
- #include <utmp.h>
-
- main()
- {
- struct utmp *u; /* Utmp file pointer */
- char friend[50][9]; /* Array of .friends names */
- char friend_file[80]; /* File name */
- int x = 0;
- FILE *f;
-
- sprintf(friend_file, "%s/.friends",
- getenv("HOME")); /* Get full file name for .friends*/
-
- f = fopen(friend_file, "r"); /* Open .friends file for reading */
-
- if(f == NULL)
- {
- printf("No .friends file?! What's the matter, don't you have any");
- printf(" friends?\n");
- exit(-1);
- }
-
- x = 0;
-
- while(!feof(f)) /* Read in list of friends */
- fscanf(f, "%s", friend[x++]);
-
- x--; /* Magic */
-
- u = getutent(); /* Get first utmp entry */
-
- while(u != NULL) /* While not end of utmp file */
- {
- int y;
-
- /* Compare each utmp entry against all in friend array */
-
- for(y = 0; y < x; y++)
- if(u->ut_type == USER_PROCESS && !strcmp(friend[y], u->ut_user))
- {
- #ifdef _SEQUENT_
- printf("%-8s %s %s\n", u->ut_user, u->ut_line,
- ut_find_host(u->ut_line));
- #else
- printf("%-8s %s\n", u->ut_user, u->ut_line);
- #endif
- }
-
- u = getutent(); /* Get next utmp file */
- }
- }
-