MCPcopy Create free account
hub / github.com/eggert/tz / dogmt

Function dogmt

date.c:111–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109}
110
111static void
112dogmt(void)
113{
114 static char ** fakeenv;
115
116 if (fakeenv == NULL) {
117 static char tzeutc0[] = "TZ=UTC0";
118 ptrdiff_t from, to, n;
119
120 for (n = 0; environ[n] != NULL; ++n)
121 continue;
122#if defined ckd_add && defined ckd_mul
123 if (!ckd_add(&n, n, 2) && !ckd_mul(&n, n, sizeof *fakeenv)
124 && n <= INDEX_MAX)
125 fakeenv = malloc(n);
126#else
127 if (n <= INDEX_MAX / sizeof *fakeenv - 2)
128 fakeenv = malloc((n + 2) * sizeof *fakeenv);
129#endif
130 if (fakeenv == NULL) {
131 fprintf(stderr, _("date: Memory exhausted\n"));
132 errensure();
133 exit(retval);
134 }
135 to = 0;
136 fakeenv[to++] = tzeutc0;
137 for (from = 1; environ[from] != NULL; ++from)
138 if (strncmp(environ[from], "TZ=", 3) != 0)
139 fakeenv[to++] = environ[from];
140 fakeenv[to] = NULL;
141 environ = fakeenv;
142 }
143}
144
145static void
146errensure(void)

Callers 1

mainFunction · 0.85

Calls 1

errensureFunction · 0.85

Tested by

no test coverage detected