include/SDL_error.h
author Ryan C. Gordon <icculus@icculus.org>
Thu, 28 May 2015 01:54:52 -0400
changeset 9671 0e1f57b051f4
parent 9619 b94b6d0bff0f
child 9998 f67cf37e9cd4
permissions -rw-r--r--
Windows GetBasePath should use GetModuleFileNameExW() and check for overflows.

Apparently you might get strange paths from GetModuleFileName(), such as
short path names or UNC filenames, so this avoids that problem. Since you have
to tapdance with linking different libraries and defining macros depending on
what Windows you plan to target, we dynamically load the API we need, which
works on all versions of Windows (on Win7, it'll load a compatibility wrapper
for the newer API location).

What a mess.

This also now does the right thing if there isn't enough space to store the
path, looping with a larger allocated buffer each try.

Fixes Bugzilla #2435.
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@9619
     3
  Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
slouken@0
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@0
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@0
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@0
    20
*/
slouken@0
    21
slouken@1895
    22
/**
slouken@3407
    23
 *  \file SDL_error.h
slouken@7191
    24
 *
slouken@3407
    25
 *  Simple error message routines for SDL.
slouken@1895
    26
 */
slouken@0
    27
slouken@0
    28
#ifndef _SDL_error_h
slouken@0
    29
#define _SDL_error_h
slouken@0
    30
slouken@1356
    31
#include "SDL_stdinc.h"
slouken@1356
    32
slouken@0
    33
#include "begin_code.h"
slouken@0
    34
/* Set up for C function definitions, even when using C++ */
slouken@0
    35
#ifdef __cplusplus
slouken@0
    36
extern "C" {
slouken@0
    37
#endif
slouken@0
    38
slouken@0
    39
/* Public functions */
icculus@7037
    40
/* SDL_SetError() unconditionally returns -1. */
slouken@8820
    41
extern DECLSPEC int SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1);
slouken@4867
    42
extern DECLSPEC const char *SDLCALL SDL_GetError(void);
slouken@337
    43
extern DECLSPEC void SDLCALL SDL_ClearError(void);
slouken@0
    44
slouken@3407
    45
/**
slouken@3407
    46
 *  \name Internal error functions
slouken@7191
    47
 *
slouken@7191
    48
 *  \internal
slouken@5221
    49
 *  Private error reporting function - used internally.
slouken@3407
    50
 */
gabomdq@7678
    51
/* @{ */
slouken@7191
    52
#define SDL_OutOfMemory()   SDL_Error(SDL_ENOMEM)
slouken@7191
    53
#define SDL_Unsupported()   SDL_Error(SDL_UNSUPPORTED)
slouken@7191
    54
#define SDL_InvalidParamError(param)    SDL_SetError("Parameter '%s' is invalid", (param))
slouken@1895
    55
typedef enum
slouken@1895
    56
{
slouken@1895
    57
    SDL_ENOMEM,
slouken@1895
    58
    SDL_EFREAD,
slouken@1895
    59
    SDL_EFWRITE,
slouken@1895
    60
    SDL_EFSEEK,
slouken@1895
    61
    SDL_UNSUPPORTED,
slouken@1895
    62
    SDL_LASTERROR
slouken@0
    63
} SDL_errorcode;
icculus@7037
    64
/* SDL_Error() unconditionally returns -1. */
icculus@7037
    65
extern DECLSPEC int SDLCALL SDL_Error(SDL_errorcode code);
gabomdq@7678
    66
/* @} *//* Internal error functions */
slouken@0
    67
slouken@0
    68
/* Ends C function definitions when using C++ */
slouken@0
    69
#ifdef __cplusplus
slouken@0
    70
}
slouken@0
    71
#endif
slouken@0
    72
#include "close_code.h"
slouken@0
    73
slouken@0
    74
#endif /* _SDL_error_h */
slouken@1895
    75
slouken@1895
    76
/* vi: set ts=4 sw=4 expandtab: */