Back to index

libdrm  2.4.37
Classes | Defines | Typedefs | Functions
bof.h File Reference
#include <stdio.h>
#include <stdint.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  bof

Defines

#define BOF_TYPE_STRING   0
#define BOF_TYPE_NULL   1
#define BOF_TYPE_BLOB   2
#define BOF_TYPE_OBJECT   3
#define BOF_TYPE_ARRAY   4
#define BOF_TYPE_INT32   5

Typedefs

typedef struct bof bof_t

Functions

int bof_file_flush (bof_t *root)
bof_tbof_file_new (const char *filename)
int bof_object_dump (bof_t *object, const char *filename)
bof_tbof_object (void)
bof_tbof_object_get (bof_t *object, const char *keyname)
int bof_object_set (bof_t *object, const char *keyname, bof_t *value)
bof_tbof_array (void)
int bof_array_append (bof_t *array, bof_t *value)
bof_tbof_array_get (bof_t *bof, unsigned i)
unsigned bof_array_size (bof_t *bof)
bof_tbof_blob (unsigned size, void *value)
unsigned bof_blob_size (bof_t *bof)
void * bof_blob_value (bof_t *bof)
bof_tbof_string (const char *value)
bof_tbof_int32 (int32_t value)
int32_t bof_int32_value (bof_t *bof)
void bof_decref (bof_t *bof)
void bof_incref (bof_t *bof)
bof_tbof_load_file (const char *filename)
int bof_dump_file (bof_t *bof, const char *filename)
void bof_print (bof_t *bof)
static int bof_is_object (bof_t *bof)
static int bof_is_blob (bof_t *bof)
static int bof_is_null (bof_t *bof)
static int bof_is_int32 (bof_t *bof)
static int bof_is_array (bof_t *bof)
static int bof_is_string (bof_t *bof)

Class Documentation

struct bof

Definition at line 41 of file bof.h.

Collaboration diagram for bof:
Class Members
struct bof ** array
uint32_t array_size
unsigned centry
FILE * file
unsigned nentry
long offset
unsigned refcount
uint32_t size
uint32_t type
void * value

Define Documentation

#define BOF_TYPE_ARRAY   4

Definition at line 36 of file bof.h.

#define BOF_TYPE_BLOB   2

Definition at line 34 of file bof.h.

#define BOF_TYPE_INT32   5

Definition at line 37 of file bof.h.

#define BOF_TYPE_NULL   1

Definition at line 33 of file bof.h.

#define BOF_TYPE_OBJECT   3

Definition at line 35 of file bof.h.

#define BOF_TYPE_STRING   0

Definition at line 32 of file bof.h.


Typedef Documentation

typedef struct bof bof_t

Function Documentation

bof_t* bof_array ( void  )

Definition at line 100 of file bof.c.

{
       bof_t *array = bof_object();

       if (array == NULL)
              return NULL;
       array->type = BOF_TYPE_ARRAY;
       array->size = 12;
       return array;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int bof_array_append ( bof_t array,
bof_t value 
)

Definition at line 111 of file bof.c.

{
       int r;
       if (array->type != BOF_TYPE_ARRAY)
              return -EINVAL;
       r = bof_entry_grow(array);
       if (r)
              return r;
       array->array[array->array_size++] = value;
       array->size += value->size;
       bof_incref(value);
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bof_t* bof_array_get ( bof_t bof,
unsigned  i 
)

Definition at line 125 of file bof.c.

{
       if (!bof_is_array(bof) || i >= bof->array_size)
              return NULL;
       return bof->array[i];
}

Here is the call graph for this function:

unsigned bof_array_size ( bof_t bof)

Definition at line 132 of file bof.c.

{
       if (!bof_is_array(bof))
              return 0;
       return bof->array_size;
}

Here is the call graph for this function:

bof_t* bof_blob ( unsigned  size,
void *  value 
)

Definition at line 142 of file bof.c.

{
       bof_t *blob = bof_object();

       if (blob == NULL)
              return NULL;
       blob->type = BOF_TYPE_BLOB;
       blob->value = calloc(1, size);
       if (blob->value == NULL) {
              bof_decref(blob);
              return NULL;
       }
       blob->size = size;
       memcpy(blob->value, value, size);
       blob->size += 12;
       return blob;
}

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned bof_blob_size ( bof_t bof)

Definition at line 160 of file bof.c.

{
       if (!bof_is_blob(bof))
              return 0;
       return bof->size - 12;
}

Here is the call graph for this function:

void* bof_blob_value ( bof_t bof)

Definition at line 167 of file bof.c.

{
       if (!bof_is_blob(bof))
              return NULL;
       return bof->value;
}

Here is the call graph for this function:

void bof_decref ( bof_t bof)

Definition at line 377 of file bof.c.

{
       unsigned i;

       if (bof == NULL)
              return;
       if (--bof->refcount > 0)
              return;
       for (i = 0; i < bof->array_size; i++) {
              bof_decref(bof->array[i]);
              bof->array[i] = NULL;
       }
       bof->array_size = 0;
       if (bof->file) {
              fclose(bof->file);
              bof->file = NULL;
       }
       free(bof->array);
       free(bof->value);
       free(bof);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int bof_dump_file ( bof_t bof,
const char *  filename 
)

Definition at line 439 of file bof.c.

{
       unsigned i;
       int r = 0;

       if (bof->file) {
              fclose(bof->file);
              bof->file = NULL;
       }
       bof->file = fopen(filename, "w");
       if (bof->file == NULL) {
              fprintf(stderr, "%s failed to open file %s\n", __func__, filename);
              r = -EINVAL;
              goto out_err;
       }
       r = fseek(bof->file, 0L, SEEK_SET);
       if (r) {
              fprintf(stderr, "%s failed to seek into file %s\n", __func__, filename);
              goto out_err;
       }
       r = fwrite(&bof->type, 4, 1, bof->file);
       if (r != 1)
              goto out_err;
       r = fwrite(&bof->size, 4, 1, bof->file);
       if (r != 1)
              goto out_err;
       r = fwrite(&bof->array_size, 4, 1, bof->file);
       if (r != 1)
              goto out_err;
       for (i = 0; i < bof->array_size; i++) {
              r = bof_file_write(bof->array[i], bof->file);
              if (r)
                     return r;
       }
out_err:
       fclose(bof->file);
       bof->file = NULL;
       return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int bof_file_flush ( bof_t root)
bof_t* bof_file_new ( const char *  filename)
void bof_incref ( bof_t bof)

Definition at line 372 of file bof.c.

{
       bof->refcount++;
}

Here is the caller graph for this function:

bof_t* bof_int32 ( int32_t  value)

Definition at line 198 of file bof.c.

{
       bof_t *int32 = bof_object();

       if (int32 == NULL)
              return NULL;
       int32->type = BOF_TYPE_INT32;
       int32->size = 4;
       int32->value = calloc(1, int32->size);
       if (int32->value == NULL) {
              bof_decref(int32);
              return NULL;
       }
       memcpy(int32->value, &value, 4);
       int32->size += 12;
       return int32;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t bof_int32_value ( bof_t bof)

Definition at line 216 of file bof.c.

{
       return *((uint32_t*)bof->value);
}
static int bof_is_array ( bof_t bof) [inline, static]

Definition at line 87 of file bof.h.

{return (bof->type == BOF_TYPE_ARRAY);}

Here is the caller graph for this function:

static int bof_is_blob ( bof_t bof) [inline, static]

Definition at line 84 of file bof.h.

{return (bof->type == BOF_TYPE_BLOB);}

Here is the caller graph for this function:

static int bof_is_int32 ( bof_t bof) [inline, static]

Definition at line 86 of file bof.h.

{return (bof->type == BOF_TYPE_INT32);}
static int bof_is_null ( bof_t bof) [inline, static]

Definition at line 85 of file bof.h.

{return (bof->type == BOF_TYPE_NULL);}
static int bof_is_object ( bof_t bof) [inline, static]

Definition at line 83 of file bof.h.

{return (bof->type == BOF_TYPE_OBJECT);}
static int bof_is_string ( bof_t bof) [inline, static]

Definition at line 88 of file bof.h.

{return (bof->type == BOF_TYPE_STRING);}
bof_t* bof_load_file ( const char *  filename)

Definition at line 336 of file bof.c.

{
       bof_t *root = bof_object();
       int r;

       if (root == NULL) {
              fprintf(stderr, "%s failed to create root object\n", __func__);
              return NULL;
       }
       root->file = fopen(filename, "r");
       if (root->file == NULL)
              goto out_err;
       r = fseek(root->file, 0L, SEEK_SET);
       if (r) {
              fprintf(stderr, "%s failed to seek into file %s\n", __func__, filename);
              goto out_err;
       }
       root->offset = ftell(root->file);
       r = fread(&root->type, 4, 1, root->file);
       if (r != 1)
              goto out_err;
       r = fread(&root->size, 4, 1, root->file);
       if (r != 1)
              goto out_err;
       r = fread(&root->array_size, 4, 1, root->file);
       if (r != 1)
              goto out_err;
       r = bof_read(root, root->file, root->offset + root->size, 2);
       if (r)
              goto out_err;
       return root;
out_err:
       bof_decref(root);
       return NULL;
}

Here is the call graph for this function:

bof_t* bof_object ( void  )

Definition at line 51 of file bof.c.

{
       bof_t *object;

       object = calloc(1, sizeof(bof_t));
       if (object == NULL)
              return NULL;
       object->refcount = 1;
       object->type = BOF_TYPE_OBJECT;
       object->size = 12;
       return object;
}

Here is the caller graph for this function:

int bof_object_dump ( bof_t object,
const char *  filename 
)
bof_t* bof_object_get ( bof_t object,
const char *  keyname 
)

Definition at line 64 of file bof.c.

{
       unsigned i;

       for (i = 0; i < object->array_size; i += 2) {
              if (!strcmp(object->array[i]->value, keyname)) {
                     return object->array[i + 1];
              }
       }
       return NULL;
}
int bof_object_set ( bof_t object,
const char *  keyname,
bof_t value 
)

Definition at line 76 of file bof.c.

{
       bof_t *key;
       int r;

       if (object->type != BOF_TYPE_OBJECT)
              return -EINVAL;
       r = bof_entry_grow(object);
       if (r)
              return r;
       key = bof_string(keyname);
       if (key == NULL)
              return -ENOMEM;
       object->array[object->array_size++] = key;
       object->array[object->array_size++] = value;
       object->size += value->size;
       object->size += key->size;
       bof_incref(value);
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void bof_print ( bof_t bof)

Definition at line 274 of file bof.c.

{
       bof_print_rec(bof, 0, 0);
}

Here is the call graph for this function:

bof_t* bof_string ( const char *  value)

Definition at line 177 of file bof.c.

{
       bof_t *string = bof_object();

       if (string == NULL)
              return NULL;
       string->type = BOF_TYPE_STRING;
       string->size = strlen(value) + 1;
       string->value = calloc(1, string->size);
       if (string->value == NULL) {
              bof_decref(string);
              return NULL;
       }
       strcpy(string->value, value);
       string->size += 12;
       return string;
}

Here is the call graph for this function:

Here is the caller graph for this function: