|
|
1.1 ! root 1: /* /sccs/src/cmd/uucp/s.uucpname.c ! 2: uucpname.c 1.1 8/30/84 17:38:03 ! 3: */ ! 4: #include "uucp.h" ! 5: VERSION(@(#)uucpname.c 1.1); ! 6: ! 7: /* ! 8: * get the uucp name ! 9: * return: ! 10: * none ! 11: */ ! 12: void ! 13: uucpname(name) ! 14: register char *name; ! 15: { ! 16: char *s; ! 17: ! 18: #ifdef BSD4_2 ! 19: int nlen; ! 20: char NameBuf[MAXBASENAME + 1]; ! 21: ! 22: /* This code is slightly wrong, at least if you believe what the */ ! 23: /* 4.1c manual says. It claims that gethostname's second parameter */ ! 24: /* should be a pointer to an int that has the size of the buffer. */ ! 25: /* The code in the kernel says otherwise. The manual also says that */ ! 26: /* the string returned is null-terminated; this, too, appears to be */ ! 27: /* contrary to fact. Finally, the variable containing the length */ ! 28: /* is supposed to be modified to have the actual length passed back; */ ! 29: /* this, too, doesn't happen. So I'm zeroing the buffer first, and */ ! 30: /* passing an int, not a pointer to one. *sigh* ! 31: ! 32: /* --Steve Bellovin */ ! 33: bzero(NameBuf, sizeof NameBuf); ! 34: nlen = sizeof NameBuf; ! 35: gethostname(NameBuf, nlen); ! 36: s = NameBuf; ! 37: s[nlen] = '\0'; ! 38: #else ! 39: #ifdef UNAME ! 40: struct utsname utsn; ! 41: ! 42: uname(&utsn); ! 43: s = utsn.nodename; ! 44: #else ! 45: char NameBuf[MAXBASENAME + 1], *strchr(); ! 46: FILE *NameFile; ! 47: ! 48: s = MYNAME; ! 49: NameBuf[0] = '\0'; ! 50: ! 51: if ((NameFile = fopen("/etc/whoami", "r")) != NULL) { ! 52: /* etc/whoami wins */ ! 53: (void) fgets(NameBuf, MAXBASENAME + 1, NameFile); ! 54: (void) fclose(NameFile); ! 55: NameBuf[MAXBASENAME] = '\0'; ! 56: if (NameBuf[0] != '\0') { ! 57: if ((s = strchr(NameBuf, '\n')) != NULL) ! 58: *s = '\0'; ! 59: s = NameBuf; ! 60: } ! 61: } ! 62: #endif ! 63: #endif ! 64: ! 65: (void) strncpy(name, s, MAXBASENAME); ! 66: name[MAXBASENAME] = '\0'; ! 67: return; ! 68: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.