SDL  2.0
SDL_test_crc32.h File Reference
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_test_crc32.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDLTest_Crc32Context
 

Macros

#define CrcUint32   unsigned int
 
#define CrcUint8   unsigned char
 
#define CRC32_POLY   0xEDB88320 /* Perl String::CRC32 compatible */
 

Functions

int SDLTest_Crc32Init (SDLTest_Crc32Context *crcContext)
 Initialize the CRC context. More...
 
int SDLTest_Crc32Calc (SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32)
 calculate a crc32 from a data block More...
 
int SDLTest_Crc32CalcStart (SDLTest_Crc32Context *crcContext, CrcUint32 *crc32)
 
int SDLTest_Crc32CalcEnd (SDLTest_Crc32Context *crcContext, CrcUint32 *crc32)
 
int SDLTest_Crc32CalcBuffer (SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32)
 
int SDLTest_Crc32Done (SDLTest_Crc32Context *crcContext)
 clean up CRC context More...
 

Detailed Description

Include file for SDL test framework.

This code is a part of the SDL2_test library, not the main SDL library.

Definition in file SDL_test_crc32.h.

Macro Definition Documentation

◆ CRC32_POLY

#define CRC32_POLY   0xEDB88320 /* Perl String::CRC32 compatible */

Definition at line 60 of file SDL_test_crc32.h.

Referenced by SDLTest_Crc32Init().

◆ CrcUint32

#define CrcUint32   unsigned int

◆ CrcUint8

#define CrcUint8   unsigned char

Definition at line 54 of file SDL_test_crc32.h.

Referenced by get_allocation_bucket(), and SDLTest_Crc32CalcBuffer().

Function Documentation

◆ SDLTest_Crc32Calc()

int SDLTest_Crc32Calc ( SDLTest_Crc32Context crcContext,
CrcUint8 inBuf,
CrcUint32  inLen,
CrcUint32 crc32 
)

calculate a crc32 from a data block

Parameters
crcContextpointer to context variable
inBufinput buffer to checksum
inLenlength of input buffer
crc32pointer to Uint32 to store the final CRC into
Returns
0 for OK, -1 on error

Definition at line 72 of file SDL_test_crc32.c.

References SDLTest_Crc32CalcBuffer(), SDLTest_Crc32CalcEnd(), and SDLTest_Crc32CalcStart().

Referenced by get_allocation_bucket().

73 {
74  if (SDLTest_Crc32CalcStart(crcContext,crc32)) {
75  return -1;
76  }
77 
78  if (SDLTest_Crc32CalcBuffer(crcContext, inBuf, inLen, crc32)) {
79  return -1;
80  }
81 
82  if (SDLTest_Crc32CalcEnd(crcContext, crc32)) {
83  return -1;
84  }
85 
86  return 0;
87 }
int SDLTest_Crc32CalcEnd(SDLTest_Crc32Context *crcContext, CrcUint32 *crc32)
int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32)
int SDLTest_Crc32CalcStart(SDLTest_Crc32Context *crcContext, CrcUint32 *crc32)

◆ SDLTest_Crc32CalcBuffer()

int SDLTest_Crc32CalcBuffer ( SDLTest_Crc32Context crcContext,
CrcUint8 inBuf,
CrcUint32  inLen,
CrcUint32 crc32 
)

Definition at line 127 of file SDL_test_crc32.c.

References SDLTest_Crc32Context::crc32_table, CrcUint32, CrcUint8, and NULL.

Referenced by SDLTest_Crc32Calc().

128 {
129  CrcUint8 *p;
130  register CrcUint32 crc;
131 
132  if (crcContext==NULL) {
133  *crc32=0;
134  return -1;
135  }
136 
137  if (inBuf==NULL) {
138  return -1;
139  }
140 
141  /*
142  * Calculate CRC from data
143  */
144  crc = *crc32;
145  for (p = inBuf; inLen > 0; ++p, --inLen) {
146 #ifdef ORIGINAL_METHOD
147  crc = (crc << 8) ^ crcContext->crc32_table[(crc >> 24) ^ *p];
148 #else
149  crc = ((crc >> 8) & 0x00FFFFFF) ^ crcContext->crc32_table[ (crc ^ *p) & 0xFF ];
150 #endif
151  }
152  *crc32 = crc;
153 
154  return 0;
155 }
GLfloat GLfloat p
CrcUint32 crc32_table[256]
#define NULL
Definition: begin_code.h:164
#define CrcUint32
#define CrcUint8

◆ SDLTest_Crc32CalcEnd()

int SDLTest_Crc32CalcEnd ( SDLTest_Crc32Context crcContext,
CrcUint32 crc32 
)

Definition at line 109 of file SDL_test_crc32.c.

References NULL.

Referenced by SDLTest_Crc32Calc().

110 {
111  /* Sanity check pointers */
112  if (crcContext==NULL) {
113  *crc32=0;
114  return -1;
115  }
116 
117  /*
118  * Return complement, per CRC-32 spec
119  */
120  *crc32 = (~(*crc32));
121 
122  return 0;
123 }
#define NULL
Definition: begin_code.h:164

◆ SDLTest_Crc32CalcStart()

int SDLTest_Crc32CalcStart ( SDLTest_Crc32Context crcContext,
CrcUint32 crc32 
)

Definition at line 91 of file SDL_test_crc32.c.

References NULL.

Referenced by SDLTest_Crc32Calc().

92 {
93  /* Sanity check pointers */
94  if (crcContext==NULL) {
95  *crc32=0;
96  return -1;
97  }
98 
99  /*
100  * Preload shift register, per CRC-32 spec
101  */
102  *crc32 = 0xffffffff;
103 
104  return 0;
105 }
#define NULL
Definition: begin_code.h:164

◆ SDLTest_Crc32Done()

int SDLTest_Crc32Done ( SDLTest_Crc32Context crcContext)

clean up CRC context

Parameters
crcContextpointer to context variable
Returns
0 for OK, -1 on error

Definition at line 157 of file SDL_test_crc32.c.

References NULL.

158 {
159  if (crcContext==NULL) {
160  return -1;
161  }
162 
163  return 0;
164 }
#define NULL
Definition: begin_code.h:164

◆ SDLTest_Crc32Init()

int SDLTest_Crc32Init ( SDLTest_Crc32Context crcContext)

Initialize the CRC context.

Note: The function initializes the crc table required for all crc calculations.

Parameters
crcContextpointer to context variable
Returns
0 for OK, -1 on error

Definition at line 34 of file SDL_test_crc32.c.

References CRC32_POLY, SDLTest_Crc32Context::crc32_table, CrcUint32, i, j, and NULL.

Referenced by SDLTest_TrackAllocations().

35 {
36  int i,j;
37  CrcUint32 c;
38 
39  /* Sanity check context pointer */
40  if (crcContext==NULL) {
41  return -1;
42  }
43 
44  /*
45  * Build auxiliary table for parallel byte-at-a-time CRC-32
46  */
47 #ifdef ORIGINAL_METHOD
48  for (i = 0; i < 256; ++i) {
49  for (c = i << 24, j = 8; j > 0; --j) {
50  c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1);
51  }
52  crcContext->crc32_table[i] = c;
53  }
54 #else
55  for (i=0; i<256; i++) {
56  c = i;
57  for (j=8; j>0; j--) {
58  if (c & 1) {
59  c = (c >> 1) ^ CRC32_POLY;
60  } else {
61  c >>= 1;
62  }
63  }
64  crcContext->crc32_table[i] = c;
65  }
66 #endif
67 
68  return 0;
69 }
#define CRC32_POLY
CrcUint32 crc32_table[256]
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
Definition: SDL_x11sym.h:50
const GLubyte * c
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:164
#define CrcUint32