YAZ  5.34.0
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 #include <yaz/yconfig.h>
16 
17 #if HAVE_MALLOC_INFO
18 #include <malloc.h>
19 #endif
20 #include <stdio.h>
21 
22 #include <yaz/wrbuf.h>
23 #include <yaz/malloc_info.h>
24 
26 {
27  int r = -2;
28 #if HAVE_MALLOC_INFO
29 #if HAVE_OPEN_MEMSTREAM
30  char *ptr = 0;
31  size_t sz = 0;
32  FILE *f = open_memstream(&ptr, &sz);
33  if (!f)
34  r = -1;
35  else
36  {
37  r = malloc_info(0, f);
38  fclose(f);
39  wrbuf_write(b, ptr, sz);
40  }
41  if (ptr)
42  free(ptr);
43 #endif
44 #endif
45  return r;
46 }
47 /*
48  * Local variables:
49  * c-basic-offset: 4
50  * c-file-style: "Stroustrup"
51  * indent-tabs-mode: nil
52  * End:
53  * vim: shiftwidth=4 tabstop=8 expandtab
54  */
55 
void free(void *)
int wrbuf_malloc_info(WRBUF b)
malloc_info to WRBUF
Definition: malloc_info.c:25
Malloc info reporting via WRBUF.
string buffer
Definition: wrbuf.h:43
void wrbuf_write(WRBUF b, const char *buf, size_t size)
append constant size buffer to WRBUF
Definition: wrbuf.c:68
Header for WRBUF (growing buffer)
Header with fundamental macros.