changeset 1279:29603c5a3317 draft

sizeof("string") treats it as a char array _including_ the null terminator, so strncmp(dest, "string", sizeof("string")) is just strcpy.
author Rob Landley <rob@landley.net>
date Sat, 10 May 2014 13:24:58 -0500
parents 324306321d82
children 4947ec3aa896
files toys/pending/last.c
diffstat 1 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/toys/pending/last.c	Sat May 10 13:20:03 2014 -0500
+++ b/toys/pending/last.c	Sat May 10 13:24:58 2014 -0500
@@ -138,7 +138,7 @@
       curlog_type = RUN_LVL;
     } else if (ut.ut_type == BOOT_TIME) {
       seize_duration(tm[0], tm[1]);
-      strncpy(ut.ut_line, "system boot", sizeof("system boot"));
+      strcpy(ut.ut_line, "system boot");
       free_list();
       printf("%-8.8s %-12.12s %-*.*s %-16.16s %-7.7s %s\n", ut.ut_user, 
           ut.ut_line, pwidth, pwidth, ut.ut_host, 
@@ -165,18 +165,18 @@
         seize_duration(tm[0], tm[2]);
         switch (type) {
           case EMPTY:
-            strncpy(toybuf+18, "  still", sizeof("  still"));
-            strncpy(toybuf+28, "logged in", sizeof("logged in")); 
+            strcpy(toybuf+18, "  still");
+            strcpy(toybuf+28, "logged in"); 
             break;
           case RUN_LVL:
-            strncpy(toybuf+18, "- down ", sizeof("- down "));
+            strcpy(toybuf+18, "- down ");
             break;
           case BOOT_TIME:
-            strncpy(toybuf+18, "- crash", sizeof("- crash"));
+            strcpy(toybuf+18, "- crash");
             break;
           case INIT_PROCESS:
-            strncpy(toybuf+18, "   gone", sizeof("   gone"));
-            strncpy(toybuf+28, "- no logout", sizeof("- no logout"));
+            strcpy(toybuf+18, "   gone");
+            strcpy(toybuf+28, "- no logout");
             break;
           default:
             break;