summaryrefslogtreecommitdiffstats
path: root/mbbsd/args.c
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-03-07 23:13:44 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-03-07 23:13:44 +0800
commitae31e19f92e717919ac8e3db9039eb38d2b89aae (patch)
treec70164d6a1852344f44b04a653ae2815043512af /mbbsd/args.c
downloadpttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.gz
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.bz2
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.lz
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.xz
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.zst
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.zip
Initial revision
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@1 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/args.c')
-rw-r--r--mbbsd/args.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/mbbsd/args.c b/mbbsd/args.c
new file mode 100644
index 00000000..4d1d6ceb
--- /dev/null
+++ b/mbbsd/args.c
@@ -0,0 +1,62 @@
+/* $Id: args.c,v 1.1 2002/03/07 15:13:48 in2 Exp $ */
+#ifdef HAVE_SETPROCTITLE
+
+void initsetproctitle(int argc, char **argv, char **envp) {
+}
+
+#else
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+char **Argv = NULL; /* pointer to argument vector */
+char *LastArgv = NULL; /* end of argv */
+extern char **environ;
+
+void initsetproctitle(int argc, char **argv, char **envp) {
+ register int i;
+
+ /* Move the environment so setproctitle can use the space at
+ the top of memory. */
+ for(i = 0; envp[i]; i++);
+ environ = malloc(sizeof(char *) * (i + 1));
+ for(i = 0; envp[i]; i++)
+ environ[i] = strdup(envp[i]);
+ environ[i] = NULL;
+
+ /* Save start and extent of argv for setproctitle. */
+ Argv = argv;
+ if(i > 0)
+ LastArgv = envp[i - 1] + strlen(envp[i - 1]);
+ else
+ LastArgv = argv[argc - 1] + strlen(argv[argc - 1]);
+}
+
+static void do_setproctitle(const char *cmdline) {
+ char buf[256], *p;
+ int i;
+
+ strncpy(buf, cmdline, 256);
+ buf[255] = '\0';
+ i = strlen(buf);
+ if(i > LastArgv - Argv[0] - 2) {
+ i = LastArgv - Argv[0] - 2;
+ }
+ strcpy(Argv[0], buf);
+ p = &Argv[0][i];
+ while(p < LastArgv)
+ *p++='\0';
+ Argv[1] = NULL;
+}
+
+void setproctitle(const char* format, ...) {
+ char buf[256];
+ va_list args;
+ va_start(args, format);
+ vsprintf(buf, format,args);
+ do_setproctitle(buf);
+ va_end(args);
+}
+#endif