From e60683a0d553b6488c564863f4e48954944fb0f8 Mon Sep 17 00:00:00 2001 From: bigbiff bigbiff Date: Fri, 22 Feb 2013 20:55:50 -0500 Subject: use libblkid to get filesystem type we can now use libblkid to detect exfat --- libblkid/setproctitle.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 libblkid/setproctitle.c (limited to 'libblkid/setproctitle.c') diff --git a/libblkid/setproctitle.c b/libblkid/setproctitle.c new file mode 100644 index 000000000..4bcf8c8a9 --- /dev/null +++ b/libblkid/setproctitle.c @@ -0,0 +1,74 @@ +/* + * set process title for ps (from sendmail) + * + * Clobbers argv of our main procedure so ps(1) will display the title. + */ +#include +#include +#include +#include + +#include "setproctitle.h" + +#ifndef SPT_BUFSIZE +# define SPT_BUFSIZE 2048 +#endif + +extern char **environ; + +static char **argv0; +static int argv_lth; + +void initproctitle (int argc, char **argv) +{ + int i; + char **envp = environ; + + /* + * Move the environment so we can reuse the memory. + * (Code borrowed from sendmail.) + * WARNING: ugly assumptions on memory layout here; + * if this ever causes problems, #undef DO_PS_FIDDLING + */ + for (i = 0; envp[i] != NULL; i++) + continue; + + environ = (char **) malloc(sizeof(char *) * (i + 1)); + if (environ == NULL) + return; + + for (i = 0; envp[i] != NULL; i++) + if ((environ[i] = strdup(envp[i])) == NULL) + return; + environ[i] = NULL; + + argv0 = argv; + if (i > 0) + argv_lth = envp[i-1] + strlen(envp[i-1]) - argv0[0]; + else + argv_lth = argv0[argc-1] + strlen(argv0[argc-1]) - argv0[0]; +} + +void setproctitle (const char *prog, const char *txt) +{ + int i; + char buf[SPT_BUFSIZE]; + + if (!argv0) + return; + + if (strlen(prog) + strlen(txt) + 5 > SPT_BUFSIZE) + return; + + sprintf(buf, "%s -- %s", prog, txt); + + i = strlen(buf); + if (i > argv_lth - 2) { + i = argv_lth - 2; + buf[i] = '\0'; + } + memset(argv0[0], '\0', argv_lth); /* clear the memory area */ + strcpy(argv0[0], buf); + + argv0[1] = NULL; +} -- cgit v1.2.3