wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

mfatal.c (673B)


      1 /* Written by Kris Maglione <maglione.k at Gmail> */
      2 /* Public domain */
      3 #include <string.h>
      4 #include <unistd.h>
      5 #include "util.h"
      6 
      7 /* Can't malloc */
      8 void
      9 mfatal(char *name, uint size) {
     10 	const char
     11 		couldnot[] = ": fatal: Could not ",
     12 		paren[] = "() ",
     13 		bytes[] = " bytes\n";
     14 	char buf[1024];
     15 	char sizestr[8];
     16 	int i;
     17 
     18 	i = sizeof sizestr;
     19 	do {
     20 		sizestr[--i] = '0' + (size%10);
     21 		size /= 10;
     22 	} while(size > 0);
     23 
     24 	strlcat(buf, argv0, sizeof buf);
     25 	strlcat(buf, couldnot, sizeof buf);
     26 	strlcat(buf, name, sizeof buf);
     27 	strlcat(buf, paren, sizeof buf);
     28 	strlcat(buf, sizestr+i, sizeof buf);
     29 	strlcat(buf, bytes, sizeof buf);
     30 	write(2, buf, strlen(buf));
     31 
     32 	exit(1);
     33 }