~ubuntu-branches/debian/sid/net-tools/sid

« back to all changes in this revision

Viewing changes to .pc/CVS-lib_sync.patch/lib/proc.c

  • Committer: Package Import Robot
  • Author(s): Martín Ferrari
  • Date: 2015-09-07 01:54:07 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20150907015407-v2tfsgxayjd3iq4i
Tags: 1.60+git20150829.73cef8a-1
* After 14 years without an upstream release, I am producing a new package
  based on today's upstream repository.
  Closes: #391495, #486448, #323261, #260587, #545328, #511395.
* Remove many patches now merged upstream, delete unmaintainable and
  undocumented local changes, and update the rest.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Tolerant /proc file parser. Copyright 1998 Andi Kleen */
2
 
/* $Id: proc.c,v 1.4 1999/01/05 20:54:00 philip Exp $ */ 
3
 
/* Fixme: cannot currently cope with removed fields */ 
4
 
 
5
 
#include <string.h>
6
 
#include <stdarg.h>
7
 
#include <stdio.h>
8
 
#include <ctype.h>
9
 
 
10
 
/* Caller must free return string. */
11
 
 
12
 
char *proc_gen_fmt(char *name, int more, FILE * fh,...)
13
 
{
14
 
    char buf[512], format[512] = "";
15
 
    char *title, *head, *hdr;
16
 
    va_list ap;
17
 
 
18
 
    if (!fgets(buf, (sizeof buf) - 1, fh))
19
 
        return NULL;
20
 
    strcat(buf, " ");
21
 
 
22
 
    va_start(ap, fh);
23
 
    title = va_arg(ap, char *);
24
 
    for (hdr = buf; hdr;) {
25
 
        while (isspace(*hdr) || *hdr == '|')
26
 
            hdr++;
27
 
        head = hdr;
28
 
        hdr = strpbrk(hdr, "| \t\n");
29
 
        if (hdr)
30
 
            *hdr++ = 0;
31
 
 
32
 
        if (!strcmp(title, head)) {
33
 
            strcat(format, va_arg(ap, char *));
34
 
            title = va_arg(ap, char *);
35
 
            if (!title || !head)
36
 
                break;
37
 
        } else {
38
 
            strcat(format, "%*s");      /* XXX */
39
 
        }
40
 
        strcat(format, " ");
41
 
    }
42
 
    va_end(ap);
43
 
 
44
 
    if (!more && title) {
45
 
        fprintf(stderr, "warning: %s does not contain required field %s\n",
46
 
                name, title);
47
 
        return NULL;
48
 
    }
49
 
    return strdup(format);
50
 
}
51
 
 
52
 
/* 
53
 
 * this will generate a bitmask of present/missing fields in the header of
54
 
 * a /proc file.
55
 
 */
56
 
int proc_guess_fmt(char *name, FILE *fh, ...)
57
 
{
58
 
    char buf[512];
59
 
    char *tmp;
60
 
    int flag = 0;
61
 
    va_list ap;
62
 
 
63
 
    if (!fgets(buf, (sizeof buf) - 1, fh))
64
 
        return -1;
65
 
    strcat(buf, "\0");
66
 
    va_start(ap, fh);
67
 
    while((tmp = va_arg(ap, char *))) {
68
 
      int f = va_arg(ap, int);
69
 
      if (strstr(buf,tmp) != 0)
70
 
        flag |= f;
71
 
    }
72
 
    va_end(ap);
73
 
    return flag;
74
 
}