home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1989, 1990, John F. Haugh II
- * All rights reserved.
- *
- * Use, duplication, and disclosure prohibited without
- * the express written permission of the author.
- */
-
- #include <stdio.h>
- #include <ctype.h>
- #ifndef BSD
- #include <string.h>
- #include <memory.h>
- #else
- #include <strings.h>
- #define strchr index
- #define strrchr rindex
- #endif
-
- #ifndef lint
- static char sccsid[] = "@(#)login.c 2.3 19:23:55 7/29/90";
- #endif
-
- void setenv ();
-
- void login (name)
- char *name;
- {
- char buf[BUFSIZ];
- char *envp[32];
- int envc;
- char *cp;
- int i;
-
- #ifndef BSD
- (void) memset (buf, '\0', sizeof buf);
- #else
- bzero (buf, sizeof buf);
- #endif
- fputs ("login: ", stdout);
-
- if (fgets (buf, BUFSIZ, stdin) != buf)
- exit (1);
-
- buf[strlen (buf) - 1] = '\0'; /* remove \n [ must be there ] */
-
- for (cp = buf;*cp == ' ' || *cp == '\t';cp++)
- ;
-
- for (i = 0;i < BUFSIZ - 1 && isgraph (*cp);name[i++] = *cp++)
- ;
-
- if (*cp)
- cp++;
-
- name[i] = '\0';
-
- if (*cp != '\0') { /* process new variables */
- for (envc = 0;envc < 32;envc++) {
- envp[envc] = strtok (envc == 0 ? cp:(char *) 0, " \t,");
-
- if (envp[envc] == (char *) 0)
- break;
- }
- setenv (envc, envp);
- }
- }
-