This is an example of record locking and unlocking.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
static char *btrieveFileName = (char *)"squaresAndSquareRoots.btr";
#define MIN_X 0
#define MAX_X 255
#pragma pack(1)
typedef struct {
uint8_t x;
uint16_t xSquared;
double xSquareRoot;
} record_t;
#pragma pack()
{
{
goto leave;
}
{
goto leave;
}
leave:
return status;
}
{
{
goto leave;
}
leave:
return status;
}
{
int i;
record_t record;
for (i = MIN_X; i <= MAX_X; i++)
{
record.x = (uint8_t)i;
record.xSquared = (uint16_t)(i * i);
record.xSquareRoot = sqrt((double)i);
{
goto leave;
}
}
leave:
return status;
}
{
{
goto leave;
}
leave:
return status;
}
{
{
goto leave;
}
leave:
return status;
}
{
{
goto leave;
}
{
goto leave;
}
{
goto leave;
}
leave:
return status;
}
updateRecord(bool expectRecordInUse)
{
record_t record;
{
goto leave;
}
{
goto leave;
}
record.xSquared++;
record.xSquareRoot++;
status = btrieveFile.
RecordUpdate((
char *)&record,
sizeof(record));
{
goto leave;
}
else
{
goto leave;
}
{
goto leave;
}
leave:
return status;
}
{
record_t record;
{
goto leave;
}
printf("record before update: (%u, %u, %f)\n", record.x, record.xSquared, record.xSquareRoot);
{
goto leave;
}
{
goto leave;
}
{
goto leave;
}
printf("record after update while locked: (%u, %u, %f)\n", record.x, record.xSquared, record.xSquareRoot);
{
goto leave;
}
{
goto leave;
}
printf("record after update while unlocked: (%u, %u, %f)\n", record.x, record.xSquared, record.xSquareRoot);
leave:
return status;
}
int
main(int argc, char *argv[])
{
static const char *usage = "Usage: %s\n";
if (argc != 1)
{
printf(usage, argv[0]);
goto leave;
}
{
goto leave;
}
{
goto leave;
}
{
goto leave;
}
{
goto leave;
}
{
goto leave;
}
{
goto leave;
}
{
goto leave;
}
leave:
return 0;
return 1;
}