Hello everyone, currently I am using a portable version of the timegm() function (it's available on man page of timegm()) which temporarily sets the value of the global TZ environment variable to UTC. The current issue is that if at the same time another process makes a call to a time-related function (that depends on TZ) for getting local time,it'll get an unexpected result as TZ is set to UTC.

#include <time.h>
#include <stdlib.h>

time_t my_timegm (struct tm *tm) {
  time_t ret;
  char *tz;

  tz = getenv("TZ");
  setenv("TZ", "", 1);
  ret = mktime(tm);
  if (tz)
      setenv("TZ", tz, 1);
  return ret;
Is there any way I can safely modify the global variable TZ without negatively affecting other processes? I'd appreciate any help regarding this. Thanks!