#warning unexpected platform in os_process.c
#endif
+#if defined(PIPE_OS_LINUX)
+# include <fcntl.h>
+#endif
+
/**
* Return the name of the current process.
return FALSE;
}
}
+
+
+/**
+ * Return the command line for the calling process. This is basically
+ * the argv[] array with the arguments separated by spaces.
+ * \param cmdline returns the command line string
+ * \param size size of the cmdline buffer
+ * \return TRUE or FALSE for success, failure
+ */
+boolean
+os_get_command_line(char *cmdline, size_t size)
+{
+#if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
+ const char *args = GetCommandLine();
+ if (args) {
+ strncpy(cmdline, args, size);
+ // make sure we terminate the string
+ cmdline[size - 1] = 0;
+ return TRUE;
+ }
+#elif defined(PIPE_OS_LINUX)
+ int f = open("/proc/self/cmdline", O_RDONLY);
+ if (f) {
+ const int n = read(f, cmdline, size - 1);
+ int i;
+ assert(n < size);
+ // The arguments are separated by '\0' chars. Convert them to spaces.
+ for (i = 0; i < n; i++) {
+ if (cmdline[i] == 0) {
+ cmdline[i] = ' ';
+ }
+ }
+ // terminate the string
+ cmdline[n] = 0;
+ close(f);
+ return TRUE;
+ }
+#endif
+
+ /* XXX to-do: implement this function for other operating systems */
+
+ cmdline[0] = 0;
+ return FALSE;
+}