Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/audiocfg Use err(3)/warn(3) instead of perror(3)/fpr...
details: https://anonhg.NetBSD.org/src/rev/68ff09a74bdb
branches: trunk
changeset: 964965:68ff09a74bdb
user: isaki <isaki%NetBSD.org@localhost>
date: Sat Aug 24 06:00:49 2019 +0000
description:
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 | 53 +++++++++++++++++++++-----------------------
3 files changed, 43 insertions(+), 45 deletions(-)
diffs (truncated from 301 to 300 lines):
diff -r 752898e63228 -r 68ff09a74bdb usr.bin/audiocfg/audiodev.c
--- a/usr.bin/audiocfg/audiodev.c Sat Aug 24 05:51:06 2019 +0000
+++ b/usr.bin/audiocfg/audiodev.c Sat Aug 24 06:00:49 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: audiodev.c,v 1.11 2019/08/24 05:51:06 isaki Exp $ */
+/* $NetBSD: audiodev.c,v 1.12 2019/08/24 06:00:49 isaki 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>
@@ -159,7 +160,7 @@
fd = open(DRVCTLDEV, O_RDONLY);
if (fd == -1) {
- perror("open " DRVCTLDEV);
+ warn("open %s", DRVCTLDEV);
return -1;
}
@@ -173,7 +174,7 @@
error = drvctl_foreach(fd, "audio", audiodev_cb, NULL);
if (error == -1) {
- perror("drvctl");
+ warnx("drvctl failed");
return -1;
}
@@ -227,19 +228,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;
}
@@ -262,8 +263,7 @@
break;
}
if (enc >= encoding_max) {
- fprintf(stderr, "unknown encoding name: %s\n", encname);
- errno = EINVAL;
+ warnx("unknown encoding name: %s", encname);
return -1;
}
@@ -286,7 +286,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;
@@ -303,7 +303,7 @@
adev->fd = open(adev->path, O_WRONLY);
if (adev->fd == -1) {
- perror("open");
+ warn("open %s", adev->path);
return -1;
}
@@ -314,11 +314,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;
}
@@ -363,7 +363,7 @@
wlen = buflen;
ret = write(adev->fd, (char *)buf + off, wlen);
if (ret == -1) {
- perror("write");
+ warn("write");
goto done;
}
wlen = ret;
@@ -372,7 +372,7 @@
}
if (ioctl(adev->fd, AUDIO_DRAIN) == -1) {
- perror("ioctl AUDIO_DRAIN");
+ warn("ioctl AUDIO_DRAIN");
goto done;
}
diff -r 752898e63228 -r 68ff09a74bdb usr.bin/audiocfg/dtmf.c
--- a/usr.bin/audiocfg/dtmf.c Sat Aug 24 05:51:06 2019 +0000
+++ b/usr.bin/audiocfg/dtmf.c Sat Aug 24 06:00:49 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.4 2019/08/24 06:00:49 isaki 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 752898e63228 -r 68ff09a74bdb usr.bin/audiocfg/main.c
--- a/usr.bin/audiocfg/main.c Sat Aug 24 05:51:06 2019 +0000
+++ b/usr.bin/audiocfg/main.c Sat Aug 24 06:00:49 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.13 2019/08/24 05:51:06 isaki Exp $ */
+/* $NetBSD: main.c,v 1.14 2019/08/24 06:00:49 isaki 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) {
@@ -169,48 +172,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);
} 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;
@@ -220,49 +219,47 @@
else if (argv[3][j] == 'r')
mode |= AUMODE_RECORD;
else
- usage(argv[0]);
+ usage();
}
if (mode == 0)
- usage(argv[0]);
+ usage();
/* NOTREACHED */
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);
if (audiodev_test(adev) == -1)
return EXIT_FAILURE;
} else
- usage(argv[0]);
+ usage();
/* NOTREACHED */
Home |
Main Index |
Thread Index |
Old Index