shithub: mq

Download patch

ref: 6faa25b814503c8c7c39f42508359924cb64e2c1
parent: 081ed9fecdb571030ee202e8014e8de58acca206
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Sep 17 14:13:02 EDT 2023

mq: allow scale suffixes on log length

--- a/mq.c
+++ b/mq.c
@@ -15,8 +15,9 @@
 };
 
 enum {
-	Cclose,
-	Ctrunc,
+	KiB	= 1024,
+	MiB	= 1024*KiB,
+	GiB	= 1024*MiB,
 };
 
 struct Aux {
@@ -492,7 +493,7 @@
 void
 main(int argc, char **argv)
 {
-	char *srvname, *mntpt;
+	char *srvname, *mntpt, *s, *e;
 
 	srvname = "mq";
 	mntpt = "/mnt/mq";
@@ -506,8 +507,20 @@
 	case 'm':
 		mntpt = EARGF(usage());
 		break;
-	case 'r':
-		maxlog = atoi(EARGF(usage()));
+	case 'l':
+		s = EARGF(usage());
+		maxlog = strtoll(s, &e, 0);
+		while(*e){
+			switch(*e++){
+			case 'k':	maxlog *= KiB;	break;
+			case 'K':	maxlog *= KiB;	break;
+			case 'm':	maxlog *= MiB;	break;
+			case 'M':	maxlog *= MiB;	break;
+			case 'g':	maxlog *= GiB;	break;
+			case 'G':	maxlog *= GiB;	break;
+			default:	sysfatal("unknown suffix %c", *e);
+			}
+		}
 		break;
 	default:
 		usage();