currently only for "TZ" */
| 127 | |
| 128 | /* currently only for "TZ" */ |
| 129 | static char *cmdline_subst(const char *cmdline) |
| 130 | { |
| 131 | DynBuf dbuf; |
| 132 | const char *p; |
| 133 | char var_name[32], *q, buf[32]; |
| 134 | |
| 135 | dbuf_init(&dbuf); |
| 136 | p = cmdline; |
| 137 | while (*p != '\0') { |
| 138 | if (p[0] == '$' && p[1] == '{') { |
| 139 | p += 2; |
| 140 | q = var_name; |
| 141 | while (*p != '\0' && *p != '}') { |
| 142 | if ((q - var_name) < sizeof(var_name) - 1) |
| 143 | *q++ = *p; |
| 144 | p++; |
| 145 | } |
| 146 | *q = '\0'; |
| 147 | if (*p == '}') |
| 148 | p++; |
| 149 | if (!strcmp(var_name, "TZ")) { |
| 150 | time_t ti; |
| 151 | struct tm tm; |
| 152 | int n, sg; |
| 153 | /* get the offset to UTC */ |
| 154 | time(&ti); |
| 155 | localtime_r(&ti, &tm); |
| 156 | n = tm.tm_gmtoff / 60; |
| 157 | sg = '-'; |
| 158 | if (n < 0) { |
| 159 | sg = '+'; |
| 160 | n = -n; |
| 161 | } |
| 162 | snprintf(buf, sizeof(buf), "UTC%c%02d:%02d", |
| 163 | sg, n / 60, n % 60); |
| 164 | dbuf_putstr(&dbuf, buf); |
| 165 | } |
| 166 | } else { |
| 167 | dbuf_putc(&dbuf, *p++); |
| 168 | } |
| 169 | } |
| 170 | dbuf_putc(&dbuf, 0); |
| 171 | return (char *)dbuf.buf; |
| 172 | } |
| 173 | |
| 174 | static BOOL find_name(const char *name, const char *name_list) |
| 175 | { |
no test coverage detected