version.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright [2021] JD.com, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <stdlib.h>
  17. #include <time.h>
  18. #include "version.h"
  19. const char compdatestr[] = __DATE__;
  20. const char comptimestr[] = __TIME__;
  21. const char version[] = DTC_VERSION;
  22. const char version_detail[] = DTC_VERSION_DETAIL;
  23. long compile_time;
  24. __attribute__((constructor)) void init_comptime(void)
  25. {
  26. struct tm tm;
  27. switch (compdatestr[0]) {
  28. case 'A':
  29. tm.tm_mon = compdatestr[1] == 'p' ? 3 /*Apr*/ : 7 /*Aug*/;
  30. break;
  31. case 'D':
  32. tm.tm_mon = 11;
  33. break; //Dec
  34. case 'F':
  35. tm.tm_mon = 1;
  36. break; //Feb
  37. case 'J':
  38. tm.tm_mon =
  39. compdatestr[1] == 'a' ?
  40. 0 /*Jan*/ :
  41. compdatestr[2] == 'n' ? 5 /*Jun*/ : 6 /*Jul*/;
  42. break;
  43. case 'M':
  44. tm.tm_mon = compdatestr[2] == 'r' ? 2 /*Mar*/ : 4 /*May*/;
  45. break;
  46. case 'N':
  47. tm.tm_mon = 10; /*Nov*/
  48. break;
  49. case 'S':
  50. tm.tm_mon = 8; /*Sep*/
  51. break;
  52. case 'O':
  53. tm.tm_mon = 9; /*Oct*/
  54. break;
  55. default:
  56. return;
  57. }
  58. tm.tm_mday = strtol(compdatestr + 4, 0, 10);
  59. tm.tm_year = strtol(compdatestr + 7, 0, 10) - 1900;
  60. tm.tm_hour = strtol(comptimestr + 0, 0, 10);
  61. tm.tm_min = strtol(comptimestr + 3, 0, 10);
  62. tm.tm_sec = strtol(comptimestr + 6, 0, 10);
  63. compile_time = mktime(&tm);
  64. }