Back to index

lightdm  1.3.2
Functions
x-common.c File Reference
#include <string.h>
#include "x-common.h"

Go to the source code of this file.

Functions

gsize pad (gsize length)
void read_padding (gsize length, gsize *offset)
guint8 read_card8 (const guint8 *buffer, gsize buffer_length, gsize *offset)
guint16 read_card16 (const guint8 *buffer, gsize buffer_length, guint8 byte_order, gsize *offset)
guint32 read_card32 (const guint8 *buffer, gsize buffer_length, guint8 byte_order, gsize *offset)
guint8 * read_string8 (const guint8 *buffer, gsize buffer_length, gsize string_length, gsize *offset)
gchar * read_string (const guint8 *buffer, gsize buffer_length, gsize string_length, gsize *offset)
gchar * read_padded_string (const guint8 *buffer, gsize buffer_length, gsize string_length, gsize *offset)
void write_card8 (guint8 *buffer, gsize buffer_length, guint8 value, gsize *offset)
void write_padding (guint8 *buffer, gsize buffer_length, gsize length, gsize *offset)
void write_card16 (guint8 *buffer, gsize buffer_length, guint8 byte_order, guint16 value, gsize *offset)
void write_card32 (guint8 *buffer, gsize buffer_length, guint8 byte_order, guint32 value, gsize *offset)
void write_string8 (guint8 *buffer, gsize buffer_length, const guint8 *value, gsize value_length, gsize *offset)
gsize padded_string_length (const gchar *value)
void write_string (guint8 *buffer, gsize buffer_length, const gchar *value, gsize *offset)
void write_padded_string (guint8 *buffer, gsize buffer_length, const gchar *value, gsize *offset)

Function Documentation

gsize pad ( gsize  length)

Definition at line 6 of file x-common.c.

{
    if (length % 4 == 0)
        return 0;
    return 4 - length % 4;
}

Here is the caller graph for this function:

gsize padded_string_length ( const gchar *  value)

Definition at line 144 of file x-common.c.

{
    return (strlen (value) + pad (strlen (value))) / 4;
}

Here is the call graph for this function:

guint16 read_card16 ( const guint8 *  buffer,
gsize  buffer_length,
guint8  byte_order,
gsize *  offset 
)

Definition at line 29 of file x-common.c.

{
    guint8 a, b;

    a = read_card8 (buffer, buffer_length, offset);
    b = read_card8 (buffer, buffer_length, offset);
    if (byte_order == X_BYTE_ORDER_MSB)
        return a << 8 | b;
    else
        return b << 8 | a;
}

Here is the call graph for this function:

guint32 read_card32 ( const guint8 *  buffer,
gsize  buffer_length,
guint8  byte_order,
gsize *  offset 
)

Definition at line 42 of file x-common.c.

{
    guint8 a, b, c, d;

    a = read_card8 (buffer, buffer_length, offset);
    b = read_card8 (buffer, buffer_length, offset);
    c = read_card8 (buffer, buffer_length, offset);
    d = read_card8 (buffer, buffer_length, offset);
    if (byte_order == X_BYTE_ORDER_MSB)
        return a << 24 | b << 16 | c << 8 | d;
    else
        return d << 24 | c << 16 | b << 8 | a;
}

Here is the call graph for this function:

guint8 read_card8 ( const guint8 *  buffer,
gsize  buffer_length,
gsize *  offset 
)

Definition at line 20 of file x-common.c.

{
    if (*offset >= buffer_length)
        return 0;
    (*offset)++;
    return buffer[*offset - 1];
}
gchar* read_padded_string ( const guint8 *  buffer,
gsize  buffer_length,
gsize  string_length,
gsize *  offset 
)

Definition at line 76 of file x-common.c.

{
    guint8 *value;
    value = read_string8 (buffer, buffer_length, string_length, offset);
    read_padding (pad (string_length), offset);
    return (gchar *) value;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void read_padding ( gsize  length,
gsize *  offset 
)

Definition at line 14 of file x-common.c.

{
    *offset += length;
}

Here is the caller graph for this function:

gchar* read_string ( const guint8 *  buffer,
gsize  buffer_length,
gsize  string_length,
gsize *  offset 
)

Definition at line 70 of file x-common.c.

{
    return (gchar *) read_string8 (buffer, buffer_length, string_length, offset);
}

Here is the call graph for this function:

guint8* read_string8 ( const guint8 *  buffer,
gsize  buffer_length,
gsize  string_length,
gsize *  offset 
)

Definition at line 57 of file x-common.c.

{
    guint8 *string;
    int i;

    string = g_malloc (string_length + 1);
    for (i = 0; i < string_length; i++)
        string[i] = read_card8 (buffer, buffer_length, offset);
    string[i] = '\0';
    return string;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void write_card16 ( guint8 *  buffer,
gsize  buffer_length,
guint8  byte_order,
guint16  value,
gsize *  offset 
)

Definition at line 102 of file x-common.c.

{
    if (byte_order == X_BYTE_ORDER_MSB)
    {
        write_card8 (buffer, buffer_length, value >> 8, offset);
        write_card8 (buffer, buffer_length, value & 0xFF, offset);
    }
    else
    {
        write_card8 (buffer, buffer_length, value & 0xFF, offset);
        write_card8 (buffer, buffer_length, value >> 8, offset);
    }
}

Here is the call graph for this function:

void write_card32 ( guint8 *  buffer,
gsize  buffer_length,
guint8  byte_order,
guint32  value,
gsize *  offset 
)

Definition at line 117 of file x-common.c.

{
    if (byte_order == X_BYTE_ORDER_MSB)
    {
        write_card8 (buffer, buffer_length, value >> 24, offset);
        write_card8 (buffer, buffer_length, (value >> 16) & 0xFF, offset);
        write_card8 (buffer, buffer_length, (value >> 8) & 0xFF, offset);
        write_card8 (buffer, buffer_length, value & 0xFF, offset);
    }
    else
    {
        write_card8 (buffer, buffer_length, value & 0xFF, offset);
        write_card8 (buffer, buffer_length, (value >> 8) & 0xFF, offset);
        write_card8 (buffer, buffer_length, (value >> 16) & 0xFF, offset);
        write_card8 (buffer, buffer_length, value >> 24, offset);
    }
}

Here is the call graph for this function:

void write_card8 ( guint8 *  buffer,
gsize  buffer_length,
guint8  value,
gsize *  offset 
)

Definition at line 85 of file x-common.c.

{
    if (*offset >= buffer_length)
        return;
    buffer[*offset] = value;
    (*offset)++;
}
void write_padded_string ( guint8 *  buffer,
gsize  buffer_length,
const gchar *  value,
gsize *  offset 
)

Definition at line 156 of file x-common.c.

{
    write_string8 (buffer, buffer_length, (guint8 *) value, strlen (value), offset);
    write_padding (buffer, buffer_length, pad (strlen (value)), offset);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void write_padding ( guint8 *  buffer,
gsize  buffer_length,
gsize  length,
gsize *  offset 
)

Definition at line 94 of file x-common.c.

{
    gsize i;
    for (i = 0; i < length; i++)
        write_card8 (buffer, buffer_length, 0, offset);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void write_string ( guint8 *  buffer,
gsize  buffer_length,
const gchar *  value,
gsize *  offset 
)

Definition at line 150 of file x-common.c.

{
    write_string8 (buffer, buffer_length, (guint8 *) value, strlen (value), offset);
}

Here is the call graph for this function:

void write_string8 ( guint8 *  buffer,
gsize  buffer_length,
const guint8 *  value,
gsize  value_length,
gsize *  offset 
)

Definition at line 136 of file x-common.c.

{
    gsize i;
    for (i = 0; i < value_length; i++)
        write_card8 (buffer, buffer_length, value[i], offset);
}

Here is the call graph for this function:

Here is the caller graph for this function: