Commit 20f0f8e1 authored by Bernd Eckenfels's avatar Bernd Eckenfels

Faster pagesize aligned fopen for netstat -s (Eric Dumazet)

parent 41cae5eb
/* Tolerant /proc file parser. Copyright 1998 Andi Kleen */
/* $Id: proc.c,v 1.4 1999/01/05 20:54:00 philip Exp $ */
/* $Id: proc.c,v 1.5 2007/12/01 18:44:57 ecki Exp $ */
/* Fixme: cannot currently cope with removed fields */
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
/* Caller must free return string. */
......@@ -72,3 +73,22 @@ int proc_guess_fmt(char *name, FILE *fh, ...)
va_end(ap);
return flag;
}
FILE *proc_fopen(const char *name)
{
static char *buffer;
static size_t pagesz;
FILE *fd = fopen(name, "r");
if (fd == NULL)
return NULL;
if (!buffer) {
pagesz = getpagesize();
buffer = malloc(pagesz);
}
setvbuf(fd, buffer, _IOFBF, pagesz);
return fd;
}
/* Generate a suitable scanf format for a column title line */
/*
* prototypes for proc.c
*/
char *proc_gen_fmt(char *name, int more, FILE * fh,...);
int proc_guess_fmt(char *name, FILE* fh,...);
FILE *proc_fopen(const char *name);
/*
* Copyright 1997,1999,2000 Andi Kleen. Subject to the GPL.
* $Id: statistics.c,v 1.19 2007/12/01 18:29:05 ecki Exp $
* $Id: statistics.c,v 1.20 2007/12/01 18:44:56 ecki Exp $
* 19980630 - i18n - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
* 19981113 - i18n fixes - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
* 19990101 - added net/netstat, -t, -u, -w supprt - Bernd Eckenfels
......@@ -11,6 +11,7 @@
#include <string.h>
#include "config.h"
#include "intl.h"
#include "proc.h"
/* #define WARN 1 */
......@@ -387,7 +388,7 @@ void parsesnmp(int flag_raw, int flag_tcp, int flag_udp)
f_raw = flag_raw; f_tcp = flag_tcp; f_udp = flag_udp;
f = fopen("/proc/net/snmp", "r");
f = proc_fopen("/proc/net/snmp");
if (!f) {
perror(_("cannot open /proc/net/snmp"));
return;
......@@ -401,7 +402,7 @@ void parsesnmp(int flag_raw, int flag_tcp, int flag_udp)
fclose(f);
f = fopen("/proc/net/netstat", "r");
f = proc_fopen("/proc/net/netstat");
if (f) {
if (process_fd(f) <0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment