Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-9]: src/usr.bin/audiocfg Pull up following revision(s) (requested...
details: https://anonhg.NetBSD.org/src/rev/7932d74d9b28
branches: netbsd-9
changeset: 963055:7932d74d9b28
user: martin <martin%NetBSD.org@localhost>
date: Sun Sep 29 07:34:09 2019 +0000
description:
Pull up following revision(s) (requested by isaki in ticket #267):
usr.bin/audiocfg/dtmf.c: revision 1.4
usr.bin/audiocfg/main.c: revision 1.14 (via patch)
usr.bin/audiocfg/audiodev.c: revision 1.12
Use err(3)/warn(3) instead of perror(3)/fprintf(stderr,...).
Use getprogname(3) for usage().
diffstat:
usr.bin/audiocfg/audiodev.c | 30 +++++++++++++-------------
usr.bin/audiocfg/dtmf.c | 5 ++-
usr.bin/audiocfg/main.c | 51 +++++++++++++++++++++-----------------------
3 files changed, 42 insertions(+), 44 deletions(-)
diffs (297 lines):
diff -r 1ab753edab44 -r 7932d74d9b28 usr.bin/audiocfg/audiodev.c
--- a/usr.bin/audiocfg/audiodev.c Sun Sep 29 07:26:23 2019 +0000
+++ b/usr.bin/audiocfg/audiodev.c Sun Sep 29 07:34:09 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.c,v 1.7.2.1 2019/09/28 07:41:18 martin Exp $ */
+/* $NetBSD: audiodev.c,v 1.7.2.2 2019/09/29 07:34:09 martin Exp $ */
/*
* Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -31,6 +31,7 @@
#include <sys/stat.h>
#include <sys/drvctlio.h>
+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <paths.h>
@@ -155,7 +156,7 @@
fd = open(DRVCTLDEV, O_RDONLY);
if (fd == -1) {
- perror("open " DRVCTLDEV);
+ warn("open %s", DRVCTLDEV);
return -1;
}
@@ -169,7 +170,7 @@
error = drvctl_foreach(fd, "audio", audiodev_cb, NULL);
if (error == -1) {
- perror("drvctl");
+ warnx("drvctl failed");
return -1;
}
@@ -230,19 +231,19 @@
unlink(_PATH_MIXER);
if (symlink(audiopath, _PATH_AUDIO) == -1) {
- perror("symlink " _PATH_AUDIO);
+ warn("symlink %s", _PATH_AUDIO);
return -1;
}
if (symlink(soundpath, _PATH_SOUND) == -1) {
- perror("symlink " _PATH_SOUND);
+ warn("symlink %s", _PATH_SOUND);
return -1;
}
if (symlink(audioctlpath, _PATH_AUDIOCTL) == -1) {
- perror("symlink " _PATH_AUDIOCTL);
+ warn("symlink %s", _PATH_AUDIOCTL);
return -1;
}
if (symlink(mixerpath, _PATH_MIXER) == -1) {
- perror("symlink " _PATH_MIXER);
+ warn("symlink %s", _PATH_MIXER);
return -1;
}
@@ -265,8 +266,7 @@
break;
}
if (enc >= encoding_max) {
- fprintf(stderr, "unknown encoding name: %s\n", encname);
- errno = EINVAL;
+ warnx("unknown encoding name: %s", encname);
return -1;
}
@@ -294,7 +294,7 @@
printf("setting %s to %s:%u, %uch, %uHz\n",
adev->xname, encname, prec, ch, freq);
if (ioctl(adev->ctlfd, AUDIO_SETFORMAT, &ai) == -1) {
- perror("ioctl AUDIO_SETFORMAT");
+ warn("ioctl AUDIO_SETFORMAT");
return -1;
}
return 0;
@@ -311,7 +311,7 @@
adev->fd = open(adev->path, O_WRONLY);
if (adev->fd == -1) {
- perror("open");
+ warn("open %s", adev->path);
return -1;
}
@@ -322,11 +322,11 @@
info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
info.mode = AUMODE_PLAY;
if (ioctl(adev->fd, AUDIO_SETINFO, &info) == -1) {
- perror("ioctl AUDIO_SETINFO");
+ warn("ioctl AUDIO_SETINFO");
goto done;
}
if (ioctl(adev->fd, AUDIO_GETINFO, &info) == -1) {
- perror("ioctl AUDIO_GETINFO");
+ warn("ioctl AUDIO_GETINFO");
goto done;
}
@@ -371,7 +371,7 @@
wlen = buflen;
ret = write(adev->fd, (char *)buf + off, wlen);
if (ret == -1) {
- perror("write");
+ warn("write");
goto done;
}
wlen = ret;
@@ -380,7 +380,7 @@
}
if (ioctl(adev->fd, AUDIO_DRAIN) == -1) {
- perror("ioctl AUDIO_DRAIN");
+ warn("ioctl AUDIO_DRAIN");
goto done;
}
diff -r 1ab753edab44 -r 7932d74d9b28 usr.bin/audiocfg/dtmf.c
--- a/usr.bin/audiocfg/dtmf.c Sun Sep 29 07:26:23 2019 +0000
+++ b/usr.bin/audiocfg/dtmf.c Sun Sep 29 07:34:09 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dtmf.c,v 1.3 2013/08/11 06:31:00 dholland Exp $ */
+/* $NetBSD: dtmf.c,v 1.3.28.1 2019/09/29 07:34:09 martin Exp $ */
/*
* Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -28,6 +28,7 @@
#include <sys/endian.h>
+#include <err.h>
#include <fcntl.h>
#include <math.h>
#include <stdio.h>
@@ -70,7 +71,7 @@
*buflen = sample_rate * sizeof(int16_t) * sample_length * channels;
*buf = calloc(1, *buflen);
if (*buf == NULL) {
- perror("calloc");
+ warn("calloc");
return;
}
diff -r 1ab753edab44 -r 7932d74d9b28 usr.bin/audiocfg/main.c
--- a/usr.bin/audiocfg/main.c Sun Sep 29 07:26:23 2019 +0000
+++ b/usr.bin/audiocfg/main.c Sun Sep 29 07:34:09 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.8.2.2 2019/09/28 07:41:18 martin Exp $ */
+/* $NetBSD: main.c,v 1.8.2.3 2019/09/29 07:34:09 martin Exp $ */
/*
* Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,6 +27,7 @@
*/
#include <assert.h>
+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@@ -38,8 +39,10 @@
#include "drvctl.h"
__dead static void
-usage(const char *p)
+usage(void)
{
+ const char *p = getprogname();
+
fprintf(stderr, "usage: %s list [<index>]\n", p);
fprintf(stderr, " %s default <index>\n", p);
fprintf(stderr, " %s set <index> [p|r] <enc> <prec> <ch> <freq>\n",
@@ -155,7 +158,7 @@
return EXIT_FAILURE;
if (argc < 2)
- usage(argv[0]);
+ usage();
/* NOTREACHED */
if (strcmp(argv[1], "list") == 0 && argc == 2) {
@@ -166,48 +169,44 @@
errno = 0;
i = strtoul(argv[2], NULL, 10);
if (errno)
- usage(argv[0]);
+ usage();
/* NOTREACHED */
adev = audiodev_get(i);
if (adev == NULL) {
- fprintf(stderr, "no such device\n");
- return EXIT_FAILURE;
+ errx(EXIT_FAILURE, "no such device");
}
print_audiodev(adev, i);
} else if (strcmp(argv[1], "default") == 0 && argc == 3) {
if (*argv[2] < '0' || *argv[2] > '9')
- usage(argv[0]);
+ usage();
/* NOTREACHED */
errno = 0;
i = strtoul(argv[2], NULL, 10);
if (errno)
- usage(argv[0]);
+ usage();
/* NOTREACHED */
adev = audiodev_get(i);
if (adev == NULL) {
- fprintf(stderr, "no such device\n");
- return EXIT_FAILURE;
+ errx(EXIT_FAILURE, "no such device");
}
printf("setting default audio device to %s\n", adev->xname);
if (audiodev_set_default(adev) == -1) {
- perror("couldn't set default device");
- return EXIT_FAILURE;
+ errx(EXIT_FAILURE, "couldn't set default device");
}
} else if (strcmp(argv[1], "set") == 0 && argc == 8) {
/* XXX bad commandline... */
/* audiocfg set <index> [p|r] <enc> <prec> <ch> <freq> */
if (*argv[2] < '0' || *argv[2] > '9')
- usage(argv[0]);
+ usage();
/* NOTREACHED */
errno = 0;
i = strtoul(argv[2], NULL, 10);
if (errno)
- usage(argv[0]);
+ usage();
/* NOTREACHED */
adev = audiodev_get(i);
if (adev == NULL) {
- fprintf(stderr, "no such device\n");
- return EXIT_FAILURE;
+ errx(EXIT_FAILURE, "no such device");
}
mode = 0;
@@ -217,46 +216,44 @@
else if (argv[3][j] == 'r')
mode |= AUMODE_RECORD;
else
- usage(argv[0]);
+ usage();
}
enc = argv[4];
prec = strtoul(argv[5], NULL, 10);
if (errno)
- usage(argv[0]);
+ usage();
errno = 0;
ch = strtoul(argv[6], NULL, 10);
if (errno)
- usage(argv[0]);
+ usage();
/* NOTREACHED */
errno = 0;
freq = strtoul(argv[7], NULL, 10);
if (errno)
- usage(argv[0]);
+ usage();
/* NOTREACHED */
if (audiodev_set_param(adev, mode, enc, prec, ch, freq) == -1) {
- perror("couldn't set parameter");
- return EXIT_FAILURE;
+ errx(EXIT_FAILURE, "couldn't set parameter");
}
} else if (strcmp(argv[1], "test") == 0 && argc == 3) {
if (*argv[2] < '0' || *argv[2] > '9')
- usage(argv[0]);
+ usage();
/* NOTREACHED */
errno = 0;
i = strtoul(argv[2], NULL, 10);
if (errno)
- usage(argv[0]);
+ usage();
/* NOTREACHED */
adev = audiodev_get(i);
if (adev == NULL) {
- fprintf(stderr, "no such device\n");
- return EXIT_FAILURE;
+ errx(EXIT_FAILURE, "no such device");
}
print_audiodev(adev, i);
if (audiodev_test(adev) == -1)
return EXIT_FAILURE;
} else
- usage(argv[0]);
+ usage();
/* NOTREACHED */
return EXIT_SUCCESS;
Home |
Main Index |
Thread Index |
Old Index