#include <math.h>
#include <stdint.h>
#include <pthread.h>
+#include <errno.h>
#include <alsa/asoundlib.h>
if (bat->debugplay) {
fp = fopen(bat->debugplay, "wb");
+ err = -errno;
if (fp == NULL) {
fprintf(bat->err, _("Cannot open file for capture: "));
- fprintf(bat->err, _("%s %d\n"), bat->debugplay, -errno);
- return -errno;
+ fprintf(bat->err, _("%s %d\n"), bat->debugplay, err);
+ return err;
}
/* leave space for wav header */
- err = fseek(fp, sizeof(wav), SEEK_SET);
- if (err != 0) {
- fprintf(bat->err, _("Seek file error: %d %d\n"),
- err, -errno);
- return -errno;
+ if (fseek(fp, sizeof(wav), SEEK_SET) != 0) {
+ err = -errno;
+ fclose(fp);
+ return err;
}
}
fprintf(bat->log, _("Playing input audio file: %s\n"),
bat->playback.file);
bat->fp = fopen(bat->playback.file, "rb");
+ err = -errno;
if (bat->fp == NULL) {
fprintf(bat->err, _("Cannot open file for capture: "));
fprintf(bat->err, _("%s %d\n"),
- bat->playback.file, -errno);
+ bat->playback.file, err);
retval_play = 1;
goto exit3;
}
remove(bat->capture.file);
fp = fopen(bat->capture.file, "w+");
+ err = -errno;
if (fp == NULL) {
fprintf(bat->err, _("Cannot open file for capture: %s %d\n"),
- bat->capture.file, -errno);
+ bat->capture.file, err);
retval_record = 1;
goto exit3;
}
static int get_duration(struct bat *bat)
{
+ int err;
float duration_f;
long duration_i;
char *ptrf, *ptri;
duration_f = strtof(bat->narg, &ptrf);
+ err = -errno;
if (duration_f == HUGE_VALF || duration_f == -HUGE_VALF
- || (duration_f == 0.0 && errno != 0))
+ || (duration_f == 0.0 && err != 0))
goto err_exit;
duration_i = strtol(bat->narg, &ptri, 10);
return 0;
err_exit:
- fprintf(bat->err, _("Duration overflow/underflow: %d\n"), -errno);
+ fprintf(bat->err, _("Duration overflow/underflow: %d\n"), err);
- return -errno;
+ return err;
}
static void get_sine_frequencies(struct bat *bat, char *freq)
static int bat_init(struct bat *bat)
{
int err = 0;
+ int fd = 0;
char name[] = TEMP_RECORD_FILE_NAME;
/* Determine logging to a file or stdout and stderr */
if (bat->logarg) {
bat->log = NULL;
bat->log = fopen(bat->logarg, "wb");
+ err = -errno;
if (bat->log == NULL) {
fprintf(bat->err, _("Cannot open file for capture:"));
- fprintf(bat->err, _(" %s %d\n"),
- bat->logarg, -errno);
- return -errno;
+ fprintf(bat->err, _(" %s %d\n"), bat->logarg, err);
+ return err;
}
bat->err = bat->log;
}
bat->capture.file = bat->playback.file;
} else {
/* create temp file for sound record and analysis */
- err = mkstemp(name);
- if (err == -1) {
+ fd = mkstemp(name);
+ err = -errno;
+ if (fd == -1) {
fprintf(bat->err, _("Fail to create record file: %d\n"),
- -errno);
- return -errno;
+ err);
+ return err;
}
/* store file name which is dynamically created */
bat->capture.file = strdup(name);
+ err = -errno;
if (bat->capture.file == NULL)
- return -errno;
+ return err;
/* close temp file */
- close(err);
+ close(fd);
}
/* Initial for playback */
}
} else {
bat->fp = fopen(bat->playback.file, "rb");
+ err = -errno;
if (bat->fp == NULL) {
fprintf(bat->err, _("Cannot open file for playback:"));
fprintf(bat->err, _(" %s %d\n"),
- bat->playback.file, -errno);
- return -errno;
+ bat->playback.file, err);
+ return err;
}
err = read_wav_header(bat, bat->playback.file, bat->fp, false);
fclose(bat->fp);