coreutils

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

AuthorJamozed <[email protected]>
Date2020-07-06 10:43:09
Commit32c7dc05245ef2cfbcd29c75003fb41161f27a23
Parente013c3eb3ad4e5d1205ea0f26aeea34b5797e26f

id: Use libokv error reporting

Diffstat

M src/id.c | 27 +++++++++++++++------------

1 files changed, 15 insertions, 12 deletions

diff --git a/src/id.c b/src/id.c
index 2721fc0..26a013c 100644
--- a/src/id.c
+++ b/src/id.c
@@ -1,4 +1,4 @@
-// id.c, version 0.1.0
+// id.c, version 0.1.1
 // OMKOV coreutils implementation of POSIX id
 // Copyright (C) 2020, Jakob Wakeling
 // All rights reserved.
@@ -37,9 +37,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 	TODO Fix memory leak when listing supplementary groups (may be unfixable)
 */
 
-#include "error.h"
 #include "optget.h"
 
+#include <error.h>
+
 #include <grp.h>
 #include <pwd.h>
 #include <sys/types.h>
@@ -48,6 +49,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 #include <stdbool.h>
 #include <stdlib.h>
 
+#define VERSION "0.1.1"
+
 typedef struct passwd pwd_t;
 typedef struct group  grp_t;
 
@@ -61,7 +64,7 @@ static inline void groups(const char *user, gid_t gid, gid_t egid);
 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 },
@@ -69,9 +72,9 @@ int main(int argc, char *argv[]) {
 	};
 
 	opt_t opt = OPTGET_INIT; opt.str = "Ggnru"; opt.lops = lops; int o;
-	while ((o = optget(&opt, argv, 1)) != -1) switch (o) {
+	while ((o = optget(&opt, av, 1)) != -1) switch (o) {
 	case 'G': case 'g': case 'u': {
-		if (mode) { error(1, "%s: invalid option combination", argv[0]); }
+		if (mode) { error(1, "invalid option combination"); }
 		else { mode = (char)o; } break;
 	}
 	case 'n': { nflag = true; break; }
@@ -82,22 +85,20 @@ int main(int argc, char *argv[]) {
 	}
 
 	if (!mode && (nflag || rflag)) {
-		error(1, "%s: options 'n' and 'r' require 'G', 'g', or 'u'", argv[0]);
+		error(1, "options 'n' and 'r' require 'G', 'g', or 'u'");
 	}
 
 	uid_t uid, euid; gid_t gid, egid;
 
-	if (opt.ind == argc) {
+	if (opt.ind == ac) {
 		uid = getuid(); euid = geteuid();
 		gid = getgid(); egid = getegid();
 		id (uid, euid, gid, egid);
 	}
-	else for (char **p = &argv[opt.ind]; *p; ++p) {
+	else for (char **p = &av[opt.ind]; *p; ++p) {
 		pwd_t *pwd;
 
-		if (!(pwd = getpwnam(*p))) {
-			error(1, "%s: %s: invalid user", argv[0], *p);
-		}
+		if (!(pwd = getpwnam(*p))) { error(1, "%s: invalid user", *p); }
 
 		uid = euid = pwd->pw_uid;
 		gid = egid = pwd->pw_gid;
@@ -184,7 +185,7 @@ static void help(void) {
 }
 
 static void version(void) {
-	puts("OMKOV coreutils id, version 0.1.0");
+	puts("OMKOV coreutils id, version " VERSION);
 	puts("Copyright (C) 2020, Jakob Wakeling");
 	puts("All rights reserved.");
 	puts("OMKOV Permissive Licence (https://www.omkov.net/OLPE)");