本文整理汇总了C++中SDL_Error函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_Error函数的具体用法?C++ SDL_Error怎么用?C++ SDL_Error使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: win32_file_write
static int SDLCALL win32_file_write(SDL_RWops *context, const void *ptr, int size, int num)
{
int total_bytes;
DWORD byte_written,nwritten;
total_bytes = size*num;
if (!context || context->hidden.win32io.h==INVALID_HANDLE_VALUE || total_bytes<=0 || !size)
return 0;
if (context->hidden.win32io.buffer.left) {
SetFilePointer(context->hidden.win32io.h,-context->hidden.win32io.buffer.left,NULL,FILE_CURRENT);
context->hidden.win32io.buffer.left = 0;
}
/* if in append mode, we must go to the EOF before write */
if (context->hidden.win32io.append) {
if ( SetFilePointer(context->hidden.win32io.h,0L,NULL,FILE_END) == INVALID_SET_FILE_POINTER ) {
SDL_Error(SDL_EFWRITE);
return 0;
}
}
if (!WriteFile(context->hidden.win32io.h,ptr,total_bytes,&byte_written,NULL)) {
SDL_Error(SDL_EFWRITE);
return 0;
}
nwritten = byte_written/size;
return nwritten;
}
示例2: win32_file_read
static size_t SDLCALL
win32_file_read(SDL_RWops * context, void *ptr, size_t size, size_t maxnum)
{
size_t total_need;
size_t total_read = 0;
size_t read_ahead;
DWORD byte_read;
total_need = size * maxnum;
if (!context || context->hidden.win32io.h == INVALID_HANDLE_VALUE
|| !total_need)
return 0;
if (context->hidden.win32io.buffer.left > 0) {
void *data = (char *) context->hidden.win32io.buffer.data +
context->hidden.win32io.buffer.size -
context->hidden.win32io.buffer.left;
read_ahead =
SDL_min(total_need, context->hidden.win32io.buffer.left);
SDL_memcpy(ptr, data, read_ahead);
context->hidden.win32io.buffer.left -= read_ahead;
if (read_ahead == total_need) {
return maxnum;
}
ptr = (char *) ptr + read_ahead;
total_need -= read_ahead;
total_read += read_ahead;
}
if (total_need < READAHEAD_BUFFER_SIZE) {
if (!ReadFile
(context->hidden.win32io.h, context->hidden.win32io.buffer.data,
READAHEAD_BUFFER_SIZE, &byte_read, NULL)) {
SDL_Error(SDL_EFREAD);
return 0;
}
read_ahead = SDL_min(total_need, (int) byte_read);
SDL_memcpy(ptr, context->hidden.win32io.buffer.data, read_ahead);
context->hidden.win32io.buffer.size = byte_read;
context->hidden.win32io.buffer.left = byte_read - read_ahead;
total_read += read_ahead;
} else {
if (!ReadFile
(context->hidden.win32io.h, ptr, (DWORD)total_need, &byte_read, NULL)) {
SDL_Error(SDL_EFREAD);
return 0;
}
total_read += byte_read;
}
return (total_read / size);
}
示例3: rfork_seek
static int rfork_seek(SDL_RWops *context, int offset, int whence)
{
rfork_data *d = (rfork_data *)context->hidden.unknown.data1;
off_t newpos;
switch (whence) {
case SEEK_SET:
newpos = offset;
break;
case SEEK_CUR:
newpos = d->current + offset;
break;
case SEEK_END:
newpos = d->size + offset;
break;
default:
SDL_SetError("Unknown value for 'whence'");
return -1;
}
if (newpos < 0 || newpos > d->size) {
SDL_Error(SDL_EFSEEK);
return -1;
}
d->current = newpos;
return newpos;
}
示例4: ReadChunk
static int ReadChunk(SDL_RWops *src, Chunk *chunk)
{
chunk->magic = SDL_ReadLE32(src);
chunk->length = SDL_ReadLE32(src);
chunk->data = (Uint8 *)malloc(chunk->length);
if ( chunk->data == NULL ) {
SDL_Error(SDL_ENOMEM);
return(-1);
}
if ( SDL_RWread(src, chunk->data, chunk->length, 1) != 1 ) {
SDL_Error(SDL_EFREAD);
free(chunk->data);
return(-1);
}
return(chunk->length);
}
示例5: SDLTest_GenerateExecKey
/**
* Generates an execution key for the fuzzer.
*
* \param runSeed The run seed to use
* \param suiteName The name of the test suite
* \param testName The name of the test
* \param iteration The iteration count
*
* \returns The generated execution key to initialize the fuzzer with.
*
*/
static Uint64
SDLTest_GenerateExecKey(const char *runSeed, char *suiteName, char *testName, int iteration)
{
SDLTest_Md5Context md5Context;
Uint64 *keys;
char iterationString[16];
Uint32 runSeedLength;
Uint32 suiteNameLength;
Uint32 testNameLength;
Uint32 iterationStringLength;
Uint32 entireStringLength;
char *buffer;
if (runSeed == NULL || runSeed[0] == '\0') {
SDLTest_LogError("Invalid runSeed string.");
return -1;
}
if (suiteName == NULL || suiteName[0] == '\0') {
SDLTest_LogError("Invalid suiteName string.");
return -1;
}
if (testName == NULL || testName[0] == '\0') {
SDLTest_LogError("Invalid testName string.");
return -1;
}
if (iteration <= 0) {
SDLTest_LogError("Invalid iteration count.");
return -1;
}
/* Convert iteration number into a string */
SDL_memset(iterationString, 0, sizeof(iterationString));
SDL_snprintf(iterationString, sizeof(iterationString) - 1, "%d", iteration);
/* Combine the parameters into single string */
runSeedLength = SDL_strlen(runSeed);
suiteNameLength = SDL_strlen(suiteName);
testNameLength = SDL_strlen(testName);
iterationStringLength = SDL_strlen(iterationString);
entireStringLength = runSeedLength + suiteNameLength + testNameLength + iterationStringLength + 1;
buffer = (char *)SDL_malloc(entireStringLength);
if (buffer == NULL) {
SDLTest_LogError("Failed to allocate buffer for execKey generation.");
SDL_Error(SDL_ENOMEM);
return 0;
}
SDL_snprintf(buffer, entireStringLength, "%s%s%s%d", runSeed, suiteName, testName, iteration);
/* Hash string and use half of the digest as 64bit exec key */
SDLTest_Md5Init(&md5Context);
SDLTest_Md5Update(&md5Context, (unsigned char *)buffer, entireStringLength);
SDLTest_Md5Final(&md5Context);
SDL_free(buffer);
keys = (Uint64 *)md5Context.digest;
return keys[0];
}
示例6: dc_seek
static int SDLCALL dc_seek(SDL_RWops *context, int offset, int whence)
{
off_t pos;
int dc_whence;
switch (whence) {
case RW_SEEK_SET:
dc_whence = SEEK_SET;
break;
case RW_SEEK_CUR:
dc_whence = SEEK_CUR;
break;
case RW_SEEK_END:
dc_whence = SEEK_END;
break;
default:
SDL_SetError("dc_seek: Unknown value for 'whence'");
return -1;
}
pos = fs_seek(context->hidden.dc.fd, offset, dc_whence);
if ( pos < 0 ) {
SDL_Error(SDL_EFSEEK);
return(-1);
}
return pos;
}
示例7: SDLTest_GenerateRunSeed
/**
* Generates a random run seed string for the harness. The generated seed
* will contain alphanumeric characters (0-9A-Z).
*
* Note: The returned string needs to be deallocated by the caller.
*
* \param length The length of the seed string to generate
*
* \returns The generated seed string
*/
char *
SDLTest_GenerateRunSeed(const int length)
{
char *seed = NULL;
SDLTest_RandomContext randomContext;
int counter;
/* Sanity check input */
if (length <= 0) {
SDLTest_LogError("The length of the harness seed must be >0.");
return NULL;
}
/* Allocate output buffer */
seed = (char *)SDL_malloc((length + 1) * sizeof(char));
if (seed == NULL) {
SDLTest_LogError("SDL_malloc for run seed output buffer failed.");
SDL_Error(SDL_ENOMEM);
return NULL;
}
/* Generate a random string of alphanumeric characters */
SDLTest_RandomInitTime(&randomContext);
for (counter = 0; counter < length; counter++) {
unsigned int number = SDLTest_Random(&randomContext);
char ch = (char) (number % (91 - 48)) + 48;
if (ch >= 58 && ch <= 64) {
ch = 65;
}
seed[counter] = ch;
}
seed[length] = '\0';
return seed;
}
示例8: zlib_file_seek
static int64_t zlib_file_seek(SDL_RWops* const context, int64_t offset, int whence) {
auto const fp = reinterpret_cast<gzFile>(context->hidden.unknown.data1);
const auto pos = gzseek(fp, offset, whence);
if (pos == -1)
return SDL_Error(SDL_EFSEEK);
return pos;
}
示例9: stdio_seek
static int SDLCALL stdio_seek(SDL_RWops *context, int offset, int whence)
{
if ( fseek(context->hidden.stdio.fp, offset, whence) == 0 ) {
return(ftell(context->hidden.stdio.fp));
} else {
SDL_Error(SDL_EFSEEK);
return(-1);
}
}
示例10: Android_JNI_FileSeek
extern "C" Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence)
{
Sint64 newPosition;
switch (whence) {
case RW_SEEK_SET:
newPosition = offset;
break;
case RW_SEEK_CUR:
newPosition = ctx->hidden.androidio.position + offset;
break;
case RW_SEEK_END:
newPosition = ctx->hidden.androidio.size + offset;
break;
default:
SDL_SetError("Unknown value for 'whence'");
return -1;
}
/* Validate the new position */
if (newPosition < 0) {
SDL_Error(SDL_EFSEEK);
return -1;
}
if (newPosition > ctx->hidden.androidio.size) {
newPosition = ctx->hidden.androidio.size;
}
Sint64 movement = newPosition - ctx->hidden.androidio.position;
if (movement > 0) {
unsigned char buffer[4096];
// The easy case where we're seeking forwards
while (movement > 0) {
Sint64 amount = sizeof (buffer);
if (amount > movement) {
amount = movement;
}
size_t result = Android_JNI_FileRead(ctx, buffer, 1, amount);
if (result <= 0) {
// Failed to read/skip the required amount, so fail
return -1;
}
movement -= result;
}
} else if (movement < 0) {
// We can't seek backwards so we have to reopen the file and seek
// forwards which obviously isn't very efficient
Android_JNI_FileClose(ctx, false);
Android_JNI_FileOpen(ctx);
Android_JNI_FileSeek(ctx, newPosition, RW_SEEK_SET);
}
return ctx->hidden.androidio.position;
}
示例11: stdio_read
static int SDLCALL stdio_read(SDL_RWops *context, void *ptr, int size, int maxnum)
{
size_t nread;
nread = fread(ptr, size, maxnum, context->hidden.stdio.fp);
if ( nread == 0 && ferror(context->hidden.stdio.fp) ) {
SDL_Error(SDL_EFREAD);
}
return(nread);
}
示例12: dc_read
static int SDLCALL dc_read(SDL_RWops *context, void *ptr, int size, int maxnum)
{
size_t nread = fs_read(context->hidden.dc.fd, ptr, size * maxnum);
if ( nread < 0 ) {
SDL_Error(SDL_EFREAD);
return -1;
}
return (nread / size);
}
示例13: stdio_write
static int SDLCALL stdio_write(SDL_RWops *context, const void *ptr, int size, int num)
{
size_t nwrote;
nwrote = fwrite(ptr, size, num, context->hidden.stdio.fp);
if ( nwrote == 0 && ferror(context->hidden.stdio.fp) ) {
SDL_Error(SDL_EFWRITE);
}
return(nwrote);
}
示例14: zlib_file_close
static int zlib_file_close(SDL_RWops * context) {
int status = 0;
if (context) {
auto const fp = reinterpret_cast<gzFile>(context->hidden.unknown.data1);
if (gzclose(fp) != 0) {
status = SDL_Error(SDL_EFWRITE);
}
}
return status;
}
示例15: zlib_file_read
static size_t zlib_file_read(SDL_RWops* const context, void *ptr, size_t size, size_t maxnum) {
auto const fp = reinterpret_cast<gzFile>(context->hidden.unknown.data1);
const size_t nread = gzread(fp, ptr, size * maxnum);
int error;
gzerror(fp, &error);
if (nread == 0 && error) {
SDL_Error(SDL_EFREAD);
}
return nread;
}