YAZ  5.23.1
malloc_info.c
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5 
11 #if HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14 
15 #if HAVE_MALLOC_INFO
16 #include <malloc.h>
17 #endif
18 #include <stdio.h>
19 
20 #include <yaz/wrbuf.h>
21 #include <yaz/malloc_info.h>
22 
24 {
25  int r = -2;
26 #if HAVE_MALLOC_INFO
27 #if HAVE_OPEN_MEMSTREAM
28  char *ptr = 0;
29  size_t sz = 0;
30  FILE *f = open_memstream(&ptr, &sz);
31  if (!f)
32  r = -1;
33  else
34  {
35  r = malloc_info(0, f);
36  fclose(f);
37  wrbuf_write(b, ptr, sz);
38  }
39  if (ptr)
40  free(ptr);
41 #endif
42 #endif
43  return r;
44 }
45 /*
46  * Local variables:
47  * c-basic-offset: 4
48  * c-file-style: "Stroustrup"
49  * indent-tabs-mode: nil
50  * End:
51  * vim: shiftwidth=4 tabstop=8 expandtab
52  */
53 
int wrbuf_malloc_info(WRBUF b)
malloc_info to WRBUF
Definition: malloc_info.c:23
Header for WRBUF (growing buffer)
void wrbuf_write(WRBUF b, const char *buf, size_t size)
append constant size buffer to WRBUF
Definition: wrbuf.c:68
string buffer
Definition: wrbuf.h:42
void free(void *)
Malloc info reporting via WRBUF.