| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| •72 |
#include <strings.h> |
| 73 |
|
| 74 |
#include "cronoutils.h" |
| 75 |
extern char *tzname[2]; |
| 76 |
|
| 77 |
|
| 78 |
#ifdef _WIN32 |
| 79 |
#include "strptime.h" |
| 80 |
#endif |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
FILE *debug_file = NULL; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
int weeks_start_on_mondays = 0; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
char *periods[] = |
| 96 |
{ |
| 97 |
"second", |
| 98 |
"minute", |
| 99 |
"hour", |
| 100 |
"day", |
| 101 |
"week", |
| 102 |
"month", |
| 103 |
"year", |
| 104 |
"aeon" |
| 105 |
}; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
int period_seconds[] = |
| 110 |
{ |
| 111 |
1, |
| 112 |
60, |
| 113 |
60 * 60, |
| 114 |
60 * 60 * 24, |
| 115 |
60 * 60 * 24 * 7, |
| 116 |
60 * 60 * 24 * 31, |
| 117 |
60 * 60 * 24 * 36 |
| 118 |
}; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
void |
| 133 |
create_subdirs(char *filename) |
| 134 |
{ |
| 135 |
#ifndef CHECK_ALL_PREFIX_DIRS |
| 136 |
static char lastpath[MAX_PATH] = ""; |
| 137 |
#endif |
| 138 |
struct stat stat_buf; |
| 139 |
char dirname[MAX_PATH]; |
| 140 |
char *p; |
| 141 |
|
| 142 |
DEBUG(("Creating missing components of \"%s\"\n", filename)); |
| 143 |
for (p = filename; (p = strchr(p, '/')); p++) |
| 144 |
{ |
| 145 |
if (p == filename) |
| 146 |
{ |
| 147 |
continue; |
| 148 |
} |
| 149 |
|
| 150 |
memcpy(dirname, filename, p - filename); |
| 151 |
dirname[p-filename] = '\0'; |
| 152 |
|
| 153 |
#ifndef CHECK_ALL_PREFIX_DIRS |
| 154 |
if (strncmp(dirname, lastpath, strlen(dirname)) == 0) |
| 155 |
{ |
| 156 |
DEBUG(("Initial prefix \"%s\" known to exist\n", dirname)); |
| 157 |
continue; |
| 158 |
} |
| 159 |
#endif |
| 160 |
|
| 161 |
DEBUG(("Testing directory \"%s\"\n", dirname)); |
| 162 |
if (stat(dirname, &stat_buf) < 0) |
| 163 |
{ |
| 164 |
if (errno != ENOENT) |
| 165 |
{ |
| 166 |
perror(dirname); |
| 167 |
exit(2); |
| 168 |
} |
| 169 |
else |
| 170 |
{ |
| 171 |
DEBUG(("Directory \"%s\" does not exist -- creating\n", dirname)); |
| 172 |
if ((mkdir(dirname, DIR_MODE) < 0) && (errno != EEXIST)) |
| 173 |
#ifndef _WIN32 |
| 174 |
{ |
| 175 |
#else |
| 176 |
if ((mkdir(dirname) < 0) && (errno != EEXIST)) |
| 177 |
#endif |
| 178 |
perror(dirname); |
| 179 |
exit(2); |
| 180 |
} |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
#ifndef CHECK_ALL_PREFIX_DIRS |
| 185 |
strcpy(lastpath, dirname); |
| 186 |
#endif |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
void |
| 194 |
create_link(char *pfilename, |
| 195 |
const char *linkname, mode_t linktype, |
| 196 |
const char *prevlinkname) |
| 197 |
{ |
| 198 |
struct stat stat_buf; |
| 199 |
|
| 200 |
if (stat(prevlinkname, &stat_buf) == 0) |
| 201 |
{ |
| 202 |
unlink(prevlinkname); |
| 203 |
} |
| 204 |
if (stat(linkname, &stat_buf) == 0) |
| 205 |
{ |
| 206 |
if (prevlinkname) { |
| 207 |
rename(linkname, prevlinkname); |
| 208 |
} |
| 209 |
else { |
| 210 |
unlink(linkname); |
| 211 |
} |
| 212 |
} |
| 213 |
#ifndef _WIN32 |
| 214 |
if (linktype == S_IFLNK) |
| 215 |
{ |
| 216 |
symlink(pfilename, linkname); |
| 217 |
} |
| 218 |
else |
| 219 |
{ |
| 220 |
link(pfilename, linkname); |
| 221 |
} |
| 222 |
#else |
| 223 |
fprintf(stderr, "Creating link from %s to %s not supported", pfilename, linkname); |
| 224 |
#endif |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
PERIODICITY |
| 232 |
determine_periodicity(char *spec) |
| 233 |
{ |
| 234 |
PERIODICITY periodicity = ONCE_ONLY; |
| 235 |
char ch; |
| 236 |
|
| 237 |
DEBUG(("Determining periodicity of \"%s\"\n", spec)); |
| 238 |
while ((ch = *spec++) != 0) |
| 239 |
{ |
| 240 |
if (ch == '%') |
| 241 |
{ |
| 242 |
ch = *spec++; |
| 243 |
if (!ch) break; |
| 244 |
|
| 245 |
switch (ch) |
| 246 |
{ |
| 247 |
case 'y': |
| 248 |
case 'Y': |
| 249 |
if (periodicity > YEARLY) |
| 250 |
{ |
| 251 |
DEBUG(("%%%c -> yearly\n", ch)); |
| 252 |
periodicity = YEARLY; |
| 253 |
} |
| 254 |
break; |
| 255 |
|
| 256 |
case 'b': |
| 257 |
case 'h': |
| 258 |
case 'B': |
| 259 |
case 'm': |
| 260 |
|
| 261 |
if (periodicity > MONTHLY) |
| 262 |
{ |
| 263 |
DEBUG(("%%%c -> monthly\n", ch)); |
| 264 |
periodicity = MONTHLY; |
| 265 |
} |
| 266 |
break; |
| 267 |
|
| 268 |
case 'U': |
| 269 |
case 'W': |
| 270 |
if (periodicity > WEEKLY) |
| 271 |
{ |
| 272 |
DEBUG(("%%%c -> weeky\n", ch)); |
| 273 |
periodicity = WEEKLY; |
| 274 |
weeks_start_on_mondays = (ch == 'W'); |
| 275 |
} |
| 276 |
break; |
| 277 |
|
| 278 |
case 'a': |
| 279 |
case 'A': |
| 280 |
case 'd': |
| 281 |
case 'e': |
| 282 |
case 'j': |
| 283 |
case 'w': |
| 284 |
case 'D': |
| 285 |
case 'x': |
| 286 |
if (periodicity > DAILY) |
| 287 |
{ |
| 288 |
DEBUG(("%%%c -> daily\n", ch)); |
| 289 |
periodicity = DAILY; |
| 290 |
} |
| 291 |
break; |
| 292 |
|
| 293 |
case 'H': |
| 294 |
case 'I': |
| 295 |
case 'p': |
| 296 |
if (periodicity > HOURLY) |
| 297 |
{ |
| 298 |
DEBUG(("%%%c -> hourly\n", ch)); |
| 299 |
periodicity = HOURLY; |
| 300 |
} |
| 301 |
break; |
| 302 |
|
| 303 |
case 'M': |
| 304 |
if (periodicity > PER_MINUTE) |
| 305 |
{ |
| 306 |
DEBUG(("%%%c -> per minute\n", ch)); |
| 307 |
periodicity = PER_MINUTE; |
| 308 |
} |
| 309 |
break; |
| 310 |
|
| 311 |
case 'S': |
| 312 |
case 's': |
| 313 |
case 'c': |
| 314 |
case 'T': |
| 315 |
case 'r': |
| 316 |
case 'R': |
| 317 |
DEBUG(("%%%c -> per second", ch)); |
| 318 |
periodicity = PER_SECOND; |
| 319 |
|
| 320 |
default: |
| 321 |
DEBUG(("ignoring %%%c\n", ch)); |
| 322 |
break; |
| 323 |
} |
| 324 |
} |
| 325 |
} |
| 326 |
return periodicity; |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
PERIODICITY |
| 332 |
parse_timespec(char *optarg, int *p_period_multiple) |
| 333 |
{ |
| 334 |
PERIODICITY periodicity = INVALID_PERIOD; |
| 335 |
int period_multiple = 1; |
| 336 |
char *p = optarg; |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
while (isspace(*p)) { p++; } |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
if (isdigit(*p)) { |
| 346 |
period_multiple = *p++ - '0'; |
| 347 |
|
| 348 |
while (isdigit(*p)) { |
| 349 |
period_multiple *= 10; |
| 350 |
period_multiple += (*p++ - '0'); |
| 351 |
} |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
while (isspace(*p)) { p++; } |
| 358 |
|
| 359 |
if (strncasecmp(p, "sec", 3) == 0) { |
| 360 |
if (period_multiple < 60) { |
| 361 |
periodicity = PER_SECOND; |
| 362 |
} |
| 363 |
} |
| 364 |
else if (strncasecmp(p, "min", 3) == 0) { |
| 365 |
if (period_multiple < 60) { |
| 366 |
periodicity = PER_MINUTE; |
| 367 |
} |
| 368 |
} |
| 369 |
else if (strncasecmp(p, "hour", 4) == 0) { |
| 370 |
if (period_multiple < 24) { |
| 371 |
periodicity = HOURLY; |
| 372 |
} |
| 373 |
} |
| 374 |
else if (strncasecmp(p, "day", 3) == 0) { |
| 375 |
if (period_multiple <= 31) { |
| 376 |
periodicity = DAILY; |
| 377 |
} |
| 378 |
} |
| 379 |
else if (strncasecmp(p, "week", 4) == 0) { |
| 380 |
if (period_multiple < 53) { |
| 381 |
periodicity = WEEKLY; |
| 382 |
} |
| 383 |
} |
| 384 |
else if (strncasecmp(p, "mon", 3) == 0) { |
| 385 |
if (period_multiple <= 12) { |
| 386 |
periodicity = MONTHLY; |
| 387 |
} |
| 388 |
} |
| 389 |
*p_period_multiple = period_multiple; |
| 390 |
return periodicity; |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
time_t |
| 401 |
start_of_next_period(time_t time_now, PERIODICITY periodicity, int period_multiple) |
| 402 |
{ |
| 403 |
time_t start_time; |
| 404 |
|
| 405 |
switch (periodicity) |
| 406 |
{ |
| 407 |
case YEARLY: |
| 408 |
start_time = (time_now + 366 * SECS_PER_DAY + DST_ALLOWANCE); |
| 409 |
break; |
| 410 |
|
| 411 |
case MONTHLY: |
| 412 |
start_time = (time_now + 31 * SECS_PER_DAY + DST_ALLOWANCE); |
| 413 |
break; |
| 414 |
|
| 415 |
case WEEKLY: |
| 416 |
start_time = (time_now + SECS_PER_WEEK + DST_ALLOWANCE); |
| 417 |
break; |
| 418 |
|
| 419 |
case DAILY: |
| 420 |
start_time = (time_now + SECS_PER_DAY + DST_ALLOWANCE); |
| 421 |
break; |
| 422 |
|
| 423 |
case HOURLY: |
| 424 |
start_time = time_now + period_multiple * SECS_PER_HOUR + LEAP_SECOND_ALLOWANCE; |
| 425 |
break; |
| 426 |
|
| 427 |
case PER_MINUTE: |
| 428 |
start_time = time_now + period_multiple * SECS_PER_MIN + LEAP_SECOND_ALLOWANCE; |
| 429 |
break; |
| 430 |
|
| 431 |
case PER_SECOND: |
| 432 |
start_time = time_now + 1; |
| 433 |
break; |
| 434 |
|
| 435 |
default: |
| 436 |
start_time = FAR_DISTANT_FUTURE; |
| 437 |
break; |
| 438 |
} |
| 439 |
return start_of_this_period(start_time, periodicity, period_multiple); |
| 440 |
} |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
time_t |
| 450 |
start_of_this_period(time_t start_time, PERIODICITY periodicity, int period_multiple) |
| 451 |
{ |
| 452 |
struct tm tm_initial; |
| 453 |
struct tm tm_adjusted; |
| 454 |
int expected_mday; |
| 455 |
|
| 456 |
#ifndef _WIN32 |
| 457 |
localtime_r(&start_time, &tm_initial); |
| 458 |
#else |
| 459 |
struct tm * tempTime; |
| 460 |
|
| 461 |
tempTime = localtime(&start_time); |
| 462 |
if (NULL != tempTime) |
| 463 |
{ |
| 464 |
memcpy(&tm_initial, tempTime, sizeof(struct tm)); |
| 465 |
|
| 466 |
free(tempTime); |
| 467 |
tempTime = NULL; |
| 468 |
} |
| 469 |
#endif |
| 470 |
switch (periodicity) |
| 471 |
{ |
| 472 |
case YEARLY: |
| 473 |
case MONTHLY: |
| 474 |
case WEEKLY: |
| 475 |
case DAILY: |
| 476 |
switch (periodicity) |
| 477 |
{ |
| 478 |
case YEARLY: |
| 479 |
start_time -= ( (tm_initial.tm_yday * SECS_PER_DAY) |
| 480 |
+ (tm_initial.tm_hour * SECS_PER_HOUR) |
| 481 |
+ (tm_initial.tm_min * SECS_PER_MIN) |
| 482 |
+ (tm_initial.tm_sec)); |
| 483 |
expected_mday = 1; |
| 484 |
break; |
| 485 |
|
| 486 |
case MONTHLY: |
| 487 |
start_time -= ( ((tm_initial.tm_mday - 1) * SECS_PER_DAY) |
| 488 |
+ ( tm_initial.tm_hour * SECS_PER_HOUR) |
| 489 |
+ ( tm_initial.tm_min * SECS_PER_MIN) |
| 490 |
+ ( tm_initial.tm_sec)); |
| 491 |
expected_mday = 1; |
| 492 |
break; |
| 493 |
|
| 494 |
case WEEKLY: |
| 495 |
if (weeks_start_on_mondays) |
| 496 |
{ |
| 497 |
tm_initial.tm_wday = (6 + tm_initial.tm_wday) % 7; |
| 498 |
} |
| 499 |
start_time -= ( (tm_initial.tm_wday * SECS_PER_DAY) |
| 500 |
+ (tm_initial.tm_hour * SECS_PER_HOUR) |
| 501 |
+ (tm_initial.tm_min * SECS_PER_MIN) |
| 502 |
+ (tm_initial.tm_sec)); |
| 503 |
expected_mday = tm_initial.tm_mday; |
| 504 |
break; |
| 505 |
|
| 506 |
case DAILY: |
| 507 |
start_time -= ( (tm_initial.tm_hour * SECS_PER_HOUR) |
| 508 |
+ (tm_initial.tm_min * SECS_PER_MIN ) |
| 509 |
+ tm_initial.tm_sec); |
| 510 |
expected_mday = tm_initial.tm_mday; |
| 511 |
break; |
| 512 |
|
| 513 |
default: |
| 514 |
fprintf(stderr, "software fault in start_of_this_period()\n"); |
| 515 |
exit(1); |
| 516 |
} |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
#ifndef _WIN32 |
| 526 |
localtime_r(&start_time, &tm_adjusted); |
| 527 |
#else |
| 528 |
tempTime = localtime(&start_time); |
| 529 |
if (NULL != tempTime) |
| 530 |
{ |
| 531 |
memcpy(&tm_adjusted, tempTime, sizeof(struct tm)); |
| 532 |
|
| 533 |
free(tempTime); |
| 534 |
tempTime = NULL; |
| 535 |
} |
| 536 |
#endif |
| 537 |
if ( (tm_adjusted.tm_hour != 0) |
| 538 |
|| (tm_adjusted.tm_min != 0) |
| 539 |
|| (tm_adjusted.tm_sec != 0)) |
| 540 |
{ |
| 541 |
char sign = '-'; |
| 542 |
time_t adjust = - ( (tm_adjusted.tm_hour * SECS_PER_HOUR) |
| 543 |
+ (tm_adjusted.tm_min * SECS_PER_MIN) |
| 544 |
+ (tm_adjusted.tm_sec)); |
| 545 |
|
| 546 |
if (tm_adjusted.tm_mday != expected_mday) |
| 547 |
{ |
| 548 |
adjust += SECS_PER_DAY; |
| 549 |
sign = '+'; |
| 550 |
} |
| 551 |
start_time += adjust; |
| 552 |
|
| 553 |
if (adjust < 0) |
| 554 |
{ |
| 555 |
adjust = -adjust; |
| 556 |
} |
| 557 |
|
| 558 |
DEBUG(("Adjust for dst: %02d/%02d/%04d %02d:%02d:%02d -- %c%0d:%02d:%02d\n", |
| 559 |
tm_initial.tm_mday, tm_initial.tm_mon+1, tm_initial.tm_year+1900, |
| 560 |
tm_initial.tm_hour, tm_initial.tm_min, tm_initial.tm_sec, sign, |
| 561 |
adjust / SECS_PER_HOUR, (adjust / 60) % 60, adjust % SECS_PER_HOUR)); |
| 562 |
} |
| 563 |
break; |
| 564 |
|
| 565 |
case HOURLY: |
| 566 |
start_time -= (tm_initial.tm_sec + tm_initial.tm_min * SECS_PER_MIN); |
| 567 |
if (period_multiple > 1) { |
| 568 |
start_time -= SECS_PER_HOUR * (tm_initial.tm_hour - |
| 569 |
period_multiple * (tm_initial.tm_hour / period_multiple)); |
| 570 |
} |
| 571 |
break; |
| 572 |
|
| 573 |
case PER_MINUTE: |
| 574 |
start_time -= tm_initial.tm_sec; |
| 575 |
if (period_multiple > 1) { |
| 576 |
start_time -= SECS_PER_MIN * (tm_initial.tm_min - |
| 577 |
period_multiple * (tm_initial.tm_min / period_multiple)); |
| 578 |
} |
| 579 |
break; |
| 580 |
|
| 581 |
case PER_SECOND: |
| 582 |
default: |
| 583 |
break; |
| 584 |
} |
| 585 |
return start_time; |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
time_t |
| 594 |
mktime_from_utc(struct tm *t) |
| 595 |
{ |
| 596 |
time_t tl, tb; |
| 597 |
|
| 598 |
tl = mktime(t); |
| 599 |
tb = mktime(gmtime(&tl)); |
| 600 |
return (tl <= tb ? (tl + (tl - tb)) : (tl - (tb - tl))); |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
static int |
| 608 |
check_end(const char *p) |
| 609 |
{ |
| 610 |
if (!p) |
| 611 |
return 0; |
| 612 |
while (isspace(*p)) |
| 613 |
++p; |
| 614 |
if (!*p || (p[0] == 'G' && p[1] == 'M' && p[2] == 'T')) |
| 615 |
return 1; |
| 616 |
else |
| 617 |
return 0; |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
static char *european_date_formats[] = |
| 629 |
{ |
| 630 |
"%d %b %Y %T", |
| 631 |
"%d %b %Y %H:%M", |
| 632 |
"%d %b %Y", |
| 633 |
"%d-%b-%Y %T", |
| 634 |
"%d-%b-%Y %H:%M", |
| 635 |
"%d-%b-%y %T", |
| 636 |
"%d-%b-%y %H:%M", |
| 637 |
"%d-%b-%Y", |
| 638 |
"%b %d %T %Y", |
| 639 |
"%b %d %Y", |
| 640 |
NULL |
| 641 |
}; |
| 642 |
|
| 643 |
static char *american_date_formats[] = |
| 644 |
{ |
| 645 |
"%b %d %Y %T", |
| 646 |
"%b %d %Y %H:%M", |
| 647 |
"%b %d %Y", |
| 648 |
"%b-%d-%Y %T", |
| 649 |
"%b-%d-%Y %H:%M", |
| 650 |
"%b-%d-%Y", |
| 651 |
"%b/%d/%Y %T", |
| 652 |
"%b/%d/%Y %H:%M", |
| 653 |
"%b/%d/%Y", |
| 654 |
NULL |
| 655 |
}; |
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
time_t |
| 660 |
parse_time(char *time_str, int use_american_date_formats) |
| 661 |
{ |
| 662 |
struct tm tm; |
| 663 |
char **date_formats; |
| 664 |
|
| 665 |
memset(&tm, 0, sizeof (tm)); |
| 666 |
tm.tm_isdst = -1; |
| 667 |
|
| 668 |
|
| 669 |
for (date_formats = (use_american_date_formats |
| 670 |
? american_date_formats |
| 671 |
: european_date_formats); |
| 672 |
*date_formats; |
| 673 |
date_formats++) |
| 674 |
{ |
| 675 |
if (check_end((const char *)strptime(time_str, *date_formats, &tm))) |
| 676 |
return mktime_from_utc(&tm); |
| 677 |
} |
| 678 |
|
| 679 |
return -1; |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
void |
| 687 |
print_debug_msg(char *msg, ...) |
| 688 |
{ |
| 689 |
va_list ap; |
| 690 |
|
| 691 |
va_start(ap, msg); |
| 692 |
vfprintf(debug_file, msg, ap); |
| 693 |
} |
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
char * |
| 700 |
timestamp(time_t thetime) |
| 701 |
{ |
| 702 |
static int index = 0; |
| 703 |
static char buffer[4][80]; |
| 704 |
struct tm *tm; |
| 705 |
char *retval; |
| 706 |
|
| 707 |
retval = buffer[index++]; |
| 708 |
index %= 4; |
| 709 |
|
| 710 |
tm = localtime(&thetime); |
| 711 |
strftime(retval, 80, "%Y/%m/%d-%H:%M:%S %Z", tm); |
| 712 |
return retval; |
| 713 |
} |
| 714 |
|
| 715 |
|