/*
- * Copyright (C) 2010 Timo Kokkonen <kaapeli@itanic.dy.fi>
+ * Copyright (C) 2010 Timo Kokkonen <timo.t.kokkonen@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
while (fgets(line, sizeof(line), file)) {
struct maps *map = alloc_map();
unsigned long start, end;
- char name[1024];
+ int skip;
if (map == NULL)
return 0;
if (the_map == NULL)
the_map = map;
- ret = sscanf(line, "%lx-%lx %*s %*s %*s %*s %s",
- &start, &end, name);
+ ret = sscanf(line, "%lx-%lx %*s %*s %*s %*s %n",
+ &start, &end, &skip);
if (ret < 2) {
printf("Error reading input: %s\n", line);
map->pid = pid;
map->tid = tid;
- if (ret >= 3)
- strncpy(map->name, name, sizeof(map->name));
+ strncpy(map->name, line + skip, sizeof(map->name) - 1);
+
+ /* zero out the newline */
+ map->name[MAX(strlen(map->name) - 1, 0)] = '\0';
list_add_tail(&map->list, &the_map->list);
}
int ret;
kpageflags_fd = open("/proc/kpageflags", O_RDONLY);
- kpagecount_fd = open("/proc/kpagecount", O_RDONLY);
+ if (kpageflags_fd < 0)
+ return -1;
- if (kpageflags_fd == -1 || kpagecount_fd == -1)
+ kpagecount_fd = open("/proc/kpagecount", O_RDONLY);
+ if (kpagecount_fd < 0)
return -1;
pf = rb_to_pageframe(rb_first(root));