- char *tname, *ttyname();
- char termname[MAXPATHLEN+1];
-
- if (ch == 'T') {
- if ((tname = ttyname(0)) == NULL)
- error("<stdin>: not a terminal");
- } else
- tname = optarg;
- if (strlen(tname) == 2) {
- if (strcmp(tname, "co") == 0)
- strcpy(termname, "/dev/console");
- else {
- strcpy(termname, "/dev/tty");
- strcat(termname, tname);
- }
- } else if (*tname != '/') {
- strcpy(termname, "/dev/");
- strcat(termname, tname);
- } else
- strcpy(termname, tname);
- if (stat(termname, &stbuf) == -1)
- syserror(termname);
- if ((stbuf.st_mode&S_IFMT) != S_IFCHR)
- error("%s: not a terminal", termname);
+ char pathbuf[MAXPATHLEN];
+
+ if (strcmp(optarg, "co") == 0)
+ ttypath = _PATH_CONSOLE;
+ else if (*optarg != '/')
+ (void) sprintf(ttypath = pathbuf, "%s%s",
+ _PATH_TTY, optarg);
+ else
+ ttypath = optarg;
+ if (stat(ttypath, &stbuf) == -1)
+ syserror(ttypath);
+ if ((stbuf.st_mode & S_IFMT) != S_IFCHR)
+ error("%s: not a terminal", ttypath);