if (cp->cache[i].id == id)
return i;
i = cp->size++;
- cp->cache = xrealloc(cp->cache, cp->size * sizeof(*cp->cache));
+ cp->cache = xrealloc_vector(cp->cache, 2, i);
cp->cache[i++].id = id;
return -i;
}
if (cp->cache[i].id == id)
return cp->cache[i].name;
i = cp->size++;
- cp->cache = xrealloc(cp->cache, cp->size * sizeof(*cp->cache));
+ cp->cache = xrealloc_vector(cp->cache, 2, i);
cp->cache[i].id = id;
/* Never fails. Generates numeric string if name isn't found */
fp(cp->cache[i].name, sizeof(cp->cache[i].name), id);
#define PROCPS_BUFSIZE 1024
-static int FAST_FUNC read_to_buf(const char *filename, void *buf)
+static int read_to_buf(const char *filename, void *buf)
{
int fd;
/* open_read_close() would do two reads, checking for EOF.
FILE *file;
strcpy(filename_tail, "/smaps");
- file = fopen(filename, "r");
+ file = fopen_for_read(filename);
if (!file)
break;
while (fgets(buf, sizeof(buf), file)) {
n = read_to_buf(filename, buf);
if (n <= 0)
break;
-#if ENABLE_PGREP || ENABLE_PKILL
if (flags & PSSCAN_ARGVN) {
- do {
- n--;
- if (buf[n] == '\0')
- buf[n] = ' ';
- } while (n);
+ sp->argv_len = n;
+ sp->argv0 = xmalloc(n + 1);
+ memcpy(sp->argv0, buf, n + 1);
+ /* sp->argv0[n] = '\0'; - buf has it */
+ } else {
+ sp->argv_len = 0;
+ sp->argv0 = xstrdup(buf);
}
-#endif
- sp->argv0 = xstrdup(buf);
}
#endif
break;