Skip to content

Commit

Permalink
Only use the music_cmd interface if we've set a command handler
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 17, 2017
1 parent bb0320d commit 769d53b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions music_cmd.c
Expand Up @@ -42,6 +42,7 @@

typedef struct {
char *file;
char *cmd;
pid_t pid;
} MusicCMD;

Expand All @@ -51,13 +52,19 @@ static void *MusicCMD_CreateFromFile(const char *file)
{
MusicCMD *music;

if (!music_cmd) {
Mix_SetError("You must call Mix_SetMusicCMD() first");
return NULL;
}

/* Allocate and fill the music structure */
music = (MusicCMD *)SDL_calloc(1, sizeof *music);
if (music == NULL) {
Mix_SetError("Out of memory");
return NULL;
}
music->file = SDL_strdup(file);
music->cmd = SDL_strdup(music_cmd);
music->pid = 0;

/* We're done */
Expand Down Expand Up @@ -145,11 +152,6 @@ static int MusicCMD_Play(void *context)
{
MusicCMD *music = (MusicCMD *)context;

if (!music_cmd) {
Mix_SetError("You must call Mix_SetMusicCMD() first");
return -1;
}

#ifdef HAVE_FORK
music->pid = fork();
#else
Expand All @@ -173,7 +175,7 @@ static int MusicCMD_Play(void *context)
}

/* Execute the command */
argv = parse_args(music_cmd, music->file);
argv = parse_args(music->cmd, music->file);
if (argv != NULL) {
execvp(argv[0], argv);

Expand Down

0 comments on commit 769d53b

Please sign in to comment.