1 /*
2 ******************************************************************************
3 *
4 * Copyright (C) 2009, International Business Machines
5 * Corporation and others. All Rights Reserved.
6 *
7 ******************************************************************************
8 */
9
10 #include "unicode/utypes.h"
11 #include "unicode/icudataver.h"
12 #include "unicode/uversion.h"
13 #include "unicode/ures.h"
14 #include "uresimp.h" /* for ures_getVersionByKey */
15 #include "cmemory.h"
16
17 /*
18 * Determines if icustd is in the data.
19 */
20 static UBool hasICUSTDBundle();
21
hasICUSTDBundle()22 static UBool hasICUSTDBundle() {
23 UErrorCode status = U_ZERO_ERROR;
24 UBool result = TRUE;
25
26 UResourceBundle *icustdbundle = ures_openDirect(NULL, U_ICU_STD_BUNDLE, &status);
27 if (U_SUCCESS(status)) {
28 result = TRUE;
29 } else {
30 result = FALSE;
31 }
32
33 ures_close(icustdbundle);
34
35 return result;
36 }
37
u_getDataVersion(UVersionInfo dataVersionFillin,UErrorCode * status)38 U_CAPI void U_EXPORT2 u_getDataVersion(UVersionInfo dataVersionFillin, UErrorCode *status) {
39 UResourceBundle *icudatares = NULL;
40
41 if (U_FAILURE(*status)) {
42 return;
43 }
44
45 if (dataVersionFillin != NULL) {
46 icudatares = ures_openDirect(NULL, U_ICU_VERSION_BUNDLE , status);
47 if (U_SUCCESS(*status)) {
48 ures_getVersionByKey(icudatares, U_ICU_DATA_KEY, dataVersionFillin, status);
49 }
50 ures_close(icudatares);
51 }
52 }
53
u_isDataOlder(UVersionInfo dataVersionFillin,UBool * isModifiedFillin,UErrorCode * status)54 U_CAPI UBool U_EXPORT2 u_isDataOlder(UVersionInfo dataVersionFillin, UBool *isModifiedFillin, UErrorCode *status) {
55 UBool result = TRUE;
56 UVersionInfo dataVersion;
57 UVersionInfo wiredVersion;
58
59 if (U_FAILURE(*status)) {
60 return result;
61 }
62
63 u_getDataVersion(dataVersion, status);
64 if (U_SUCCESS(*status)) {
65 u_versionFromString(wiredVersion, U_ICU_DATA_VERSION);
66
67 if (uprv_memcmp(dataVersion, wiredVersion, sizeof(UVersionInfo)) >= 0) {
68 result = FALSE;
69 }
70
71 if (dataVersionFillin != NULL) {
72 uprv_memcpy(dataVersionFillin, dataVersion, sizeof(UVersionInfo));
73 }
74
75 if (hasICUSTDBundle()) {
76 *isModifiedFillin = FALSE;
77 } else {
78 *isModifiedFillin = TRUE;
79 }
80 }
81
82 return result;
83 }
84