SDDSlib
Loading...
Searching...
No Matches
logfile_gener.c File Reference

This file provides functions for creating time-based filenames, timestamps, and for breaking down and retrieving the current time in various formats. More...

#include "mdb.h"
#include <unistd.h>
#include <time.h>

Go to the source code of this file.

Functions

char * makeTimeStamp (double Time)
 Create a human-readable timestamp from the given time in seconds since the Epoch.
 
void getTimeBreakdown (double *ptrTime, double *ptrDay, double *ptrHour, double *ptrJulianDay, double *ptrMonth, double *ptrYear, char **ptrTimeStamp)
 Retrieve detailed time breakdown (day, hour, julian day, month, year, and timestamp).
 
double getHourOfDay ()
 Get the current hour of the day (0-23, possibly fractional).
 
void makeTimeBreakdown (double Time, double *ptrTime, double *ptrDay, double *ptrHour, double *ptrJulianDay, double *ptrMonth, double *ptrYear, char **ptrTimeStamp)
 Break down a given time into multiple components (time, day, hour, Julian day, month, year, and timestamp).
 
double computeYearStartTime (double StartTime)
 Compute the start time of the year for the given time.
 
double getTimeInSecs ()
 Get the current time in seconds since the Epoch with high resolution.
 
long double getLongDoubleTimeInSecs ()
 Get the current time in seconds since the Epoch as a long double for higher precision.
 
char * MakeGenerationFilename (char *rootname, long digits, char *delimiter, char *lastFile)
 Generate a new filename with an incremented index based on a root name and delimiter.
 
char * MakeSCRDailyTimeGenerationFilename (char *rootname)
 Generate a new daily filename with a timestamp based on the current date and time.
 
char * MakeDailyGenerationFilename (char *rootname, long digits, char *delimiter, long timetag)
 Generate a new daily filename. Can include a time tag or a numeric index.
 
char * MakeMonthlyGenerationFilename (char *rootname, long digits, char *delimiter, long timetag)
 Generate a new monthly filename. Can include a time tag or a numeric index.
 
void usleepSystemIndependent (long usec)
 Sleep for a given number of microseconds, system-independently.
 
char * getHourMinuteSecond ()
 Get the current hour, minute, and second as a string.
 
void checkGenerationFileLocks (char *match_date)
 Check for matching date-based generation files and ensure none are locked.
 
void TouchFile (char *filename)
 Update the modification timestamp of a file if it exists.
 

Variables

static long daysInMonth [12]
 

Detailed Description

This file provides functions for creating time-based filenames, timestamps, and for breaking down and retrieving the current time in various formats.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, R. Soliday

Definition in file logfile_gener.c.

Function Documentation

◆ checkGenerationFileLocks()

void checkGenerationFileLocks ( char * match_date)

Check for matching date-based generation files and ensure none are locked.

Parameters
match_dateDate pattern to match.

Definition at line 651 of file logfile_gener.c.

651 {
652#if !defined(vxWorks) && !defined(__rtems__) && !defined(__CYGWIN__)
653 char comm[1024], filename[2048], buffer[1024];
654 FILE *handle, *fp;
655
656 sprintf(comm, "ls %s* 2> /dev/stdout", match_date);
657 if (!(handle = popen(comm, "r"))) {
658 fprintf(stderr, "Error: no data returned from popen call\n");
659 exit(1);
660 }
661 while (!feof(handle)) {
662 if (fgets(filename, sizeof(filename), handle)) {
663 if (filename[strlen(filename) - 1] == '\n') {
664 filename[strlen(filename) - 1] = 0;
665 }
666 if (!(fp = fopen(filename, "r")))
667 continue;
668 if (lockf(fileno(fp), F_TEST, 0) == -1) {
669 /* file exists and is locked */
670 fclose(fp);
671 sprintf(buffer, "aborting--previous generation %s is still active",
672 filename);
673 fprintf(stderr, "Warning: %s\n", buffer);
674 exit(0);
675 }
676 fclose(fp);
677 }
678 }
679#endif
680}

◆ computeYearStartTime()

double computeYearStartTime ( double StartTime)

Compute the start time of the year for the given time.

Parameters
StartTimeTime in seconds since the Epoch.
Returns
Start-of-year time in seconds since the Epoch.

Definition at line 205 of file logfile_gener.c.

205 {
206 struct tm *YearStart;
207 time_t intTime;
208
209 intTime = StartTime;
210 YearStart = localtime(&intTime);
211 YearStart->tm_sec = 0;
212 YearStart->tm_min = 0;
213 YearStart->tm_hour = 0;
214 YearStart->tm_mday = 1;
215 YearStart->tm_mon = 0;
216#if defined(SUNOS4)
217 return (double)timelocal(YearStart);
218#else
219 return (double)mktime(YearStart);
220#endif
221}

◆ getHourMinuteSecond()

char * getHourMinuteSecond ( )

Get the current hour, minute, and second as a string.

Returns
Pointer to a static string (e.g., "HH:MM:SS").

Definition at line 629 of file logfile_gener.c.

629 {
630 time_t now;
631 char *Hour, *ptr;
632 int i = 0;
633
634 now = time(NULL);
635 Hour = ctime(&now);
636 ptr = strtok(Hour, " ");
637 i++;
638 while (ptr != NULL) {
639 if (i == 4)
640 break;
641 ptr = strtok(NULL, " ");
642 i++;
643 }
644 return ptr;
645}

◆ getHourOfDay()

double getHourOfDay ( )

Get the current hour of the day (0-23, possibly fractional).

Returns
Hour of the day.

Definition at line 116 of file logfile_gener.c.

116 {
117 double theTime, hour;
118 theTime = getTimeInSecs(); /* may get more precision than time() offers */
119 makeTimeBreakdown(theTime, NULL, NULL, &hour, NULL, NULL, NULL, NULL);
120 return hour;
121}
void makeTimeBreakdown(double Time, double *ptrTime, double *ptrDay, double *ptrHour, double *ptrJulianDay, double *ptrMonth, double *ptrYear, char **ptrTimeStamp)
Break down a given time into multiple components (time, day, hour, Julian day, month,...
double getTimeInSecs()
Get the current time in seconds since the Epoch with high resolution.

◆ getLongDoubleTimeInSecs()

long double getLongDoubleTimeInSecs ( )

Get the current time in seconds since the Epoch as a long double for higher precision.

Returns
Current time in seconds as a long double.

Definition at line 300 of file logfile_gener.c.

300 {
301#if defined(_WIN32)
302 struct timespecoag tp;
303 clock_gettime_oag(&tp);
304 return ((long double)tp.tv_sec) + ((long double)tp.tv_nsec) * 1e-9L;
305#endif
306
307#if defined(__APPLE__) /* This is only needed until I compile on MacOS 10.12 */
308# include <sys/time.h>
309 struct timeval tv;
310 gettimeofday(&tv, NULL);
311 return ((long double)tv.tv_sec) + ((long double)tv.tv_usec) * 1e-6L;
312#endif
313
314#if !defined(_WIN32) && !defined(__APPLE__)
315# include <time.h>
316 struct timespec tp;
317 clock_gettime(CLOCK_REALTIME, &tp);
318 return ((long double)tp.tv_sec) + ((long double)tp.tv_nsec) * 1e-9L;
319#endif
320}

◆ getTimeBreakdown()

void getTimeBreakdown ( double * ptrTime,
double * ptrDay,
double * ptrHour,
double * ptrJulianDay,
double * ptrMonth,
double * ptrYear,
char ** ptrTimeStamp )

Retrieve detailed time breakdown (day, hour, julian day, month, year, and timestamp).

Parameters
ptrTimeIf not NULL, stores the time in seconds since the Epoch.
ptrDayIf not NULL, stores the day of the month (fractional).
ptrHourIf not NULL, stores the hour of the day (fractional).
ptrJulianDayIf not NULL, stores the Julian day (fractional).
ptrMonthIf not NULL, stores the month of the year (fractional).
ptrYearIf not NULL, stores the year (fractional).
ptrTimeStampIf not NULL, stores a pointer to a timestamp string.

Definition at line 103 of file logfile_gener.c.

105 {
106 double theTime;
107 theTime = getTimeInSecs(); /* may get more precision than time() offers */
108 makeTimeBreakdown(theTime, ptrTime, ptrDay, ptrHour, ptrJulianDay,
109 ptrMonth, ptrYear, ptrTimeStamp);
110}

◆ getTimeInSecs()

double getTimeInSecs ( )

Get the current time in seconds since the Epoch with high resolution.

Returns
Current time in seconds.

Definition at line 274 of file logfile_gener.c.

274 {
275#if defined(_WIN32)
276 struct timespecoag tp;
277 clock_gettime_oag(&tp);
278 return ((double)tp.tv_sec) + ((double)tp.tv_nsec) * 1e-9;
279#endif
280
281#if defined(__APPLE__) /* This is only needed until I compile on MacOS 10.12 */
282# include <sys/time.h>
283 struct timeval tv;
284 gettimeofday(&tv, NULL);
285 return ((double)tv.tv_sec) + ((double)tv.tv_usec) * 1e-6;
286#endif
287
288#if !defined(_WIN32) && !defined(__APPLE__)
289# include <time.h>
290 struct timespec tp;
291 clock_gettime(CLOCK_REALTIME, &tp);
292 return ((double)tp.tv_sec) + ((double)tp.tv_nsec) * 1e-9;
293#endif
294}

◆ MakeDailyGenerationFilename()

char * MakeDailyGenerationFilename ( char * rootname,
long digits,
char * delimiter,
long timetag )

Generate a new daily filename. Can include a time tag or a numeric index.

Parameters
rootnameBase name for the file.
digitsNumber of digits for the index.
delimiterDelimiter between parts of the filename.
timetagIf non-zero, includes a time tag in the filename.
Returns
Newly allocated string containing the daily generated filename.

Definition at line 432 of file logfile_gener.c.

432 {
433#if !defined(vxWorks)
434 char buffer[1024];
435#endif
436 char format[100], filename[1024], *name, *hourNow, match_date[1024];
437 long index = 1;
438 FILE *fp;
439 double dayDbl, jDayDbl, monthDbl, yearDbl, theTime;
440 long day, jDay, month, year;
441
442 if (digits < 0)
443 digits = DEFAULT_GENERATIONS_DIGITS;
444 theTime = getTimeInSecs();
445 makeTimeBreakdown(theTime, NULL, &dayDbl, NULL, &jDayDbl, &monthDbl, &yearDbl, NULL);
446 day = dayDbl;
447 jDay = jDayDbl;
448 month = monthDbl;
449 year = yearDbl;
450
451 if (timetag) {
452 hourNow = getHourMinuteSecond();
453 if (rootname && strlen(rootname) > 0)
454 sprintf(match_date, "%s-%4ld-%03ld-%02ld%02ld", rootname, year, jDay, month, day);
455 else
456 sprintf(match_date, "%4ld-%03ld-%02ld%02ld", year, jDay, month, day);
457 checkGenerationFileLocks(match_date);
458 if (rootname && strlen(rootname) > 0)
459 sprintf(filename, "%s-%4ld-%03ld-%02ld%02ld.%s", rootname,
460 year, jDay, month, day, hourNow);
461 else
462 sprintf(filename, "%4ld-%03ld-%02ld%02ld.%s", year, jDay, month, day, hourNow);
463 } else {
464 if (!digits) {
465 if (rootname && strlen(rootname) > 0)
466 sprintf(filename, "%s-%4ld-%03ld-%02ld%02ld", rootname, year, jDay, month, day);
467 else
468 sprintf(filename, "%4ld-%03ld-%02ld%02ld", year, jDay, month, day);
469 if ((fp = fopen(filename, "r"))) {
470#if !defined(vxWorks) && !defined(__rtems__) && !defined(__CYGWIN__)
471 if (lockf(fileno(fp), F_TEST, 0) == -1) {
472 /* file exists and is locked */
473 fclose(fp);
474 sprintf(buffer, "aborting--previous generation of %s is still active", filename);
475 fprintf(stderr, "Warning: %s\n", buffer);
476 exit(0);
477 }
478#endif
479 }
480 } else {
481 if (!delimiter || strlen(delimiter) == 0)
482 return NULL;
483 if (rootname && strlen(rootname) > 0)
484 sprintf(format, "%s-%%4ld-%%03ld-%%02ld%%02ld%s%%0%ldld", rootname, delimiter, digits);
485 else
486 sprintf(format, "%%4ld-%%03ld-%%02ld%%02ld%s%%0%ldld", delimiter, digits);
487 do {
488 sprintf(filename, format, year, jDay, month, day, index);
489 index++;
490 if (!(fp = fopen(filename, "r")))
491 break;
492 theTime = getTimeInSecs();
493 makeTimeBreakdown(theTime, NULL, &dayDbl, NULL, &jDayDbl, &monthDbl, &yearDbl, NULL);
494 day = dayDbl;
495 jDay = jDayDbl;
496 month = monthDbl;
497 year = yearDbl;
498#if !defined(vxWorks) && !defined(__rtems__) && !defined(__CYGWIN__)
499 if (lockf(fileno(fp), F_TEST, 0) == -1) {
500 /* file exists and is locked */
501 fclose(fp);
502 sprintf(buffer, "aborting--previous generation of %s (%s) is still active", rootname,
503 filename);
504 fprintf(stderr, "Warning: %s\n", buffer);
505 exit(0);
506 }
507#endif
508 fclose(fp);
509 } while (1);
510 }
511 }
512 if (!(name = malloc(sizeof(*name) * (strlen(filename) + 1)))) {
513 fprintf(stderr, "Error: memory allocation failure making generation filename\n");
514 exit(1);
515 }
516 return strcpy(name, filename);
517}
void checkGenerationFileLocks(char *match_date)
Check for matching date-based generation files and ensure none are locked.
char * getHourMinuteSecond()
Get the current hour, minute, and second as a string.

◆ MakeGenerationFilename()

char * MakeGenerationFilename ( char * rootname,
long digits,
char * delimiter,
char * lastFile )

Generate a new filename with an incremented index based on a root name and delimiter.

Parameters
rootnameBase name for the file.
digitsNumber of digits to use for the index.
delimiterDelimiter between root name and index.
lastFileLast generated filename, used to determine the next index.
Returns
Newly allocated string containing the generated filename.

Definition at line 330 of file logfile_gener.c.

330 {
331 char format[100], filename[1024], buffer[1024], *name, *ptr, *ptr1;
332 long index = 1;
333 FILE *fp;
334
335 if (!rootname || strlen(rootname) == 0)
336 return NULL;
337 if (digits < 1)
338 digits = DEFAULT_GENERATIONS_DIGITS;
339
340 if (lastFile && strlen(lastFile)) {
341 ptr1 = lastFile;
342 ptr = NULL;
343 while ((ptr1 = strstr(ptr1, delimiter))) {
344 ptr = ptr1;
345 ptr1 += 1;
346 }
347 if (ptr) {
348 ptr += strlen(delimiter);
349 while (*ptr == '0')
350 ptr++;
351 if (sscanf(ptr, "%ld", &index) != 1) {
352 sprintf(buffer, "Error scanning name of last file: %s", lastFile);
353 fprintf(stderr, "Error: %s\n", buffer);
354 exit(1);
355 }
356 } else {
357 sprintf(buffer, "Error scanning name of last file: %s", lastFile);
358 fprintf(stderr, "Error: %s\n", buffer);
359 exit(1);
360 }
361 if (!fexists(lastFile))
362 index += 1; /* avoids reuse of the file even if it has been deleted */
363 }
364
365 sprintf(format, "%%s%s%%0%ldld", delimiter, digits);
366
367 do {
368 sprintf(filename, format, rootname, index);
369 index++;
370 if (!(fp = fopen(filename, "r")))
371 break;
372#if !defined(vxWorks) && !defined(__rtems__) && !defined(__CYGWIN__)
373 if (lockf(fileno(fp), F_TEST, 0) == -1) {
374 /* file exists and is locked */
375 fclose(fp);
376 sprintf(buffer, "aborting--previous generation of %s (%s) is still active", rootname,
377 filename);
378 fprintf(stderr, "Warning: %s\n", buffer);
379 exit(0);
380 }
381#endif
382 fclose(fp);
383 } while (1);
384 if (!(name = malloc(sizeof(*name) * (strlen(filename) + 1)))) {
385 fprintf(stderr, "Error: memory allocation failure making generation filename\n");
386 exit(1);
387 }
388 return strcpy(name, filename);
389}
long fexists(const char *filename)
Checks if a file exists.
Definition fexists.c:27

◆ MakeMonthlyGenerationFilename()

char * MakeMonthlyGenerationFilename ( char * rootname,
long digits,
char * delimiter,
long timetag )

Generate a new monthly filename. Can include a time tag or a numeric index.

Parameters
rootnameBase name for the file.
digitsNumber of digits for the index.
delimiterDelimiter between parts of the filename.
timetagIf non-zero, includes a time tag in the filename.
Returns
Newly allocated string containing the monthly generated filename.

Definition at line 527 of file logfile_gener.c.

527 {
528#if !defined(vxWorks)
529 char buffer[1024];
530#endif
531 char format[100], filename[1024], *name, *hourNow, match_date[1024];
532 long index = 1;
533 FILE *fp;
534 double dayDbl, jDayDbl, monthDbl, yearDbl, theTime;
535 long month, year;
536
537 if (digits < 0)
538 digits = DEFAULT_GENERATIONS_DIGITS;
539 theTime = getTimeInSecs();
540 makeTimeBreakdown(theTime, NULL, &dayDbl, NULL, &jDayDbl, &monthDbl, &yearDbl, NULL);
541 month = monthDbl;
542 year = yearDbl;
543
544 if (timetag) {
545 hourNow = getHourMinuteSecond();
546 if (rootname && strlen(rootname) > 0)
547 sprintf(match_date, "%s-%4ld-%02ld", rootname, year, month);
548 else
549 sprintf(match_date, "%4ld-%02ld", year, month);
550 checkGenerationFileLocks(match_date);
551 if (rootname && strlen(rootname) > 0)
552 sprintf(filename, "%s-%4ld-%02ld.%s", rootname,
553 year, month, hourNow);
554 else
555 sprintf(filename, "%4ld-%02ld.%s", year, month, hourNow);
556 } else {
557 if (!digits) {
558 if (rootname && strlen(rootname) > 0)
559 sprintf(filename, "%s-%4ld-%02ld", rootname, year, month);
560 else
561 sprintf(filename, "%4ld-%02ld", year, month);
562 if ((fp = fopen(filename, "r"))) {
563#if !defined(vxWorks) && !defined(__rtems__) && !defined(__CYGWIN__)
564 if (lockf(fileno(fp), F_TEST, 0) == -1) {
565 /* file exists and is locked */
566 fclose(fp);
567 sprintf(buffer, "aborting--previous generation of %s is still active", filename);
568 fprintf(stderr, "Warning: %s\n", buffer);
569 exit(0);
570 }
571#endif
572 }
573 } else {
574 if (!delimiter || strlen(delimiter) == 0)
575 return NULL;
576 if (rootname && strlen(rootname) > 0)
577 sprintf(format, "%s-%%4ld-%%02ld%s%%0%ldld", rootname, delimiter, digits);
578 else
579 sprintf(format, "%%4ld-%%02ld%s%%0%ldld", delimiter, digits);
580 do {
581 sprintf(filename, format, year, month, index);
582 index++;
583 if (!(fp = fopen(filename, "r")))
584 break;
585 /* theTime = getTimeInSecs(); */
586 /* makeTimeBreakdown(theTime, NULL, &dayDbl, NULL, &jDayDbl, &monthDbl, &yearDbl, NULL); */
587 /* month = monthDbl; */
588 /* year = yearDbl; */
589#if !defined(vxWorks) && !defined(__rtems__) && !defined(__CYGWIN__)
590 if (lockf(fileno(fp), F_TEST, 0) == -1) {
591 /* file exists and is locked */
592 fclose(fp);
593 sprintf(buffer, "aborting--previous generation of %s (%s) is still active", rootname,
594 filename);
595 fprintf(stderr, "Warning: %s\n", buffer);
596 exit(0);
597 }
598#endif
599 fclose(fp);
600 } while (1);
601 }
602 }
603 if (!(name = malloc(sizeof(*name) * (strlen(filename) + 1)))) {
604 fprintf(stderr, "Error: memory allocation failure making generation filename\n");
605 exit(1);
606 }
607 return strcpy(name, filename);
608}

◆ MakeSCRDailyTimeGenerationFilename()

char * MakeSCRDailyTimeGenerationFilename ( char * rootname)

Generate a new daily filename with a timestamp based on the current date and time.

Parameters
rootnameBase name for the file.
Returns
Newly allocated string containing the generated filename.

Definition at line 396 of file logfile_gener.c.

396 {
397 char buffer[1024];
398 char filename[1024];
399 char *name;
400 time_t now;
401 struct tm *now1;
402 FILE *fp;
403
404 if (!rootname) {
405 fprintf(stderr, "The rootname is not provided.\n");
406 exit(1);
407 }
408 /*generate a new file name */
409 do {
410 now = time(NULL);
411 now1 = localtime(&now);
412 strftime(buffer, 1024, "%Y-%j-%m%d-%H%M%S", now1);
413 sprintf(filename, "%s%s", rootname, buffer);
414 fp = fopen(filename, "r");
415 } while (fp != NULL);
416
417 if (!(name = malloc(sizeof(*name) * (strlen(filename) + 1)))) {
418 fprintf(stderr, "Error: memory allocation failure making generation filename\n");
419 exit(1);
420 }
421 return strcpy(name, filename);
422}

◆ makeTimeBreakdown()

void makeTimeBreakdown ( double Time,
double * ptrTime,
double * ptrDay,
double * ptrHour,
double * ptrJulianDay,
double * ptrMonth,
double * ptrYear,
char ** ptrTimeStamp )

Break down a given time into multiple components (time, day, hour, Julian day, month, year, and timestamp).

Parameters
TimeTime in seconds since the Epoch.
ptrTimeIf not NULL, stores the input time value.
ptrDayIf not NULL, stores the day of the month (fractional).
ptrHourIf not NULL, stores the hour of the day (fractional).
ptrJulianDayIf not NULL, stores the Julian day (fractional).
ptrMonthIf not NULL, stores the month (fractional).
ptrYearIf not NULL, stores the year (fractional).
ptrTimeStampIf not NULL, stores a timestamp string.

Definition at line 149 of file logfile_gener.c.

151 {
152 double SubSeconds;
153 double Day, Hour, JulianDay, Year;
154 struct tm *tmBreakdown;
155 time_t integerTime;
156 long isLeap;
157
158 if (ptrTime)
159 *ptrTime = Time;
160 if (ptrTimeStamp)
161 *ptrTimeStamp = makeTimeStamp(Time);
162
163 /* get breakdown based on integer part of time */
164 integerTime = (time_t)Time;
165 SubSeconds = Time - integerTime;
166 tmBreakdown = localtime(&integerTime);
167
168 /* time since midnight in hours */
169 Hour = (tmBreakdown->tm_min + (tmBreakdown->tm_sec + SubSeconds) / 60.0) / 60.0 + tmBreakdown->tm_hour;
170 if (ptrHour)
171 *ptrHour = Hour;
172
173 /* time since beginning of month in days (includes partial days) */
174 Day = tmBreakdown->tm_mday + Hour / 24.0;
175 if (ptrDay)
176 *ptrDay = Day;
177
178 /* time since start of year in days (includes partial days) plus 1 day to give Julian convention */
179 JulianDay = tmBreakdown->tm_yday + Hour / 24.0 + 1;
180 if (ptrJulianDay)
181 *ptrJulianDay = JulianDay;
182
183 /* years since 0000 AD, including fractional years */
184 isLeap = 0;
185 tmBreakdown->tm_year += 1900;
186 if ((tmBreakdown->tm_year % 4 == 0 && tmBreakdown->tm_year % 100 != 0) || tmBreakdown->tm_year % 400 == 0)
187 isLeap = 1;
188 Year = tmBreakdown->tm_year + (JulianDay - 1) / (365.0 + isLeap);
189 if (ptrYear)
190 *ptrYear = Year;
191
192 /* time since start of year in 30-day months (includes partial days) */
193 if (ptrMonth) {
194 *ptrMonth = tmBreakdown->tm_mon + 1 +
195 +(1.0 * tmBreakdown->tm_mday - 1) / (daysInMonth[tmBreakdown->tm_mon] +
196 (isLeap && tmBreakdown->tm_mon == 1 ? 1 : 0));
197 }
198}
char * makeTimeStamp(double Time)
Create a human-readable timestamp from the given time in seconds since the Epoch.

◆ makeTimeStamp()

char * makeTimeStamp ( double Time)

Create a human-readable timestamp from the given time in seconds since the Epoch.

Parameters
TimeTime in seconds since the Epoch.
Returns
Pointer to a static string containing the formatted timestamp.

Definition at line 84 of file logfile_gener.c.

84 {
85 time_t intTime;
86 char *TimeStamp;
87 intTime = Time;
88 TimeStamp = ctime(&intTime);
89 TimeStamp[strlen(TimeStamp) - 1] = 0; /* kill newline */
90 return TimeStamp;
91}

◆ TouchFile()

void TouchFile ( char * filename)

Update the modification timestamp of a file if it exists.

Parameters
filenameFile to "touch."

Definition at line 686 of file logfile_gener.c.

686 {
687#if !defined(vxWorks) && !defined(__rtems__)
688 FILE *fp;
689 static FILE *fsh = NULL;
690
691 if (!fsh) {
692 if (!(fsh = popen("csh", "w"))) {
693 fprintf(stderr, "Error: unable to launch csh for touchFile operations\n");
694 exit(1);
695 }
696 }
697 if (filename) {
698 if ((fp = fopen(filename, "r"))) {
699 fclose(fp);
700 fprintf(fsh, "touch %s\n", filename);
701 fflush(fsh);
702 }
703 }
704#endif
705}

◆ usleepSystemIndependent()

void usleepSystemIndependent ( long usec)

Sleep for a given number of microseconds, system-independently.

Parameters
usecNumber of microseconds to sleep.

Definition at line 614 of file logfile_gener.c.

614 {
615#if defined(vxWorks) && !defined(__rtems__)
616 struct timespec rqtp;
617 rqtp.tv_sec = (long)(usec / 1000000);
618 rqtp.tv_nsec = usec % 1000000 * 1000;
619 nanosleep(&rqtp, NULL);
620#else
621 usleep(usec);
622#endif
623}

Variable Documentation

◆ daysInMonth

long daysInMonth[12]
static
Initial value:
= {
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31,
}

Definition at line 123 of file logfile_gener.c.

123 {
124 31,
125 28,
126 31,
127 30,
128 31,
129 30,
130 31,
131 31,
132 30,
133 31,
134 30,
135 31,
136};