summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-03-14 13:18:24 -0400
committerJakob Kaivo <jkk@ung.org>2019-03-14 13:18:24 -0400
commitaabf2e0f651292400d8683b41656cecab65033a5 (patch)
treeef32442e1bc3b811aa37628047b11e34088472ef
parent534e9a5d77adbcfe09d4ad6c643ea7bf3c824449 (diff)
call setlocale() for localized perror() messages; cleaner return at end
-rw-r--r--nice.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/nice.c b/nice.c
index 274191d..a103d0c 100644
--- a/nice.c
+++ b/nice.c
@@ -1,14 +1,20 @@
#define _XOPEN_SOURCE 700
#include <errno.h>
+#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#define NICE_UTILITY_NOT_FOUND 127
+#define NICE_UTILITY_NOT_INVOKED 126
+
int main(int argc, char *argv[])
{
int increment = 0;
int c;
+ setlocale(LC_ALL, "");
+
while ((c = getopt(argc, argv, "n:")) != -1) {
switch (c) {
case 'n':
@@ -30,5 +36,10 @@ int main(int argc, char *argv[])
execvp(argv[0], argv);
perror("nice");
- return errno == ENOENT ? 127 : 126;
+
+ if (errno == ENOENT) {
+ return NICE_UTILITY_NOT_FOUND;
+ }
+
+ return NICE_UTILITY_NOT_INVOKED;
}