OTF_Stream *stream;
};
+struct _OTF_ApplicationData
+{
+ char *id;
+ void *data;
+ void (*freer) (void *data);
+ struct _OTF_ApplicationData *next;
+};
+
+typedef struct _OTF_ApplicationData OTF_ApplicationData;
+
struct OTF_InternalData
{
/* Information about each OTF table. */
/* Records of allocated memories. */
OTF_MemoryRecord *memory_record;
+
+ /* Root of application data chain. */
+ OTF_ApplicationData *app_data;
};
if (internal_data)
{
OTF_MemoryRecord *memrec = internal_data->memory_record;
+ OTF_ApplicationData *app_data = internal_data->app_data;
if (internal_data->header_stream)
free_stream (internal_data->header_stream);
free (memrec);
memrec = next;
}
+
+ for (; app_data; app_data = app_data->next)
+ if (app_data->data && app_data->freer)
+ app_data->freer (app_data->data);
free (internal_data);
}
if (otf->filename)
name[3] = (char) (tag & 0xFF);
name[4] = '\0';
}
+
+int
+OTF_put_data (OTF *otf, char *id, void *data, void (*freer) (void *data))
+{
+ char *errfmt = "appdata %s";
+ int errret = -1;
+ OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data;
+ OTF_ApplicationData *app_data = internal_data->app_data;
+ int len = strlen (id) + 1;
+
+ for (; app_data; app_data = app_data->next)
+ if (memcmp (app_data->id, id, len) == 0)
+ {
+ if (app_data->data && app_data->freer)
+ app_data->freer (app_data->data);
+ break;
+ }
+ if (! app_data)
+ {
+ OTF_MALLOC (app_data, sizeof (OTF_ApplicationData), id);
+ app_data->next = internal_data->app_data;
+ internal_data->app_data = app_data;
+ OTF_MALLOC (app_data->id, len, id);
+ memcpy (app_data->id, id, len);
+ }
+ app_data->data = data;
+ app_data->freer = freer;
+ return 0;
+}
+
+void *
+OTF_get_data (OTF *otf, char *id)
+{
+ OTF_InternalData *internal_data = (OTF_InternalData *) otf->internal_data;
+ OTF_ApplicationData *app_data = internal_data->app_data;
+
+ for (; app_data; app_data = app_data->next)
+ if (strcmp (app_data->id, id) == 0)
+ return app_data->data;
+ return NULL;
+}