strncpy(path, argv[optind], 128);
safe_strncpy(path, argv[optind], sizeof(path));
main(int argc, char *argv[]){  char path[128];  char buff[128];  char *speed = NULL;  char *proto = DEF_PROTO;  char *extcmd = (char *)0;  struct hwtype *ht;  char *sp;  int s;  static struct option longopts[] = {    { "version", 0, NULL, 'V' },    { NULL, 0, NULL, 0 }  };  strcpy(path, "");  /* Scan command line for any arguments. */  opterr = 0;  while ((s = getopt_long(argc, argv, "c:ehlLmnp:qs:vdVk:o:", longopts, NULL)) != EOF) switch(s) {	case 'c':		extcmd = optarg;		break;	case 'e':		opt_e = 1 - opt_e;		break;	case 'h':		opt_h = 1 - opt_h;		break;#ifdef SIOCSKEEPALIVE	case 'k':		opt_k = atoi(optarg);		break;#endif	case 'L':		opt_L = 1 - opt_L;		break;	case 'l':		opt_l = 1 - opt_l;		break;	case 'm':		opt_m = 1 - opt_m;		break;	case 'n':		opt_n = 1 - opt_n;		break;#ifdef SIOCSOUTFILL	case 'o':		opt_o = atoi(optarg);		break;#endif	case 'p':		proto = optarg;		break;	case 'q':		opt_q = 1 - opt_q;		break;	case 's':		speed = optarg;		break;	case 'd':		opt_d = 1 - opt_d;		break;	case 'v':		opt_v = 1 - opt_v;		break;        case 'V':		version();		/*NOTREACHED*/	default:		usage();		/*NOTREACHED*/  }    activate_init();  /* Check the protocol. */  if ((ht = get_hwtype(proto)) == NULL && strcmp(proto, "tty")) {	if (opt_q == 0) fprintf(stderr, _("slattach: unsupported protocol %s\n"), proto);	return(2);  }  if (ht == NULL) opt_m++;  /* Is a terminal given? */  if (optind != (argc - 1)) usage();  strncpy(path, argv[optind], 128);  if (!strcmp(path, "-")) {	opt_e = 1;	sp = NULL;	if (tty_open(NULL, speed) < 0) { return(3); }  } else {	if ((sp = strrchr(path, '/')) != NULL) *sp++ = '\0';	  else sp = path;	if (tty_open(sp, speed) < 0) { return(3); }  }  /* Start the correct protocol. */  if (ht == NULL) {	tty_sdisc = N_TTY;	tty_close();	return(0);  }  (*ht->activate)(tty_fd);  if ((opt_v == 1) || (opt_d == 1)) {	tty_get_name(buff);	printf(_("%s started"), proto);	if (sp != NULL) printf(_(" on %s"), sp);	printf(_(" interface %s\n"), buff);  }  /* Configure keepalive and outfill. */#ifdef SIOCSKEEPALIVE  if (opt_k && (ioctl(tty_fd, SIOCSKEEPALIVE, &opt_k) < 0))	  fprintf(stderr, "slattach: ioctl(SIOCSKEEPALIVE): %s\n", strerror(errno));#endif#ifdef SIOCSOUTFILL  if (opt_o && (ioctl(tty_fd, SIOCSOUTFILL, &opt_o) < 0))	  fprintf(stderr, "slattach: ioctl(SIOCSOUTFILL): %s\n", strerror(errno));#endif  (void) signal(SIGHUP, sig_catch);  (void) signal(SIGINT, sig_catch);  (void) signal(SIGQUIT, sig_catch);  (void) signal(SIGTERM, sig_catch);  /* Wait until we get killed if hanging on a terminal. */  if (opt_e == 0) {	while(1) {		if(opt_h == 1) { /* hangup on carrier loss */			int n = 0;		        ioctl(tty_fd, TIOCMGET, &n);			if(!(n & TIOCM_CAR))				break;			sleep(15);		}		else			sleep(60);	};	tty_close();	if(extcmd!=(char *)0) /* external command on exit */		system(extcmd);  }  exit(0);}