coreutils

General Software Utilities
git clone http://git.omkov.net/coreutils
Log | Tree | Refs | README | LICENCE | Download

AuthorJamozed <[email protected]>
Date2020-07-06 11:19:56
Commit69fd1df5999ae1a77aabff6cce656e65484be71d
Parentecf4694c1114f3191f19a33f595cfe17267e95de

rand: Use libokv error reporting

Diffstat

M src/rand.c | 25 +++++++++++++------------

1 files changed, 13 insertions, 12 deletions

diff --git a/src/rand.c b/src/rand.c
index 5b7747b..df876b9 100644
--- a/src/rand.c
+++ b/src/rand.c
@@ -1,4 +1,4 @@
-// rand.c, version 1.0.0
+// rand.c, version 1.0.1
 // OMKOV coreutils rand
 // Copyright (C) 2020, Jakob Wakeling
 // All rights reserved.
@@ -33,14 +33,15 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 */
 
-#include "error.h"
 #include "optget.h"
 
-#include <errno.h>
+#include <error.h>
+
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+
+#define VERSION "1.0.1"
 
 #define aSIZE (sizeof (aset) - 1)
 #define ASIZE (sizeof (Aset) - 1)
@@ -58,7 +59,7 @@ static uintmax_t len;
 static void help(void);
 static void version(void);
 
-int main(int argc, char *argv[]) {
+int main(int ac, char *av[]) { A0 = av[0];
 	lop_t lops[] = {
 		{ "help",    ARG_NUL, 256 },
 		{ "version", ARG_NUL, 257 },
@@ -66,7 +67,7 @@ int main(int argc, char *argv[]) {
 	};
 
 	opt_t opt = OPTGET_INIT; opt.str = "aAns"; opt.lops = lops; int o;
-	while ((o = optget(&opt, argv, 1)) != -1) switch (o) {
+	while ((o = optget(&opt, av, 1)) != -1) switch (o) {
 	case 'a': { mode |= 1; break; }
 	case 'A': { mode |= 2; break; }
 	case 'n': { mode |= 4; break; }
@@ -77,21 +78,21 @@ int main(int argc, char *argv[]) {
 	}
 
 	if (!mode) { mode = 6; }
-	if (opt.ind == argc) { len = 8; }
+	if (opt.ind == ac) { len = 8; }
 	else {
-		register uintmax_t d; register char *p = argv[opt.ind];
+		register uintmax_t d; register char *p = av[opt.ind];
 		for (; *p >= '0' && *p <= '9'; ++p) {
 			d = (uintmax_t)*p - '0';
 			if (len > (UINTMAX_MAX - d) / 10) { break; }
 			len = len * 10 + d;
 		}
 
-		if (*p) { error(1, "%s: %s: invalid length", argv[0], argv[opt.ind]); }
+		if (*p) { error(1, "%s: invalid length", av[opt.ind]); }
 	}
 
 	FILE *rand; char *set; unsigned setlen = 0, n;
 	if (!(rand = fopen("/dev/urandom", "r"))) {
-		error(1, "%s: %s: %s", argv[0], "/dev/urandom", serrno);
+		error(1, "%s: %s", "/dev/urandom", serr());
 	}
 
 	if (mode & 1) { setlen += aSIZE; }
@@ -100,7 +101,7 @@ int main(int argc, char *argv[]) {
 	if (mode & 8) { setlen += sSIZE; }
 
 	if (!(set = (char *)malloc(setlen + 1))) {
-		fclose(rand); error(1, "%s: %s", argv[0], serrno);
+		fclose(rand); error(1, "%s", serr());
 	}
 
 	if (mode & 1) { strcat(set, aset); }
@@ -130,7 +131,7 @@ static void help(void) {
 }
 
 static void version(void) {
-	puts("OMKOV coreutils rand, version 1.0.0");
+	puts("OMKOV coreutils rand, version " VERSION);
 	puts("Copyright (C) 2020, Jakob Wakeling");
 	puts("All rights reserved.");
 	puts("OMKOV Permissive Licence (https://www.omkov.net/OLPE)");