https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124330

--- Comment #2 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
What about something like this:

void
shared_memory_set_env (pid_t pid)
{
  /* Increased size slightly to accommodate "ENV_VAR_NAME=" prefix for putenv
*/
  char *buffer;
  int res;

#if defined(HAVE_SETENV)
  char val[20];
  snprintf (val, 20, "%d", pid);
  setenv (ENV_PPID, val, 1);
#elif defined(_WIN32)
  char val[20];
  snprintf (val, 20, "%d", pid);
  SetEnvironmentVariable (ENV_PPID, val);
#else
  /* HP-UX / Legacy Fallback using putenv */
  res = asprintf (&buffer, "%s=%d", ENV_PPID, (int)pid);
  if (res != -1)
    putenv (buffer);
#endif
}

Reply via email to