From 4f77c0ac81914da49deed40fd3af4307fa284937 Mon Sep 17 00:00:00 2001 From: mickey Date: Sat, 5 May 2001 07:12:50 +0000 Subject: use strlcpy vs strncpy+a[n-1]='\0' --- usr.sbin/ac/ac.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'usr.sbin/ac') diff --git a/usr.sbin/ac/ac.c b/usr.sbin/ac/ac.c index 1a57109acbb..cd166a73b45 100644 --- a/usr.sbin/ac/ac.c +++ b/usr.sbin/ac/ac.c @@ -14,7 +14,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: ac.c,v 1.7 1997/10/09 15:07:17 deraadt Exp $"; +static char rcsid[] = "$Id: ac.c,v 1.8 2001/05/05 07:12:50 mickey Exp $"; #endif #include @@ -129,8 +129,7 @@ add_tty(name) tp->ret = 0; name++; } - (void)strncpy(tp->name, name, sizeof (tp->name) - 1); - tp->name[sizeof (tp->name) - 1] = '\0'; + strlcpy(tp->name, name, sizeof (tp->name)); if ((rcp = strchr(tp->name, '*')) != NULL) { /* wild card */ *rcp = '\0'; tp->len = strlen(tp->name); /* match len bytes only */ @@ -210,8 +209,7 @@ update_user(head, name, secs) if ((up = NEW(struct user_list)) == NULL) err(1, "malloc"); up->next = head; - (void)strncpy(up->name, name, sizeof (up->name) - 1); - up->name[sizeof (up->name) - 1] = '\0'; /* paranoid! */ + strlcpy(up->name, name, sizeof (up->name)); up->secs = secs; Total += secs; return up; @@ -420,8 +418,7 @@ log_in(head, up) /* * this allows us to pick the right logout */ - (void)strncpy(up->ut_line, Console, sizeof (up->ut_line) - 1); - up->ut_line[sizeof (up->ut_line) - 1] = '\0'; /* paranoid! */ + strlcpy(up->ut_line, Console, sizeof (up->ut_line)); } #endif /* -- cgit v1.2.3-59-g8ed1b