src/SDL_error.c
changeset 10643 930938c7ca82
parent 10403 a0c76d344583
child 10644 594c17c446f6
     1.1 --- a/src/SDL_error.c	Wed Nov 23 10:51:44 2016 -0500
     1.2 +++ b/src/SDL_error.c	Wed Nov 23 11:49:26 2016 -0500
     1.3 @@ -116,8 +116,68 @@
     1.4      return -1;
     1.5  }
     1.6  
     1.7 +static char *SDL_GetErrorMsg(char *errstr, int maxlen);
     1.8 +
     1.9 +/* Available for backwards compatibility */
    1.10 +const char *
    1.11 +SDL_GetError(void)
    1.12 +{
    1.13 +    static char errmsg[SDL_ERRBUFIZE];
    1.14 +
    1.15 +    return SDL_GetErrorMsg(errmsg, SDL_ERRBUFIZE);
    1.16 +}
    1.17 +
    1.18 +void
    1.19 +SDL_ClearError(void)
    1.20 +{
    1.21 +    SDL_error *error;
    1.22 +
    1.23 +    error = SDL_GetErrBuf();
    1.24 +    error->error = 0;
    1.25 +}
    1.26 +
    1.27 +/* Very common errors go here */
    1.28 +int
    1.29 +SDL_Error(SDL_errorcode code)
    1.30 +{
    1.31 +    switch (code) {
    1.32 +    case SDL_ENOMEM:
    1.33 +        return SDL_SetError("Out of memory");
    1.34 +    case SDL_EFREAD:
    1.35 +        return SDL_SetError("Error reading from datastream");
    1.36 +    case SDL_EFWRITE:
    1.37 +        return SDL_SetError("Error writing to datastream");
    1.38 +    case SDL_EFSEEK:
    1.39 +        return SDL_SetError("Error seeking in datastream");
    1.40 +    case SDL_UNSUPPORTED:
    1.41 +        return SDL_SetError("That operation is not supported");
    1.42 +    default:
    1.43 +        return SDL_SetError("Unknown SDL error");
    1.44 +    }
    1.45 +}
    1.46 +
    1.47 +#ifdef TEST_ERROR
    1.48 +int
    1.49 +main(int argc, char *argv[])
    1.50 +{
    1.51 +    char buffer[BUFSIZ + 1];
    1.52 +
    1.53 +    SDL_SetError("Hi there!");
    1.54 +    printf("Error 1: %s\n", SDL_GetError());
    1.55 +    SDL_ClearError();
    1.56 +    SDL_memset(buffer, '1', BUFSIZ);
    1.57 +    buffer[BUFSIZ] = 0;
    1.58 +    SDL_SetError("This is the error: %s (%f)", buffer, 1.0);
    1.59 +    printf("Error 2: %s\n", SDL_GetError());
    1.60 +    exit(0);
    1.61 +}
    1.62 +#endif
    1.63 +
    1.64 +
    1.65 +/* keep this at the end of the file so it works with GCC builds that don't
    1.66 +   support "#pragma GCC diagnostic push" ... we'll just leave the warning
    1.67 +   disabled after this. */
    1.68  #ifdef __GNUC__
    1.69 -#pragma GCC diagnostic push
    1.70  #pragma GCC diagnostic ignored "-Wformat-nonliteral"
    1.71  #endif
    1.72  /* This function has a bit more overhead than most error functions
    1.73 @@ -220,63 +280,5 @@
    1.74      }
    1.75      return (errstr);
    1.76  }
    1.77 -#ifdef __GNUC__
    1.78 -#pragma GCC diagnostic pop
    1.79 -#endif
    1.80 -
    1.81 -/* Available for backwards compatibility */
    1.82 -const char *
    1.83 -SDL_GetError(void)
    1.84 -{
    1.85 -    static char errmsg[SDL_ERRBUFIZE];
    1.86 -
    1.87 -    return SDL_GetErrorMsg(errmsg, SDL_ERRBUFIZE);
    1.88 -}
    1.89 -
    1.90 -void
    1.91 -SDL_ClearError(void)
    1.92 -{
    1.93 -    SDL_error *error;
    1.94 -
    1.95 -    error = SDL_GetErrBuf();
    1.96 -    error->error = 0;
    1.97 -}
    1.98 -
    1.99 -/* Very common errors go here */
   1.100 -int
   1.101 -SDL_Error(SDL_errorcode code)
   1.102 -{
   1.103 -    switch (code) {
   1.104 -    case SDL_ENOMEM:
   1.105 -        return SDL_SetError("Out of memory");
   1.106 -    case SDL_EFREAD:
   1.107 -        return SDL_SetError("Error reading from datastream");
   1.108 -    case SDL_EFWRITE:
   1.109 -        return SDL_SetError("Error writing to datastream");
   1.110 -    case SDL_EFSEEK:
   1.111 -        return SDL_SetError("Error seeking in datastream");
   1.112 -    case SDL_UNSUPPORTED:
   1.113 -        return SDL_SetError("That operation is not supported");
   1.114 -    default:
   1.115 -        return SDL_SetError("Unknown SDL error");
   1.116 -    }
   1.117 -}
   1.118 -
   1.119 -#ifdef TEST_ERROR
   1.120 -int
   1.121 -main(int argc, char *argv[])
   1.122 -{
   1.123 -    char buffer[BUFSIZ + 1];
   1.124 -
   1.125 -    SDL_SetError("Hi there!");
   1.126 -    printf("Error 1: %s\n", SDL_GetError());
   1.127 -    SDL_ClearError();
   1.128 -    SDL_memset(buffer, '1', BUFSIZ);
   1.129 -    buffer[BUFSIZ] = 0;
   1.130 -    SDL_SetError("This is the error: %s (%f)", buffer, 1.0);
   1.131 -    printf("Error 2: %s\n", SDL_GetError());
   1.132 -    exit(0);
   1.133 -}
   1.134 -#endif
   1.135  
   1.136  /* vi: set ts=4 sw=4 expandtab: */