diff --git a/alsactl/alsactl.c b/alsactl/alsactl.c index 219d780..1e88ecc 100644 --- a/alsactl/alsactl.c +++ b/alsactl/alsactl.c @@ -916,7 +916,8 @@ static int save_state(char *file, const char *cardname) { int err; snd_config_t *config; - FILE *fp; + snd_input_t *in; + snd_output_t *out; int stdio; err = snd_config_top(&config); @@ -925,10 +926,9 @@ static int save_state(char *file, const char *cardname) return err; } stdio = !strcmp(file, "-"); - if (!stdio && (fp = fopen(file, "r"))) { - err = snd_config_load(config, fp); - if (!stdio) - fclose(fp); + if (!stdio && (err = snd_input_stdio_open(&in, file)) >= 0) { + err = snd_config_load(config, in); + snd_input_close(in); #if 0 if (err < 0) { error("snd_config_load error: %s", snd_strerror(err)); @@ -969,17 +969,16 @@ static int save_state(char *file, const char *cardname) } } - if (stdio) - fp = stdout; + if (stdio) + err = snd_output_stdio_attach(&out, stdout, 0); else - fp = fopen(file, "w"); - if (!fp) { + err = snd_output_stdio_open(&out, file); + if (err < 0) { error("Cannot open %s for writing", file); return -errno; } - err = snd_config_save(config, fp); - if (!stdio) - fclose(fp); + err = snd_config_save(config, out); + snd_output_close(out); if (err < 0) error("snd_config_save: %s", snd_strerror(err)); return 0; @@ -990,7 +989,7 @@ static int load_state(char *file, const char *cardname) { int err; snd_config_t *config; - FILE *fp; + snd_input_t *in; int stdio; err = snd_config_top(&config); @@ -1000,13 +999,12 @@ static int load_state(char *file, const char *cardname) } stdio = !strcmp(file, "-"); if (stdio) - fp = stdin; + err = snd_input_stdio_attach(&in, stdin, 0); else - fp = fopen(file, "r"); - if (fp) { - err = snd_config_load(config, fp); - if (!stdio) - fclose(fp); + err = snd_input_stdio_open(&in, file); + if (err >= 0) { + err = snd_config_load(config, in); + snd_input_close(in); if (err < 0) { error("snd_config_load error: %s", snd_strerror(err)); return err; diff --git a/aplay/aplay.c b/aplay/aplay.c index c8b79b6..ce5580d 100644 --- a/aplay/aplay.c +++ b/aplay/aplay.c @@ -86,6 +86,7 @@ static size_t bits_per_sample, bits_per_frame; static size_t chunk_bytes; static int digtype = SND_CONTROL_TYPE_NONE; static snd_digital_audio_t diga; +static snd_output_t *log; static int count; static int vocmajor, vocminor; @@ -235,14 +236,18 @@ static void device_list(void) static void pcm_list(void) { snd_config_t *conf; + snd_output_t *out; int err = snd_config_update(); if (err < 0) error("snd_pcm_update: %s", snd_strerror(err)); + err = snd_output_stdio_attach(&out, stderr, 0); + assert(err >= 0); err = snd_config_search(snd_config, "pcm", &conf); if (err < 0) return; fprintf(stderr, "PCM list:"); - snd_config_save(conf, stderr); + snd_config_save(conf, out); + snd_output_close(out); } static void version(void) @@ -285,6 +290,9 @@ int main(int argc, char *argv[]) char *pcm_name = "plug:0,0"; int tmp, err, c; + err = snd_output_stdio_attach(&log, stderr, 0); + assert(err >= 0); + command = argv[0]; file_type = FORMAT_DEFAULT; if (strstr(argv[0], "arecord")) { @@ -517,6 +525,7 @@ int main(int argc, char *argv[]) } snd_pcm_close(handle); free(audiobuf); + snd_output_close(log); return EXIT_SUCCESS; } @@ -774,7 +783,7 @@ static void set_params(void) err = snd_pcm_hw_params(handle, ¶ms); if (err < 0) { fprintf(stderr, "Unable to install hw params:\n"); - snd_pcm_hw_params_dump(¶ms, stderr); + snd_pcm_hw_params_dump(¶ms, log); exit(EXIT_FAILURE); } chunk_size = snd_pcm_hw_param_value(¶ms, SND_PCM_HW_PARAM_PERIOD_SIZE, 0); @@ -798,7 +807,7 @@ static void set_params(void) assert(err >= 0); if (snd_pcm_sw_params(handle, &swparams) < 0) { error("unable to install sw params:"); - snd_pcm_sw_params_dump(&swparams, stderr); + snd_pcm_sw_params_dump(&swparams, log); exit(EXIT_FAILURE); } if (snd_pcm_prepare(handle) < 0) { @@ -807,7 +816,7 @@ static void set_params(void) } if (verbose) - snd_pcm_dump(handle, stderr); + snd_pcm_dump(handle, log); bits_per_sample = snd_pcm_format_physical_width(hwparams.format); bits_per_frame = bits_per_sample * hwparams.channels; @@ -839,7 +848,7 @@ void xrun(void) fprintf(stderr, "xrun!!! (at least %.3f ms long)\n", diff.tv_sec * 1000 + diff.tv_usec / 1000.0); if (verbose) { fprintf(stderr, "Status:\n"); - snd_pcm_status_dump(&status, stderr); + snd_pcm_status_dump(&status, log); } if ((res = snd_pcm_prepare(handle))<0) { error("xrun: prepare error: %s", snd_strerror(res));