tuned out the knocking
[platform/upstream/libvorbis.git] / win32 / src / shmmap_c.h
1 /********************************************************************
2  *                                                                  *
3  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
4  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
5  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
7  *                                                                  *
8  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
9  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
10
11  ********************************************************************
12
13  function: Creates an image of strutures and mappings in registry.c
14            to be copied into shared memory segment via DllMain().
15            See: dllmain.c
16
17  created:  06-Sep-2001, Chris Wolf 
18
19  last mod: $Id: shmmap_c.h,v 1.1 2001/09/11 20:16:11 cwolf Exp $
20
21  This module gets conditionally appended to the end of registry.c
22  ********************************************************************/
23 #include <malloc.h>
24 #include <memory.h>
25
26 #include <shmmap.h>
27
28 /**
29  * Create image of mappings defined in regsitry.c.
30  *
31  * PARAM  len: pointer to callers length indicator, will indicate
32  *             size of shared map.
33  * RETURN SHARED_MAP: pointer to allocated mapping image, NULL on failure.
34  */
35 SHARED_MAP* table_map2mem(int *len)
36 {
37   SHARED_MAP* map;
38   int p;
39   int size;
40
41   if ((map = calloc(1, sizeof(SHARED_MAP))) == (SHARED_MAP*)0)
42     return (SHARED_MAP*)0;
43
44   size =         sizeof(SHARED_MAP);
45
46   if ((map->p_time_P = calloc(NUMELEMENTS(_time_P), 
47                  sizeof(vorbis_func_time*))) == (vorbis_func_time**)0)
48     return (SHARED_MAP*)0;
49
50   size += sizeof(_time_P);
51   
52   for (p=0; p<NUMELEMENTS(_time_P); p++)
53   {
54     if ((map->p_time_P[p] = calloc(NUMELEMENTS(_time_P), 
55                  sizeof(vorbis_func_time))) == (vorbis_func_time*)0)
56       return (SHARED_MAP*)0;
57
58     (void)memcpy((void *)map->p_time_P[p], 
59                  (const void *)_time_P[p], 
60                  sizeof(vorbis_func_time));
61
62     size +=      sizeof(vorbis_func_time);
63   }
64
65   if ((map->p_floor_P = calloc(NUMELEMENTS(_floor_P), 
66                  sizeof(vorbis_func_floor*))) == (vorbis_func_floor**)0)
67     return (SHARED_MAP*)0;
68
69   size +=        sizeof(_floor_P);
70   
71   for (p=0; p<NUMELEMENTS(_floor_P); p++)
72   {
73     if ((map->p_floor_P[p] = calloc(1, 
74                  sizeof(vorbis_func_floor))) == (vorbis_func_floor*)0)
75       return (SHARED_MAP*)0;
76
77     (void)memcpy((void *)map->p_floor_P[p], 
78                  (const void *)_floor_P[p], 
79                  sizeof(vorbis_func_floor));
80
81     size +=      sizeof(vorbis_func_floor);
82   }
83
84   if ((map->p_residue_P = calloc(NUMELEMENTS(_residue_P), 
85                  sizeof(vorbis_func_residue*))) == (vorbis_func_residue**)0)
86   size +=        sizeof(_residue_P);
87
88   for (p=0; p<NUMELEMENTS(_residue_P); p++)
89   {
90     if ((map->p_residue_P[p] = calloc(1, 
91                  sizeof(vorbis_func_residue))) == (vorbis_func_residue*)0)
92       return (SHARED_MAP*)0;
93
94     (void)memcpy((void *)map->p_residue_P[p], 
95                  (const void *)_residue_P[p], 
96                  sizeof(vorbis_func_residue));
97
98     size +=      sizeof(vorbis_func_residue);
99   }
100
101   if ((map->p_mapping_P = calloc(NUMELEMENTS(_mapping_P), 
102                  sizeof(vorbis_func_mapping*))) == (vorbis_func_mapping**)0)
103       return (SHARED_MAP*)0;
104
105   size +=        sizeof(_mapping_P);
106
107   for (p=0; p<NUMELEMENTS(_mapping_P); p++)
108   {
109     if ((map->p_mapping_P[p] = calloc(1, 
110                  sizeof(vorbis_func_mapping))) == (vorbis_func_mapping*)0)
111       return (SHARED_MAP*)0;
112
113     (void)memcpy((void *)map->p_mapping_P[p], 
114                  (const void *)_mapping_P[p], 
115                  sizeof(vorbis_func_mapping));
116
117     size +=      sizeof(vorbis_func_mapping);
118   }
119
120   *len = size;
121
122   return (map);
123 }