From ba37d057fb89f6175d4f33be0b2745c068292b4a Mon Sep 17 00:00:00 2001 From: bjoernf Date: Thu, 17 Aug 2023 17:59:49 +0200 Subject: [PATCH] fixed bug that changed the HOME env var inside the program --- main.c | 8 +++++--- play_raw_audio.c | 8 -------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/main.c b/main.c index 757d1a0..7c55c4b 100644 --- a/main.c +++ b/main.c @@ -12,10 +12,12 @@ int main(int argc, char **argv) { int countdown_min_total; + char *HOME = getenv("HOME"); - char *audio_file = ""; + char audio_file_path[256] = ""; if (HOME != NULL) { - audio_file = strcat(HOME, "/music/alarm-clock-elapsed.wav"); + strcpy(audio_file_path, HOME); + strcat(audio_file_path, "/music/alarm-clock-elapsed.wav"); } else { printf ("Can't find environment variable HOME!\n"); return 1; @@ -59,7 +61,7 @@ int main(int argc, char **argv) { } printf ("THE TIME IS UP!\n"); - play_raw_audio(audio_file); + play_raw_audio(audio_file_path); return 0; } diff --git a/play_raw_audio.c b/play_raw_audio.c index d6be552..c76d57a 100644 --- a/play_raw_audio.c +++ b/play_raw_audio.c @@ -21,16 +21,8 @@ int play_raw_audio(char file_name[]) { ss.rate = 48000; ss.channels = 2; - // Temporarily redirect stderr to /dev/null - // because pulseaudio prints to stderr even though it does not set any error codes - FILE *original_stderr = stderr; - stderr = fopen("/dev/null", "w"); - simple = pa_simple_new(NULL, "Audio Playback", PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &pa_error); - // Restore stderr - stderr = original_stderr; - int i = 0; while (read(myfd, content, sizeof(content))) { // skip the first 1024 bytes to not play the file header