chiark / gitweb /
util, manager: and mempset() and use it
authorMichal Schmidt <mschmidt@redhat.com>
Tue, 5 Mar 2013 14:52:44 +0000 (15:52 +0100)
committerMichal Schmidt <mschmidt@redhat.com>
Wed, 13 Mar 2013 13:14:13 +0000 (14:14 +0100)
Just like mempcpy() is almost identical to memcpy() except the useful
return value, so is the relation of mempset() to memset().

src/core/manager.c
src/shared/util.h

index a3eeb4afc10c9837c238bc4e1c9d739e6b9cda25..8e66732cd7bf8c68347f6a307b10f37e1aea2246 100644 (file)
@@ -226,10 +226,8 @@ static void draw_cylon(char buffer[], size_t buflen, unsigned width, unsigned po
         assert(pos <= width+1); /* 0 or width+1 mean that the center light is behind the corner */
 
         if (pos > 1) {
         assert(pos <= width+1); /* 0 or width+1 mean that the center light is behind the corner */
 
         if (pos > 1) {
-                if (pos > 2) {
-                        memset(p, ' ', pos-2);
-                        p += pos-2;
-                }
+                if (pos > 2)
+                        p = mempset(p, ' ', pos-2);
                 p = stpcpy(p, ANSI_RED_ON);
                 *p++ = '*';
         }
                 p = stpcpy(p, ANSI_RED_ON);
                 *p++ = '*';
         }
@@ -244,10 +242,8 @@ static void draw_cylon(char buffer[], size_t buflen, unsigned width, unsigned po
         if (pos < width) {
                 p = stpcpy(p, ANSI_RED_ON);
                 *p++ = '*';
         if (pos < width) {
                 p = stpcpy(p, ANSI_RED_ON);
                 *p++ = '*';
-                if (pos < width-1) {
-                        memset(p, ' ', width-1-pos);
-                        p += width-1-pos;
-                }
+                if (pos < width-1)
+                        p = mempset(p, ' ', width-1-pos);
                 p = stpcpy(p, ANSI_HIGHLIGHT_OFF);
         }
 }
                 p = stpcpy(p, ANSI_HIGHLIGHT_OFF);
         }
 }
index 04c9fcd71e4454830ce7a6f76595bcec1c9ec6d6..f0dfe19ad46252e7b0b65148b2c1eb8fc30e3463 100644 (file)
@@ -594,3 +594,8 @@ int search_and_fopen_nulstr(const char *path, const char *mode, const char *sear
                 } else if (ignore_file((de)->d_name))                   \
                         continue;                                       \
                 else
                 } else if (ignore_file((de)->d_name))                   \
                         continue;                                       \
                 else
+
+static inline void *mempset(void *s, int c, size_t n) {
+        memset(s, c, n);
+        return (char*)s + n;
+}