test/testloadso.c
changeset 7639 9406b7dd2f2d
parent 7517 965d57022c01
child 8149 681eb46b8ac4
equal deleted inserted replaced
7638:783d1cff9b20 7639:9406b7dd2f2d
    31     void *lib = NULL;
    31     void *lib = NULL;
    32     fntype fn = NULL;
    32     fntype fn = NULL;
    33 
    33 
    34     if (argc != 3) {
    34     if (argc != 3) {
    35         const char *app = argv[0];
    35         const char *app = argv[0];
    36         fprintf(stderr, "USAGE: %s <library> <functionname>\n", app);
    36         SDL_Log("USAGE: %s <library> <functionname>\n", app);
    37         fprintf(stderr, "       %s --hello <lib with puts()>\n", app);
    37         SDL_Log("       %s --hello <lib with puts()>\n", app);
    38         return 1;
    38         return 1;
    39     }
    39     }
    40 
    40 
    41     /* Initialize SDL */
    41     /* Initialize SDL */
    42     if (SDL_Init(0) < 0) {
    42     if (SDL_Init(0) < 0) {
    43         fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    43         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
    44         return 2;
    44         return 2;
    45     }
    45     }
    46 
    46 
    47     if (strcmp(argv[1], "--hello") == 0) {
    47     if (strcmp(argv[1], "--hello") == 0) {
    48         hello = 1;
    48         hello = 1;
    53         symname = argv[2];
    53         symname = argv[2];
    54     }
    54     }
    55 
    55 
    56     lib = SDL_LoadObject(libname);
    56     lib = SDL_LoadObject(libname);
    57     if (lib == NULL) {
    57     if (lib == NULL) {
    58         fprintf(stderr, "SDL_LoadObject('%s') failed: %s\n",
    58         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadObject('%s') failed: %s\n",
    59                 libname, SDL_GetError());
    59                 libname, SDL_GetError());
    60         retval = 3;
    60         retval = 3;
    61     } else {
    61     } else {
    62         fn = (fntype) SDL_LoadFunction(lib, symname);
    62         fn = (fntype) SDL_LoadFunction(lib, symname);
    63         if (fn == NULL) {
    63         if (fn == NULL) {
    64             fprintf(stderr, "SDL_LoadFunction('%s') failed: %s\n",
    64             SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadFunction('%s') failed: %s\n",
    65                     symname, SDL_GetError());
    65                     symname, SDL_GetError());
    66             retval = 4;
    66             retval = 4;
    67         } else {
    67         } else {
    68             printf("Found %s in %s at %p\n", symname, libname, fn);
    68             SDL_Log("Found %s in %s at %p\n", symname, libname, fn);
    69             if (hello) {
    69             if (hello) {
    70                 printf("Calling function...\n");
    70                 SDL_Log("Calling function...\n");
    71                 fflush(stdout);
    71                 fflush(stdout);
    72                 fn("     HELLO, WORLD!\n");
    72                 fn("     HELLO, WORLD!\n");
    73                 printf("...apparently, we survived.  :)\n");
    73                 SDL_Log("...apparently, we survived.  :)\n");
    74                 printf("Unloading library...\n");
    74                 SDL_Log("Unloading library...\n");
    75                 fflush(stdout);
    75                 fflush(stdout);
    76             }
    76             }
    77         }
    77         }
    78         SDL_UnloadObject(lib);
    78         SDL_UnloadObject(lib);
    79     }
    79     }