1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
6 * Copyright (C) 2004 Novell, Inc.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
31 #include <sys/types.h>
39 FIXME: It is not safe to call this function from multiple threads.
45 static char proc_filename
[64] = {'\0'};
46 static char buffer
[1024];
50 if (proc_filename
[0] == '\0')
51 snprintf (proc_filename
, 64, "/proc/%d/status", getpid ());
53 fd
= open (proc_filename
, O_RDONLY
);
55 if (read (fd
, buffer
, sizeof (buffer
)) > 0) {
56 char *pos
= strstr (buffer
, "VmSize:");
58 if (pos
!= NULL
&& strlen (pos
) > 7) {
60 while (*pos
&& isspace (*pos
))
63 vmsize
= (int) strtol (pos
, &endpos
, 10);
64 if (pos
== endpos
|| *endpos
!= ' ')
75 /* a stupid cut&paste */
79 static char proc_filename
[64] = {'\0'};
80 static char buffer
[1024];
84 if (proc_filename
[0] == '\0')
85 snprintf (proc_filename
, 64, "/proc/%d/status", getpid ());
87 fd
= open (proc_filename
, O_RDONLY
);
89 if (read (fd
, buffer
, sizeof (buffer
)) > 0) {
90 char *pos
= strstr (buffer
, "VmRSS:");
92 if (pos
!= NULL
&& strlen (pos
) > 7) {
94 while (*pos
&& isspace (*pos
))
97 vmsize
= (int) strtol (pos
, &endpos
, 10);
98 if (pos
== endpos
|| *endpos
!= ' ')