library: tweak formatting style for meminfo and vmstat
This patch mostly just eliminates darn tab characters. Plus the library function declarations and definitions have been standardized. Most visibly, the input params now have all been indented on their own separate line. Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
@ -41,12 +41,13 @@ struct procps_vmstat {
|
||||
*
|
||||
* Returns: a new procps_vmstat container
|
||||
*/
|
||||
PROCPS_EXPORT int procps_vmstat_new(struct procps_vmstat **info)
|
||||
PROCPS_EXPORT int procps_vmstat_new (
|
||||
struct procps_vmstat **info)
|
||||
{
|
||||
struct procps_vmstat *v;
|
||||
v = calloc(1, sizeof(struct procps_vmstat));
|
||||
if (!v)
|
||||
return -ENOMEM;
|
||||
return -ENOMEM;
|
||||
|
||||
v->refcount = 1;
|
||||
v->vmstat_fd = -1;
|
||||
@ -62,7 +63,8 @@ PROCPS_EXPORT int procps_vmstat_new(struct procps_vmstat **info)
|
||||
*
|
||||
* Returns: 0 on success, negative on error
|
||||
*/
|
||||
PROCPS_EXPORT int procps_vmstat_read(struct procps_vmstat *info)
|
||||
PROCPS_EXPORT int procps_vmstat_read (
|
||||
struct procps_vmstat *info)
|
||||
{
|
||||
char buf[8192];
|
||||
char *head, *tail;
|
||||
@ -70,85 +72,87 @@ PROCPS_EXPORT int procps_vmstat_read(struct procps_vmstat *info)
|
||||
unsigned long *valptr;
|
||||
|
||||
if (info == NULL)
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
memset(&(info->data), 0, sizeof(struct vmstat_data));
|
||||
/* read in the data */
|
||||
|
||||
if (-1 == info->vmstat_fd && (info->vmstat_fd = open(VMSTAT_FILE, O_RDONLY)) == -1) {
|
||||
return -errno;
|
||||
return -errno;
|
||||
}
|
||||
if (lseek(info->vmstat_fd, 0L, SEEK_SET) == -1) {
|
||||
return -errno;
|
||||
return -errno;
|
||||
}
|
||||
if ((size = read(info->vmstat_fd, buf, sizeof(buf)-1)) < 0) {
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
buf[size] = '\0';
|
||||
|
||||
/* Scan the file */
|
||||
head = buf;
|
||||
do {
|
||||
tail = strchr(head, ' ');
|
||||
if (!tail)
|
||||
break;
|
||||
*tail = '\0';
|
||||
valptr = NULL;
|
||||
if (0 == strcmp(head, "pgpgin")) {
|
||||
valptr = &(info->data.pgpgin);
|
||||
}else if (0 == strcmp(head, "pgpgout")) {
|
||||
valptr = &(info->data.pgpgout);
|
||||
}else if (0 == strcmp(head, "pswpin")) {
|
||||
valptr = &(info->data.pswpin);
|
||||
}else if (0 == strcmp(head, "pswpout")) {
|
||||
valptr = &(info->data.pswpout);
|
||||
}
|
||||
head = tail+1;
|
||||
if (valptr) {
|
||||
*valptr = strtoul(head, &tail, 10);
|
||||
}
|
||||
tail = strchr(head, ' ');
|
||||
if (!tail)
|
||||
break;
|
||||
*tail = '\0';
|
||||
valptr = NULL;
|
||||
if (0 == strcmp(head, "pgpgin")) {
|
||||
valptr = &(info->data.pgpgin);
|
||||
}else if (0 == strcmp(head, "pgpgout")) {
|
||||
valptr = &(info->data.pgpgout);
|
||||
}else if (0 == strcmp(head, "pswpin")) {
|
||||
valptr = &(info->data.pswpin);
|
||||
}else if (0 == strcmp(head, "pswpout")) {
|
||||
valptr = &(info->data.pswpout);
|
||||
}
|
||||
head = tail+1;
|
||||
if (valptr) {
|
||||
*valptr = strtoul(head, &tail, 10);
|
||||
}
|
||||
|
||||
tail = strchr(head, '\n');
|
||||
if (!tail)
|
||||
break;
|
||||
head = tail + 1;
|
||||
tail = strchr(head, '\n');
|
||||
if (!tail)
|
||||
break;
|
||||
head = tail + 1;
|
||||
} while(tail);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PROCPS_EXPORT struct procps_vmstat *procps_vmstat_ref(struct procps_vmstat *info)
|
||||
PROCPS_EXPORT struct procps_vmstat *procps_vmstat_ref (
|
||||
struct procps_vmstat *info)
|
||||
{
|
||||
if (info == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
info->refcount++;
|
||||
return info;
|
||||
}
|
||||
|
||||
PROCPS_EXPORT struct procps_vmstat *procps_vmstat_unref(struct procps_vmstat *info)
|
||||
PROCPS_EXPORT struct procps_vmstat *procps_vmstat_unref (
|
||||
struct procps_vmstat *info)
|
||||
{
|
||||
if (info == NULL)
|
||||
return NULL;
|
||||
return NULL;
|
||||
info->refcount--;
|
||||
if (info->refcount > 0)
|
||||
return NULL;
|
||||
return NULL;
|
||||
free(info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Accessor functions */
|
||||
PROCPS_EXPORT unsigned long procps_vmstat_get(
|
||||
struct procps_vmstat *info,
|
||||
enum vmstat_item item)
|
||||
PROCPS_EXPORT unsigned long procps_vmstat_get (
|
||||
struct procps_vmstat *info,
|
||||
enum vmstat_item item)
|
||||
{
|
||||
switch(item) {
|
||||
case PROCPS_VMSTAT_PGPGIN:
|
||||
return info->data.pgpgin;
|
||||
case PROCPS_VMSTAT_PGPGOUT:
|
||||
return info->data.pgpgout;
|
||||
case PROCPS_VMSTAT_PSWPIN:
|
||||
return info->data.pswpin;
|
||||
case PROCPS_VMSTAT_PSWPOUT:
|
||||
return info->data.pswpout;
|
||||
switch (item) {
|
||||
case PROCPS_VMSTAT_PGPGIN:
|
||||
return info->data.pgpgin;
|
||||
case PROCPS_VMSTAT_PGPGOUT:
|
||||
return info->data.pgpgout;
|
||||
case PROCPS_VMSTAT_PSWPIN:
|
||||
return info->data.pswpin;
|
||||
case PROCPS_VMSTAT_PSWPOUT:
|
||||
return info->data.pswpout;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user