File: test_buf.c

package info (click to toggle)
libg3d 0.0.8-26
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,700 kB
  • sloc: ansic: 27,295; sh: 9,288; xml: 4,123; makefile: 865; cpp: 13
file content (59 lines) | stat: -rw-r--r-- 1,774 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* $Id:$ */

/*
    libg3d - 3D object loading library

    Copyright (C) 2005-2009  Markus Dahms <mad@automagically.de>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <stdio.h>
#include <glib.h>
#include <g3d/g3d.h>
#include <g3d/stream.h>

static guint8 test_buffer[] = {
	0x01, 0x23, 0x45, 0x67, /* 0x01234567 MSB */
	0x67, 0x45, 0x23, 0x01, /* 0x01234567 LSB */
	0x00
};
static gsize tbsize = sizeof(test_buffer);

int main(int argc, char *argv[])
{
	G3DStream *stream;
	guint32 u;

	stream = g3d_stream_from_buffer(test_buffer, tbsize, "testbuf", FALSE);

	/* read 2 x 32-bit integer */
	u = g3d_stream_read_int32_be(stream);
	g_print("MSB value: 0x%08x\n", u);
	u = g3d_stream_read_int32_le(stream);
	g_print("LSB value: 0x%08x\n", u);
	/* seek back 4 bytes */
	g3d_stream_seek(stream, -4, G_SEEK_CUR);
	u = g3d_stream_read_int32_le(stream);
	g_print("LSB value: 0x%08x\n", u);
	/* rewind stream */
	g3d_stream_seek(stream, 0, G_SEEK_SET);
	u = g3d_stream_read_int32_be(stream);
	g_print("MSB value: 0x%08x\n", u);

	g3d_stream_close(stream);

	return 0;
}