2002-05-05 Dick Porter <dick@ximian.com>
[mono.git] / mono / handles / scratch.c
1 #include <config.h>
2 #include <glib.h>
3 #include <unistd.h>
4
5 #include <mono/io-layer/io-layer.h>
6
7 /* We're digging into handle internals here... */
8 #include <mono/io-layer/handles-private.h>
9 #include <mono/io-layer/wapi-private.h>
10
11 #define HDRSIZE sizeof(struct _WapiScratchHeader)
12
13 static guchar *printable (guchar *data, guint32 datalen)
14 {
15         static guchar buf[32];
16         guint32 i;
17         
18         if(datalen>=32) {
19                 datalen=31;
20         }
21
22         for(i=0; i<datalen; i++) {
23                 if(g_ascii_isprint (data[i])) {
24                         buf[i]=data[i];
25                 } else {
26                         buf[i]='.';
27                 }
28         }
29         buf[i]='\0';
30
31         return(buf);
32 }
33
34 int main (int argc, char **argv)
35 {
36         guint32 idx=0;
37         struct _WapiScratchHeader *hdr;
38         
39         _wapi_shared_data=_wapi_shm_attach (FALSE);
40
41         hdr=(struct _WapiScratchHeader *)&_wapi_shared_data->scratch_base[0];
42         if(hdr->flags==0 && hdr->length==0) {
43                 g_print ("Scratch space unused\n");
44                 exit (0);
45         }
46         
47         while(idx < _WAPI_SHM_SCRATCH_SIZE) {
48                 hdr=(struct _WapiScratchHeader *)&_wapi_shared_data->scratch_base[idx];
49                 if(hdr->flags & WAPI_SHM_SCRATCH_FREE) {
50                         g_print ("Free block at %6d (index %6d), length %6d\n",
51                                  idx, idx+HDRSIZE, hdr->length);
52                 } else {
53                         guchar *data=&_wapi_shared_data->scratch_base[idx+HDRSIZE];
54                         
55                         g_print ("Used block at %6d (index %6d), length %6d, [%s]\n",
56                                  idx, idx+HDRSIZE, hdr->length,
57                                  printable (data, hdr->length));
58                 }
59
60                 idx+=(hdr->length+HDRSIZE);
61         }
62         
63         exit (0);
64 }