1*12530Sdlw /* 2*12530Sdlw * configttys - configure "tty" ports 3*12530Sdlw * 4*12530Sdlw * David L. Wasley 5*12530Sdlw * U.C.Berkeley 6*12530Sdlw */ 7*12530Sdlw 8*12530Sdlw #ifndef lint 9*12530Sdlw char sccsid[] = "@(#)configttys.c 4.1 Berkeley 05/18/83"; 10*12530Sdlw #endif 11*12530Sdlw 12*12530Sdlw #include <stdio.h> 13*12530Sdlw #include <getty.h> 14*12530Sdlw #include <signal.h> 15*12530Sdlw 16*12530Sdlw #define exists(file) (access(file, 0) == 0) 17*12530Sdlw 18*12530Sdlw char *etc_ttys = "/etc/ttys"; /* active port speed table */ 19*12530Sdlw char *etc_ttytype = "/etc/ttytype"; /* terminal type table */ 20*12530Sdlw char *etc_conf = "/etc/ttyconf"; /* master config file */ 21*12530Sdlw char *lockfile = "/etc/ttyconf.lock"; /* interlock file */ 22*12530Sdlw 23*12530Sdlw struct ttys { 24*12530Sdlw char ty_active; /* active login port */ 25*12530Sdlw char ty_speed; /* speed table character */ 26*12530Sdlw char ty_port[32]; /* port name */ 27*12530Sdlw } ttys[256]; 28*12530Sdlw 29*12530Sdlw struct ttytype { 30*12530Sdlw char tp_term[64]; /* terminal type name */ 31*12530Sdlw char tp_port[32]; /* port name */ 32*12530Sdlw } ttytype[256]; 33*12530Sdlw 34*12530Sdlw char conformat[] = "%s\t%s\t%s\t%s\n"; 35*12530Sdlw 36*12530Sdlw int error = 0; 37*12530Sdlw int renamed = 0; 38*12530Sdlw int debug = 0; /* debug mode */ 39*12530Sdlw int backup = 0; /* create backup copies of old data */ 40*12530Sdlw int interactive = 1; /* interactive mode */ 41*12530Sdlw 42*12530Sdlw char *speedname(); /* port speed code name */ 43*12530Sdlw char speedchar(); /* getty table name */ 44*12530Sdlw char *termname(); /* name of terminal on this port */ 45*12530Sdlw char *rindex(); 46*12530Sdlw struct ttytype *type(); /* find ttytype for port */ 47*12530Sdlw FILE *fopen(); 48*12530Sdlw 49*12530Sdlw main (argc, argv) 50*12530Sdlw int argc; 51*12530Sdlw char **argv; 52*12530Sdlw { 53*12530Sdlw int lineno; 54*12530Sdlw int child; 55*12530Sdlw int status; 56*12530Sdlw char c; 57*12530Sdlw struct ttys *ty; 58*12530Sdlw struct ttytype *tp; 59*12530Sdlw char port[32]; 60*12530Sdlw char active[16]; 61*12530Sdlw char speed[32]; 62*12530Sdlw char term[64]; 63*12530Sdlw FILE *tyf, *tpf, *conf; 64*12530Sdlw char buf[1024]; 65*12530Sdlw char ans[32]; 66*12530Sdlw 67*12530Sdlw while (--argc > 0) 68*12530Sdlw { 69*12530Sdlw if (**++argv == '-') switch (*++*argv) 70*12530Sdlw { 71*12530Sdlw case 'd': 72*12530Sdlw debug = 1; 73*12530Sdlw break; 74*12530Sdlw 75*12530Sdlw case 'n': /* non-interactive */ 76*12530Sdlw interactive = 0; 77*12530Sdlw break; 78*12530Sdlw 79*12530Sdlw case 'b': /* backup old databases */ 80*12530Sdlw backup = 1; 81*12530Sdlw break; 82*12530Sdlw 83*12530Sdlw default: 84*12530Sdlw fprintf(stderr, "unknown option %c\n", **argv); 85*12530Sdlw exit(1); 86*12530Sdlw } 87*12530Sdlw } 88*12530Sdlw 89*12530Sdlw if (debug) 90*12530Sdlw { 91*12530Sdlw etc_ttys = rindex(etc_ttys, '/') + 1; 92*12530Sdlw etc_ttytype = rindex(etc_ttytype, '/') + 1; 93*12530Sdlw etc_conf = rindex(etc_conf, '/') + 1; 94*12530Sdlw lockfile = rindex(lockfile, '/') + 1; 95*12530Sdlw } 96*12530Sdlw 97*12530Sdlw /* 98*12530Sdlw * create backup copies of the databases? 99*12530Sdlw */ 100*12530Sdlw if (backup) 101*12530Sdlw { 102*12530Sdlw if (exists(etc_ttys)) 103*12530Sdlw { 104*12530Sdlw sprintf(buf, "/bin/cp %s %s.bak", etc_ttys, etc_ttys); 105*12530Sdlw system(buf); 106*12530Sdlw } 107*12530Sdlw if (exists(etc_ttys)) 108*12530Sdlw { 109*12530Sdlw sprintf(buf, "/bin/cp %s %s.bak", etc_ttytype, etc_ttytype); 110*12530Sdlw system(buf); 111*12530Sdlw } 112*12530Sdlw if (exists(etc_conf)) 113*12530Sdlw { 114*12530Sdlw sprintf(buf, "/bin/cp %s %s.bak", etc_conf, etc_conf); 115*12530Sdlw system(buf); 116*12530Sdlw } 117*12530Sdlw } 118*12530Sdlw 119*12530Sdlw /* 120*12530Sdlw * create interlock file 121*12530Sdlw */ 122*12530Sdlw getlockfile(lockfile); 123*12530Sdlw 124*12530Sdlw /* 125*12530Sdlw * always read ttys file for comparison 126*12530Sdlw * It is afterall what really counts! 127*12530Sdlw */ 128*12530Sdlw if (readttys() != 0) 129*12530Sdlw quit(1); 130*12530Sdlw 131*12530Sdlw /* 132*12530Sdlw * read old ttytypes if necessary 133*12530Sdlw */ 134*12530Sdlw if (! exists(etc_conf)) 135*12530Sdlw { 136*12530Sdlw /* 137*12530Sdlw * open old ttytype file 138*12530Sdlw */ 139*12530Sdlw if ((tpf = fopen(etc_ttytype, "r")) == NULL) 140*12530Sdlw { 141*12530Sdlw perror(etc_ttytype); 142*12530Sdlw quit(1); 143*12530Sdlw } 144*12530Sdlw 145*12530Sdlw /* 146*12530Sdlw * read ttytype file 147*12530Sdlw */ 148*12530Sdlw lineno = 0; 149*12530Sdlw tp = ttytype; 150*12530Sdlw while (fgets(buf, sizeof buf, tpf)) 151*12530Sdlw { 152*12530Sdlw lineno++; 153*12530Sdlw if (sscanf(buf, "%s %s", tp->tp_term, tp->tp_port) == 2) 154*12530Sdlw tp++; 155*12530Sdlw else 156*12530Sdlw { 157*12530Sdlw error++; 158*12530Sdlw fprintf(stderr, "bad line %d in %s: %s", 159*12530Sdlw lineno, etc_ttytype, buf); 160*12530Sdlw } 161*12530Sdlw } 162*12530Sdlw fclose(tpf); 163*12530Sdlw tp->tp_term[0] = '\0'; 164*12530Sdlw 165*12530Sdlw if (error > 0) 166*12530Sdlw quit(1); 167*12530Sdlw 168*12530Sdlw /* 169*12530Sdlw * create master config file 170*12530Sdlw */ 171*12530Sdlw if ((conf = fopen(etc_conf, "w")) == NULL) 172*12530Sdlw { 173*12530Sdlw perror(etc_conf); 174*12530Sdlw quit(1); 175*12530Sdlw } 176*12530Sdlw 177*12530Sdlw fprintf(conf, conformat, "port", "active", "speed\t", "terminal name"); 178*12530Sdlw fprintf(conf, conformat, "----", "------", "-----\t", "-------------"); 179*12530Sdlw for (ty = ttys; ty->ty_active; ty++) 180*12530Sdlw { 181*12530Sdlw fprintf(conf, conformat, ty->ty_port, 182*12530Sdlw ty->ty_active == '1'? "active":"-", 183*12530Sdlw speedname(ty->ty_speed), 184*12530Sdlw termname(ty->ty_port)); 185*12530Sdlw } 186*12530Sdlw fclose(conf); 187*12530Sdlw } 188*12530Sdlw 189*12530Sdlw /* 190*12530Sdlw * open master config file 191*12530Sdlw */ 192*12530Sdlw if ((conf = fopen(etc_conf, "r")) == NULL) 193*12530Sdlw { 194*12530Sdlw perror(etc_conf); 195*12530Sdlw quit(1); 196*12530Sdlw } 197*12530Sdlw 198*12530Sdlw if (interactive) 199*12530Sdlw edit(); 200*12530Sdlw 201*12530Sdlw /* 202*12530Sdlw * read conf file 203*12530Sdlw */ 204*12530Sdlw re_read: 205*12530Sdlw rewind(conf); 206*12530Sdlw ty = ttys; 207*12530Sdlw renamed = 0; 208*12530Sdlw error = 0; 209*12530Sdlw lineno = 0; 210*12530Sdlw 211*12530Sdlw while (fgets(buf, sizeof buf, conf)) /* skip heading */ 212*12530Sdlw { 213*12530Sdlw lineno++; 214*12530Sdlw if (buf[0] == '-') 215*12530Sdlw break; 216*12530Sdlw } 217*12530Sdlw 218*12530Sdlw while (fgets(buf, sizeof buf, conf)) 219*12530Sdlw { 220*12530Sdlw lineno++; 221*12530Sdlw if (sscanf(buf, "%s %s %s %s", port, active, speed, term) < 4) 222*12530Sdlw { 223*12530Sdlw fprintf(stderr, "line %d: field(s) missing: %s", 224*12530Sdlw lineno, buf); 225*12530Sdlw error++; 226*12530Sdlw break; 227*12530Sdlw } 228*12530Sdlw 229*12530Sdlw if (strcmp(port, ty->ty_port) != 0) 230*12530Sdlw { 231*12530Sdlw if (! ty->ty_active || renamed) 232*12530Sdlw strcpy(ty->ty_port, port); 233*12530Sdlw else 234*12530Sdlw { 235*12530Sdlw fprintf(stderr, "line %d: port name changed! %s -> %s\n", 236*12530Sdlw lineno, ty->ty_port, port); 237*12530Sdlw fprintf(stderr, "Are you sure this is OK? "); 238*12530Sdlw gets(ans); 239*12530Sdlw if (ans[0] != 'y') 240*12530Sdlw { 241*12530Sdlw edit(); 242*12530Sdlw goto re_read; 243*12530Sdlw } 244*12530Sdlw renamed++; 245*12530Sdlw strcpy(ty->ty_port, port); 246*12530Sdlw } 247*12530Sdlw } 248*12530Sdlw 249*12530Sdlw if (strcmp(active, "active") == 0) 250*12530Sdlw ty->ty_active = '1'; 251*12530Sdlw else 252*12530Sdlw ty->ty_active = '0'; 253*12530Sdlw 254*12530Sdlw if (c = speedchar(speed)) 255*12530Sdlw ty->ty_speed = c; 256*12530Sdlw else 257*12530Sdlw { 258*12530Sdlw fprintf(stderr, "line %d: speed name not known: %s\n", 259*12530Sdlw lineno, speed); 260*12530Sdlw error++; 261*12530Sdlw } 262*12530Sdlw 263*12530Sdlw if (tp = type(port)) 264*12530Sdlw strcpy(tp->tp_term, term); 265*12530Sdlw /* else ?? */ 266*12530Sdlw 267*12530Sdlw ty++; 268*12530Sdlw } 269*12530Sdlw 270*12530Sdlw if (ty == ttys) 271*12530Sdlw { 272*12530Sdlw fprintf(stderr, "%s empty??\n", etc_conf); 273*12530Sdlw error++; 274*12530Sdlw } 275*12530Sdlw 276*12530Sdlw if (error) 277*12530Sdlw { 278*12530Sdlw if (interactive) 279*12530Sdlw { 280*12530Sdlw fprintf(stderr, "re-edit? "); 281*12530Sdlw gets(ans); 282*12530Sdlw if (ans[0] == 'y') 283*12530Sdlw { 284*12530Sdlw edit(); 285*12530Sdlw goto re_read; 286*12530Sdlw } 287*12530Sdlw } 288*12530Sdlw fprintf(stderr, "Files not modified.\n"); 289*12530Sdlw quit(1); 290*12530Sdlw } 291*12530Sdlw 292*12530Sdlw writettys(); 293*12530Sdlw quit(0); 294*12530Sdlw } 295*12530Sdlw 296*12530Sdlw readttys() 297*12530Sdlw { 298*12530Sdlw /* 299*12530Sdlw * read ttys file 300*12530Sdlw */ 301*12530Sdlw FILE *tyf; 302*12530Sdlw register struct ttys *ty; 303*12530Sdlw char buf[1024]; 304*12530Sdlw int lineno; 305*12530Sdlw int error = 0; 306*12530Sdlw 307*12530Sdlw if ((tyf = fopen(etc_ttys, "r")) == NULL) 308*12530Sdlw { 309*12530Sdlw perror(etc_ttys); 310*12530Sdlw quit(1); 311*12530Sdlw } 312*12530Sdlw 313*12530Sdlw lineno = 0; 314*12530Sdlw ty = ttys; 315*12530Sdlw while (fgets(buf, sizeof buf, tyf)) 316*12530Sdlw { 317*12530Sdlw lineno++; 318*12530Sdlw if (sscanf(buf, "%c%c%s", 319*12530Sdlw &ty->ty_active, &ty->ty_speed, ty->ty_port) == 3) 320*12530Sdlw ty++; 321*12530Sdlw else 322*12530Sdlw { 323*12530Sdlw error++; 324*12530Sdlw fprintf(stderr, "bad line %d in %s: %s", 325*12530Sdlw lineno, etc_ttys, buf); 326*12530Sdlw } 327*12530Sdlw } 328*12530Sdlw fclose(tyf); 329*12530Sdlw ty->ty_active = '\0'; 330*12530Sdlw return(error); 331*12530Sdlw } 332*12530Sdlw 333*12530Sdlw writettys() 334*12530Sdlw { 335*12530Sdlw int rtn = 0; 336*12530Sdlw char temp[1024]; 337*12530Sdlw FILE *tyf, *tpf; 338*12530Sdlw register struct ttys *ty; 339*12530Sdlw 340*12530Sdlw sprintf(temp, "%s.tmp", etc_ttys); 341*12530Sdlw if ((tyf = fopen(temp, "w")) == NULL) 342*12530Sdlw { 343*12530Sdlw perror(temp); 344*12530Sdlw quit(1); 345*12530Sdlw } 346*12530Sdlw 347*12530Sdlw for (ty = ttys; ty->ty_active; ty++) 348*12530Sdlw fprintf(tyf, "%c%c%s\n", 349*12530Sdlw ty->ty_active, ty->ty_speed, ty->ty_port); 350*12530Sdlw fclose(tyf); 351*12530Sdlw 352*12530Sdlw if (rename(temp, etc_ttys) != 0) 353*12530Sdlw { 354*12530Sdlw fprintf(stderr, "Can't rename %s\n", temp); 355*12530Sdlw rtn = 1; 356*12530Sdlw } 357*12530Sdlw 358*12530Sdlw sprintf(temp, "%s.tmp", etc_ttytype); 359*12530Sdlw if ((tpf = fopen(temp, "w")) == NULL) 360*12530Sdlw { 361*12530Sdlw perror(temp); 362*12530Sdlw quit(1); 363*12530Sdlw } 364*12530Sdlw 365*12530Sdlw for (ty = ttys; ty->ty_active; ty++) /* same ports! */ 366*12530Sdlw fprintf(tpf, "%s %s\n", 367*12530Sdlw type(ty->ty_port)->tp_term, ty->ty_port); 368*12530Sdlw fclose(tpf); 369*12530Sdlw 370*12530Sdlw if (rename(temp, etc_ttytype) != 0) 371*12530Sdlw { 372*12530Sdlw fprintf(stderr, "Can't rename %s\n", temp); 373*12530Sdlw rtn = 1; 374*12530Sdlw } 375*12530Sdlw 376*12530Sdlw return (rtn); 377*12530Sdlw } 378*12530Sdlw 379*12530Sdlw 380*12530Sdlw edit() 381*12530Sdlw { 382*12530Sdlw /* 383*12530Sdlw * invoke editor 384*12530Sdlw */ 385*12530Sdlw int child; 386*12530Sdlw int status; 387*12530Sdlw 388*12530Sdlw if ((child = fork()) == 0) 389*12530Sdlw { 390*12530Sdlw execl("/usr/ucb/vi", "vi", etc_conf, 0); 391*12530Sdlw execl("/bin/ed", "ed", etc_conf, 0); 392*12530Sdlw exit(1); 393*12530Sdlw } 394*12530Sdlw 395*12530Sdlw if (child < 0) 396*12530Sdlw { 397*12530Sdlw perror("can't fork editor"); 398*12530Sdlw quit(1); 399*12530Sdlw } 400*12530Sdlw 401*12530Sdlw /* 402*12530Sdlw * wait for editor 403*12530Sdlw */ 404*12530Sdlw while (wait(&status) >= 0) 405*12530Sdlw ; 406*12530Sdlw 407*12530Sdlw return (status); 408*12530Sdlw } 409*12530Sdlw 410*12530Sdlw 411*12530Sdlw quit (n) 412*12530Sdlw int n; 413*12530Sdlw { 414*12530Sdlw unlink (lockfile); 415*12530Sdlw if (n > 1) 416*12530Sdlw { 417*12530Sdlw signal (n, SIG_DFL); 418*12530Sdlw kill (getpid(), n); 419*12530Sdlw } 420*12530Sdlw exit (n); 421*12530Sdlw } 422*12530Sdlw 423*12530Sdlw getlockfile () 424*12530Sdlw { 425*12530Sdlw char *p; 426*12530Sdlw char locktmp[64]; 427*12530Sdlw int fd; 428*12530Sdlw 429*12530Sdlw strcpy(locktmp, lockfile); 430*12530Sdlw if (p = rindex(locktmp, '/')) 431*12530Sdlw p++; 432*12530Sdlw else 433*12530Sdlw p = locktmp; 434*12530Sdlw strcpy(p, "confttysXXXXXX"); 435*12530Sdlw mktemp(locktmp); 436*12530Sdlw 437*12530Sdlw if ((fd = creat(locktmp, 0600)) < 0) 438*12530Sdlw { 439*12530Sdlw perror(locktmp); 440*12530Sdlw exit(1); 441*12530Sdlw } 442*12530Sdlw 443*12530Sdlw if (link(locktmp, lockfile) < 0) 444*12530Sdlw { 445*12530Sdlw perror(lockfile); 446*12530Sdlw unlink(locktmp); 447*12530Sdlw exit(1); 448*12530Sdlw } 449*12530Sdlw 450*12530Sdlw signal(SIGINT, quit); 451*12530Sdlw signal(SIGQUIT, quit); 452*12530Sdlw 453*12530Sdlw unlink(locktmp); 454*12530Sdlw return(0); 455*12530Sdlw } 456*12530Sdlw 457*12530Sdlw struct speeds { 458*12530Sdlw char *sp_name; /* human readable name */ 459*12530Sdlw char sp_table; /* getty table name */ 460*12530Sdlw } speeds[] = { 461*12530Sdlw { "dialup", GT_DIALUP }, /* normal dialup rotation */ 462*12530Sdlw { "selector", GT_SELECTOR }, /* port selector pseudo-table autobaud*/ 463*12530Sdlw { "b110", GT_B110 }, /* 110 baud */ 464*12530Sdlw { "b134", GT_B134 }, /* 134.5 baud selectric */ 465*12530Sdlw { "b150", GT_B150 }, /* 150 baud */ 466*12530Sdlw { "b300", GT_B300 }, /* 300 baud */ 467*12530Sdlw { "b600", GT_B600 }, /* 600 baud */ 468*12530Sdlw { "b1200", GT_B1200 }, /* 1200 baud */ 469*12530Sdlw { "b2400", GT_B2400 }, /* 2400 baud */ 470*12530Sdlw { "b4800", GT_B4800 }, /* 4800 baud */ 471*12530Sdlw { "b9600", GT_B9600 }, /* 9600 baud */ 472*12530Sdlw { "dw2console", GT_DW2CONSOLE },/* Decwriter Console - 300 baud */ 473*12530Sdlw { "fastdialup", GT_FASTDIALUP },/* 1200-300 baud rotation for dialup */ 474*12530Sdlw { "fastdialup1",GT_FASTDIALUP1},/* 300-1200 " " " " */ 475*12530Sdlw { "crt_hcpy", GT_CRT_HCPY }, /* 9600-300 CRT + hardcopy rotation */ 476*12530Sdlw { "hcpy_crt", GT_HCPY_CRT }, /* 300-9600 " " " */ 477*12530Sdlw { "plugboard", GT_PLUGBOARD }, /* 9600-300-1200 rotation */ 478*12530Sdlw { "plugboard1", GT_PLUGBOARD2 },/* 300-1200-9600 rotation */ 479*12530Sdlw { "plugboard2", GT_PLUGBOARD2 },/* 1200-9600-300 rotation */ 480*12530Sdlw { "interdata", GT_INTERDATA }, /* Interdata Console */ 481*12530Sdlw { "chess", GT_CHESS }, /* LSI Chess Terminal */ 482*12530Sdlw { "tty33", GT_TTY33 }, /* 110 baud Model 33 TTY */ 483*12530Sdlw { "network", GT_NETWORK }, /* ethernet port */ 484*12530Sdlw { "", 0 } 485*12530Sdlw }; 486*12530Sdlw 487*12530Sdlw char * 488*12530Sdlw speedname (c) 489*12530Sdlw char c; 490*12530Sdlw { 491*12530Sdlw struct speeds *sp; 492*12530Sdlw static char sbuf[32]; 493*12530Sdlw 494*12530Sdlw for (sp = speeds; sp->sp_table; sp++) 495*12530Sdlw if (sp->sp_table == c) 496*12530Sdlw break; 497*12530Sdlw 498*12530Sdlw if (sp->sp_table) 499*12530Sdlw strcpy(sbuf, sp->sp_name); 500*12530Sdlw else 501*12530Sdlw strcpy(sbuf, "-"); 502*12530Sdlw 503*12530Sdlw if (strlen(sbuf) < 8) 504*12530Sdlw strcat(sbuf, "\t"); 505*12530Sdlw 506*12530Sdlw return (sbuf); 507*12530Sdlw } 508*12530Sdlw 509*12530Sdlw char * 510*12530Sdlw termname (port) 511*12530Sdlw char *port; 512*12530Sdlw { 513*12530Sdlw register struct ttytype *tp; 514*12530Sdlw 515*12530Sdlw for (tp = ttytype; tp->tp_term[0]; tp++) 516*12530Sdlw if (strcmp(port, tp->tp_port) == 0) 517*12530Sdlw return (tp->tp_term); 518*12530Sdlw 519*12530Sdlw if (tp < &ttytype[(sizeof ttytype / sizeof (struct ttytype)) -1]) 520*12530Sdlw { 521*12530Sdlw strcpy(tp->tp_port, port); 522*12530Sdlw strcpy(tp->tp_term, "unknown"); 523*12530Sdlw (++tp)->tp_term[0] = '\0'; 524*12530Sdlw } 525*12530Sdlw 526*12530Sdlw return ("unknown"); 527*12530Sdlw } 528*12530Sdlw 529*12530Sdlw char 530*12530Sdlw speedchar (speed) 531*12530Sdlw char *speed; 532*12530Sdlw { 533*12530Sdlw register struct speeds *sp; 534*12530Sdlw 535*12530Sdlw for (sp = speeds; sp->sp_table; sp++) 536*12530Sdlw if (strcmp(sp->sp_name, speed) == 0) 537*12530Sdlw return (sp->sp_table); 538*12530Sdlw return ('\0'); 539*12530Sdlw } 540*12530Sdlw 541*12530Sdlw struct ttytype * 542*12530Sdlw type (port) 543*12530Sdlw char *port; 544*12530Sdlw { 545*12530Sdlw register struct ttytype *tp; 546*12530Sdlw 547*12530Sdlw for (tp = ttytype; tp->tp_term[0]; tp++) 548*12530Sdlw if (strcmp(tp->tp_port, port) == 0) 549*12530Sdlw return (tp); 550*12530Sdlw 551*12530Sdlw if (tp < &ttytype[(sizeof ttytype / sizeof (struct ttytype)) -1]) 552*12530Sdlw { 553*12530Sdlw strcpy(tp->tp_port, port); 554*12530Sdlw strcpy(tp->tp_term, "unknown"); 555*12530Sdlw return(tp); 556*12530Sdlw } 557*12530Sdlw 558*12530Sdlw return((struct ttytype *)0); 559*12530Sdlw } 560*12530Sdlw 561*12530Sdlw /* DELETE this for 4.2bsd */ 562*12530Sdlw 563*12530Sdlw #include <errno.h> 564*12530Sdlw 565*12530Sdlw rename (from, to) 566*12530Sdlw char *from, *to; 567*12530Sdlw { 568*12530Sdlw extern int errno; 569*12530Sdlw 570*12530Sdlw if (unlink(to) < 0) 571*12530Sdlw if (errno != ENOENT) 572*12530Sdlw return(-1); 573*12530Sdlw if (link(from, to) == 0) 574*12530Sdlw return (unlink(from)); 575*12530Sdlw else 576*12530Sdlw return(-1); 577*12530Sdlw } 578*12530Sdlw 579