-
Notifications
You must be signed in to change notification settings - Fork 0
/
ustdlib.c
1826 lines (1668 loc) · 52 KB
/
ustdlib.c
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//*****************************************************************************
//
// ustdlib.c - Simple standard library functions.
//
// Copyright (c) 2007-2017 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 2.1.4.178 of the Tiva Utility Library.
//
//*****************************************************************************
#include <stdint.h>
#include "driverlib/debug.h"
#include "utils/ustdlib.h"
//*****************************************************************************
//
//! \addtogroup ustdlib_api
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
// A mapping from an integer between 0 and 15 to its ASCII character
// equivalent.
//
//*****************************************************************************
static const char * const g_pcHex = "0123456789abcdef";
//*****************************************************************************
//
//! Copies a certain number of characters from one string to another.
//!
//! \param s1 is a pointer to the destination buffer into which characters
//! are to be copied.
//! \param s2 is a pointer to the string from which characters are to be
//! copied.
//! \param n is the number of characters to copy to the destination buffer.
//!
//! This function copies at most \e n characters from the string pointed to
//! by \e s2 into the buffer pointed to by \e s1. If the end of \e s2 is found
//! before \e n characters have been copied, remaining characters in \e s1
//! will be padded with zeroes until \e n characters have been written. Note
//! that the destination string will only be NULL terminated if the number of
//! characters to be copied is greater than the length of \e s2.
//!
//! \return Returns \e s1.
//
//*****************************************************************************
char *
ustrncpy(char * restrict s1, const char * restrict s2, size_t n)
{
size_t count;
//
// Check the arguments.
//
ASSERT(s1);
ASSERT(s2);
//
// Start at the beginning of the source string.
//
count = 0;
//
// Copy the source string until we run out of source characters or
// destination space.
//
while(n && s2[count])
{
s1[count] = s2[count];
count++;
n--;
}
//
// Pad the destination if we are not yet done.
//
while(n)
{
s1[count++] = (char)0;
n--;
}
//
// Pass the destination pointer back to the caller.
//
return(s1);
}
//*****************************************************************************
//
//! A simple vsnprintf function supporting \%c, \%d, \%p, \%s, \%u, \%x, and
//! \%X.
//!
//! \param s points to the buffer where the converted string is stored.
//! \param n is the size of the buffer.
//! \param format is the format string.
//! \param arg is the list of optional arguments, which depend on the
//! contents of the format string.
//!
//! This function is very similar to the C library <tt>vsnprintf()</tt>
//! function. Only the following formatting characters are supported:
//!
//! - \%c to print a character
//! - \%d or \%i to print a decimal value
//! - \%s to print a string
//! - \%u to print an unsigned decimal value
//! - \%x to print a hexadecimal value using lower case letters
//! - \%X to print a hexadecimal value using lower case letters (not upper case
//! letters as would typically be used)
//! - \%p to print a pointer as a hexadecimal value
//! - \%\% to print out a \% character
//!
//! For \%d, \%i, \%p, \%s, \%u, \%x, and \%X, an optional number may reside
//! between the \% and the format character, which specifies the minimum number
//! of characters to use for that value; if preceded by a 0 then the extra
//! characters will be filled with zeros instead of spaces. For example,
//! ``\%8d'' will use eight characters to print the decimal value with spaces
//! added to reach eight; ``\%08d'' will use eight characters as well but will
//! add zeroes instead of spaces.
//!
//! The type of the arguments after \e format must match the requirements of
//! the format string. For example, if an integer was passed where a string
//! was expected, an error of some kind will most likely occur.
//!
//! The \e n parameter limits the number of characters that will be
//! stored in the buffer pointed to by \e s to prevent the possibility of
//! a buffer overflow. The buffer size should be large enough to hold the
//! expected converted output string, including the null termination character.
//!
//! The function will return the number of characters that would be converted
//! as if there were no limit on the buffer size. Therefore it is possible for
//! the function to return a count that is greater than the specified buffer
//! size. If this happens, it means that the output was truncated.
//!
//! \return Returns the number of characters that were to be stored, not
//! including the NULL termination character, regardless of space in the
//! buffer.
//
//*****************************************************************************
int
uvsnprintf(char * restrict s, size_t n, const char * restrict format,
va_list arg)
{
unsigned long ulIdx, ulValue, ulCount, ulBase, ulNeg;
char *pcStr, cFill;
int iConvertCount = 0;
//
// Check the arguments.
//
ASSERT(s);
ASSERT(n);
ASSERT(format);
//
// Adjust buffer size limit to allow one space for null termination.
//
if(n)
{
n--;
}
//
// Initialize the count of characters converted.
//
iConvertCount = 0;
//
// Loop while there are more characters in the format string.
//
while(*format)
{
//
// Find the first non-% character, or the end of the string.
//
for(ulIdx = 0; (format[ulIdx] != '%') && (format[ulIdx] != '\0');
ulIdx++)
{
}
//
// Write this portion of the string to the output buffer. If there are
// more characters to write than there is space in the buffer, then
// only write as much as will fit in the buffer.
//
if(ulIdx > n)
{
ustrncpy(s, format, n);
s += n;
n = 0;
}
else
{
ustrncpy(s, format, ulIdx);
s += ulIdx;
n -= ulIdx;
}
//
// Update the conversion count. This will be the number of characters
// that should have been written, even if there was not room in the
// buffer.
//
iConvertCount += ulIdx;
//
// Skip the portion of the format string that was written.
//
format += ulIdx;
//
// See if the next character is a %.
//
if(*format == '%')
{
//
// Skip the %.
//
format++;
//
// Set the digit count to zero, and the fill character to space
// (that is, to the defaults).
//
ulCount = 0;
cFill = ' ';
//
// It may be necessary to get back here to process more characters.
// Goto's aren't pretty, but effective. I feel extremely dirty for
// using not one but two of the beasts.
//
again:
//
// Determine how to handle the next character.
//
switch(*format++)
{
//
// Handle the digit characters.
//
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
{
//
// If this is a zero, and it is the first digit, then the
// fill character is a zero instead of a space.
//
if((format[-1] == '0') && (ulCount == 0))
{
cFill = '0';
}
//
// Update the digit count.
//
ulCount *= 10;
ulCount += format[-1] - '0';
//
// Get the next character.
//
goto again;
}
//
// Handle the %c command.
//
case 'c':
{
//
// Get the value from the varargs.
//
ulValue = va_arg(arg, unsigned long);
//
// Copy the character to the output buffer, if there is
// room. Update the buffer size remaining.
//
if(n != 0)
{
*s++ = (char)ulValue;
n--;
}
//
// Update the conversion count.
//
iConvertCount++;
//
// This command has been handled.
//
break;
}
//
// Handle the %d and %i commands.
//
case 'd':
case 'i':
{
//
// Get the value from the varargs.
//
ulValue = va_arg(arg, unsigned long);
//
// If the value is negative, make it positive and indicate
// that a minus sign is needed.
//
if((long)ulValue < 0)
{
//
// Make the value positive.
//
ulValue = -(long)ulValue;
//
// Indicate that the value is negative.
//
ulNeg = 1;
}
else
{
//
// Indicate that the value is positive so that a
// negative sign isn't inserted.
//
ulNeg = 0;
}
//
// Set the base to 10.
//
ulBase = 10;
//
// Convert the value to ASCII.
//
goto convert;
}
//
// Handle the %s command.
//
case 's':
{
//
// Get the string pointer from the varargs.
//
pcStr = va_arg(arg, char *);
//
// Determine the length of the string.
//
for(ulIdx = 0; pcStr[ulIdx] != '\0'; ulIdx++)
{
}
//
// Update the convert count to include any padding that
// should be necessary (regardless of whether we have space
// to write it or not).
//
if(ulCount > ulIdx)
{
iConvertCount += (ulCount - ulIdx);
}
//
// Copy the string to the output buffer. Only copy as much
// as will fit in the buffer. Update the output buffer
// pointer and the space remaining.
//
if(ulIdx > n)
{
ustrncpy(s, pcStr, n);
s += n;
n = 0;
}
else
{
ustrncpy(s, pcStr, ulIdx);
s += ulIdx;
n -= ulIdx;
//
// Write any required padding spaces assuming there is
// still space in the buffer.
//
if(ulCount > ulIdx)
{
ulCount -= ulIdx;
if(ulCount > n)
{
ulCount = n;
}
n = -ulCount;
while(ulCount--)
{
*s++ = ' ';
}
}
}
//
// Update the conversion count. This will be the number of
// characters that should have been written, even if there
// was not room in the buffer.
//
iConvertCount += ulIdx;
//
// This command has been handled.
//
break;
}
//
// Handle the %u command.
//
case 'u':
{
//
// Get the value from the varargs.
//
ulValue = va_arg(arg, unsigned long);
//
// Set the base to 10.
//
ulBase = 10;
//
// Indicate that the value is positive so that a minus sign
// isn't inserted.
//
ulNeg = 0;
//
// Convert the value to ASCII.
//
goto convert;
}
//
// Handle the %x and %X commands. Note that they are treated
// identically; that is, %X will use lower case letters for a-f
// instead of the upper case letters is should use. We also
// alias %p to %x.
//
case 'x':
case 'X':
case 'p':
{
//
// Get the value from the varargs.
//
ulValue = va_arg(arg, unsigned long);
//
// Set the base to 16.
//
ulBase = 16;
//
// Indicate that the value is positive so that a minus sign
// isn't inserted.
//
ulNeg = 0;
//
// Determine the number of digits in the string version of
// the value.
//
convert:
for(ulIdx = 1;
(((ulIdx * ulBase) <= ulValue) &&
(((ulIdx * ulBase) / ulBase) == ulIdx));
ulIdx *= ulBase, ulCount--)
{
}
//
// If the value is negative, reduce the count of padding
// characters needed.
//
if(ulNeg)
{
ulCount--;
}
//
// If the value is negative and the value is padded with
// zeros, then place the minus sign before the padding.
//
if(ulNeg && (n != 0) && (cFill == '0'))
{
//
// Place the minus sign in the output buffer.
//
*s++ = '-';
n--;
//
// Update the conversion count.
//
iConvertCount++;
//
// The minus sign has been placed, so turn off the
// negative flag.
//
ulNeg = 0;
}
//
// See if there are more characters in the specified field
// width than there are in the conversion of this value.
//
if((ulCount > 1) && (ulCount < 65536))
{
//
// Loop through the required padding characters.
//
for(ulCount--; ulCount; ulCount--)
{
//
// Copy the character to the output buffer if there
// is room.
//
if(n != 0)
{
*s++ = cFill;
n--;
}
//
// Update the conversion count.
//
iConvertCount++;
}
}
//
// If the value is negative, then place the minus sign
// before the number.
//
if(ulNeg && (n != 0))
{
//
// Place the minus sign in the output buffer.
//
*s++ = '-';
n--;
//
// Update the conversion count.
//
iConvertCount++;
}
//
// Convert the value into a string.
//
for(; ulIdx; ulIdx /= ulBase)
{
//
// Copy the character to the output buffer if there is
// room.
//
if(n != 0)
{
*s++ = g_pcHex[(ulValue / ulIdx) % ulBase];
n--;
}
//
// Update the conversion count.
//
iConvertCount++;
}
//
// This command has been handled.
//
break;
}
//
// Handle the %% command.
//
case '%':
{
//
// Simply write a single %.
//
if(n != 0)
{
*s++ = format[-1];
n--;
}
//
// Update the conversion count.
//
iConvertCount++;
//
// This command has been handled.
//
break;
}
//
// Handle all other commands.
//
default:
{
//
// Indicate an error.
//
if(n >= 5)
{
ustrncpy(s, "ERROR", 5);
s += 5;
n -= 5;
}
else
{
ustrncpy(s, "ERROR", n);
s += n;
n = 0;
}
//
// Update the conversion count.
//
iConvertCount += 5;
//
// This command has been handled.
//
break;
}
}
}
}
//
// Null terminate the string in the buffer.
//
*s = 0;
//
// Return the number of characters in the full converted string.
//
return(iConvertCount);
}
//*****************************************************************************
//
//! A simple sprintf function supporting \%c, \%d, \%p, \%s, \%u, \%x, and \%X.
//!
//! \param s is the buffer where the converted string is stored.
//! \param format is the format string.
//! \param ... are the optional arguments, which depend on the contents of the
//! format string.
//!
//! This function is very similar to the C library <tt>sprintf()</tt> function.
//! Only the following formatting characters are supported:
//!
//! - \%c to print a character
//! - \%d or \%i to print a decimal value
//! - \%s to print a string
//! - \%u to print an unsigned decimal value
//! - \%x to print a hexadecimal value using lower case letters
//! - \%X to print a hexadecimal value using lower case letters (not upper case
//! letters as would typically be used)
//! - \%p to print a pointer as a hexadecimal value
//! - \%\% to print out a \% character
//!
//! For \%d, \%i, \%p, \%s, \%u, \%x, and \%X, an optional number may reside
//! between the \% and the format character, which specifies the minimum number
//! of characters to use for that value; if preceded by a 0 then the extra
//! characters will be filled with zeros instead of spaces. For example,
//! ``\%8d'' will use eight characters to print the decimal value with spaces
//! added to reach eight; ``\%08d'' will use eight characters as well but will
//! add zeros instead of spaces.
//!
//! The type of the arguments after \e format must match the requirements of
//! the format string. For example, if an integer was passed where a string
//! was expected, an error of some kind will most likely occur.
//!
//! The caller must ensure that the buffer \e s is large enough to hold the
//! entire converted string, including the null termination character.
//!
//! \return Returns the count of characters that were written to the output
//! buffer, not including the NULL termination character.
//
//*****************************************************************************
int
usprintf(char * restrict s, const char *format, ...)
{
va_list arg;
int ret;
//
// Start the varargs processing.
//
va_start(arg, format);
//
// Call vsnprintf to perform the conversion. Use a large number for the
// buffer size.
//
ret = uvsnprintf(s, 0xffff, format, arg);
//
// End the varargs processing.
//
va_end(arg);
//
// Return the conversion count.
//
return(ret);
}
//*****************************************************************************
//
//! A simple snprintf function supporting \%c, \%d, \%p, \%s, \%u, \%x, and
//! \%X.
//!
//! \param s is the buffer where the converted string is stored.
//! \param n is the size of the buffer.
//! \param format is the format string.
//! \param ... are the optional arguments, which depend on the contents of the
//! format string.
//!
//! This function is very similar to the C library <tt>sprintf()</tt> function.
//! Only the following formatting characters are supported:
//!
//! - \%c to print a character
//! - \%d or \%i to print a decimal value
//! - \%s to print a string
//! - \%u to print an unsigned decimal value
//! - \%x to print a hexadecimal value using lower case letters
//! - \%X to print a hexadecimal value using lower case letters (not upper case
//! letters as would typically be used)
//! - \%p to print a pointer as a hexadecimal value
//! - \%\% to print out a \% character
//!
//! For \%d, \%i, \%p, \%s, \%u, \%x, and \%X, an optional number may reside
//! between the \% and the format character, which specifies the minimum number
//! of characters to use for that value; if preceded by a 0 then the extra
//! characters will be filled with zeros instead of spaces. For example,
//! ``\%8d'' will use eight characters to print the decimal value with spaces
//! added to reach eight; ``\%08d'' will use eight characters as well but will
//! add zeros instead of spaces.
//!
//! The type of the arguments after \e format must match the requirements of
//! the format string. For example, if an integer was passed where a string
//! was expected, an error of some kind will most likely occur.
//!
//! The function will copy at most \e n - 1 characters into the buffer
//! \e s. One space is reserved in the buffer for the null termination
//! character.
//!
//! The function will return the number of characters that would be converted
//! as if there were no limit on the buffer size. Therefore it is possible for
//! the function to return a count that is greater than the specified buffer
//! size. If this happens, it means that the output was truncated.
//!
//! \return Returns the number of characters that were to be stored, not
//! including the NULL termination character, regardless of space in the
//! buffer.
//
//*****************************************************************************
int
usnprintf(char * restrict s, size_t n, const char * restrict format, ...)
{
va_list arg;
int ret;
//
// Start the varargs processing.
//
va_start(arg, format);
//
// Call vsnprintf to perform the conversion.
//
ret = uvsnprintf(s, n, format, arg);
//
// End the varargs processing.
//
va_end(arg);
//
// Return the conversion count.
//
return(ret);
}
//*****************************************************************************
//
// This array contains the number of days in a year at the beginning of each
// month of the year, in a non-leap year.
//
//*****************************************************************************
static const time_t g_psDaysToMonth[12] =
{
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
};
//*****************************************************************************
//
//! Converts from seconds to calendar date and time.
//!
//! \param timer is the number of seconds.
//! \param tm is a pointer to the time structure that is filled in with the
//! broken down date and time.
//!
//! This function converts a number of seconds since midnight GMT on January 1,
//! 1970 (traditional Unix epoch) into the equivalent month, day, year, hours,
//! minutes, and seconds representation.
//!
//! \return None.
//
//*****************************************************************************
void
ulocaltime(time_t timer, struct tm *tm)
{
time_t temp, months;
//
// Extract the number of seconds, converting time to the number of minutes.
//
temp = timer / 60;
tm->tm_sec = timer - (temp * 60);
timer = temp;
//
// Extract the number of minutes, converting time to the number of hours.
//
temp = timer / 60;
tm->tm_min = timer - (temp * 60);
timer = temp;
//
// Extract the number of hours, converting time to the number of days.
//
temp = timer / 24;
tm->tm_hour = timer - (temp * 24);
timer = temp;
//
// Compute the day of the week.
//
tm->tm_wday = (timer + 4) % 7;
//
// Compute the number of leap years that have occurred since 1968, the
// first leap year before 1970. For the beginning of a leap year, cut the
// month loop below at March so that the leap day is classified as February
// 29 followed by March 1, instead of March 1 followed by another March 1.
//
timer += 366 + 365;
temp = timer / ((4 * 365) + 1);
if((timer - (temp * ((4 * 365) + 1))) > (31 + 28))
{
temp++;
months = 12;
}
else
{
months = 2;
}
//
// Extract the year.
//
tm->tm_year = ((timer - temp) / 365) + 68;
timer -= ((tm->tm_year - 68) * 365) + temp;
//
// Extract the month.
//
for(temp = 0; temp < months; temp++)
{
if(g_psDaysToMonth[temp] > timer)
{
break;
}
}
tm->tm_mon = temp - 1;
//
// Extract the day of the month.
//
tm->tm_mday = timer - g_psDaysToMonth[temp - 1] + 1;
}
//*****************************************************************************
//
//! Compares two time structures and determines if one is greater than,
//! less than, or equal to the other.
//!
//! \param t1 is the first time structure to compare.
//! \param t2 is the second time structure to compare.
//!
//! This function compares two time structures and returns a signed number
//! to indicate the result of the comparison. If the time represented by
//! \e t1 is greater than the time represented by \e t2 then a positive
//! number is returned. Likewise if \e t1 is less than \e t2 then a
//! negative number is returned. If the two times are equal then the function
//! returns 0.
//!
//! \return Returns 0 if the two times are equal, +1 if \e t1 is greater
//! than \e t2, and -1 if \e t1 is less than \e t2.
//
//*****************************************************************************
static int
ucmptime(struct tm *t1, struct tm *t2)
{
//
// Compare each field in descending signficance to determine if
// greater than, less than, or equal.
//
if(t1->tm_year > t2->tm_year)
{
return(1);
}
else if(t1->tm_year < t2->tm_year)
{
return(-1);
}
else if(t1->tm_mon > t2->tm_mon)
{
return(1);
}
else if(t1->tm_mon < t2->tm_mon)
{
return(-1);
}
else if(t1->tm_mday > t2->tm_mday)
{
return(1);
}
else if(t1->tm_mday < t2->tm_mday)
{
return(-1);
}
else if(t1->tm_hour > t2->tm_hour)
{
return(1);
}
else if(t1->tm_hour < t2->tm_hour)
{
return(-1);
}
else if(t1->tm_min > t2->tm_min)
{
return(1);
}
else if(t1->tm_min < t2->tm_min)
{
return(-1);
}
else if(t1->tm_sec > t2->tm_sec)