2 * "THE BEER-WARE LICENSE" (Revision 42):
3 * <tobias.rehbein@web.de> wrote this file. As long as you retain this notice
4 * you can do whatever you want with this stuff. If we meet some day, and you
5 * think this stuff is worth it, you can buy me a beer in return.
17 #include <sys/types.h>
28 plr_context_open(char const *ogg123
, char const *ogg123_options
)
30 struct plr_context
*ctx
;
33 assert(ogg123
!= NULL
);
35 if ((ctx
= malloc(sizeof(*ctx
))) == NULL
)
36 err(EX_SOFTWARE
, "could not malloc plr_ctx");
39 if ((ctx
->ogg123
= malloc(len
+ 1)) == NULL
)
40 err(EX_SOFTWARE
, "could not malloc plr_ctx->ogg123");
41 strncpy(ctx
->ogg123
, ogg123
, len
);
42 ctx
->ogg123
[len
] = '\0';
44 len
= strlen(ogg123_options
);
46 if ((ctx
->ogg123_options
= malloc(len
+ 1)) == NULL
)
47 err(EX_SOFTWARE
, "could not malloc plr_ctx->ogg123_options");
48 strncpy(ctx
->ogg123_options
, ogg123_options
, len
);
49 ctx
->ogg123_options
[len
] = '\0';
51 ctx
->ogg123_options
= NULL
;
53 ctx
->pid
= (pid_t
) - 1;
59 plr_context_close(struct plr_context
*ctx
)
69 plr_play(struct plr_context
*ctx
, char *ogg
)
78 switch (lpid
= fork()) {
80 execl(ctx
->ogg123
, ctx
->ogg123
, "-q", ogg
, ctx
->ogg123_options
, NULL
);
81 err(EX_OSERR
, "could not exec %s", ctx
->ogg123
);
83 err(EX_OSERR
, "could not fork player");
90 plr_stop(struct plr_context
*ctx
)
92 if (ctx
->pid
!= (pid_t
) (-1)) {
93 if ((kill(ctx
->pid
, SIGHUP
) == -1) && (errno
!= ESRCH
))
94 err(EX_OSERR
, "could not kill running player: %d", ctx
->pid
);