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.
16 #include <sys/types.h>
26 plr_context_open(char const *ogg123
)
28 struct plr_context
*ctx
;
31 assert(ogg123
!= NULL
);
33 if ((ctx
= malloc(sizeof(*ctx
))) == NULL
)
34 err(EX_SOFTWARE
, "could not malloc plr_ctx");
36 ogg123len
= strlen(ogg123
);
37 if ((ctx
->ogg123
= malloc(ogg123len
+ 1)) == NULL
)
38 err(EX_SOFTWARE
, "could not malloc plr_ctx->ogg123");
39 strncpy(ctx
->ogg123
, ogg123
, ogg123len
);
40 ctx
->ogg123
[ogg123len
] = '\0';
42 ctx
->pid
= (pid_t
) - 1;
48 plr_context_close(struct plr_context
*ctx
)
58 plr_play(struct plr_context
*ctx
, char *ogg
)
67 switch (lpid
= fork()) {
69 execl(ctx
->ogg123
, ctx
->ogg123
, "-q", ogg
, NULL
);
70 err(EX_OSERR
, "could not exec %s", ctx
->ogg123
);
72 err(EX_OSERR
, "could not fork player");
79 plr_stop(struct plr_context
*ctx
)
81 if (ctx
->pid
!= (pid_t
) (-1)) {
82 if (kill(ctx
->pid
, SIGHUP
))
83 err(EX_OSERR
, "could not kill running player: %d", ctx
->pid
);