[systemd-devel] small implementation of systemd escaping

Manuel Amador (Rudd-O) rudd-o at rudd-o.com
Wed Feb 29 00:35:56 PST 2012


Feel free to add to systemd under whatever license you choose.  I use it for 
my generators in ZFS.

---------------systemdescaper.c---------------------------------

#include <stdio.h>

int main ( int argc, char ** argv) {
	
	if (argc != 3) {
		fprintf(stderr,"usage: <command> --escape <string>\n");
		return 0;
	}
	
	const char * parm = argv[2];
	char character;
	int counter;
	
	counter = 0;
	character = parm[counter];
	while (character != '\0') {
		if (character == '/' && counter == 0) printf("");
		else if (character == '/' && counter != 0) printf("-");
		else if (character <= 32 || character == '-') printf("\\x%x",character);
		else printf("%c",character);
		counter++;
		character = parm[counter];
	}
	return 0;
	
}



More information about the systemd-devel mailing list