2 *******************************************************************************
4 * Copyright (C) 2016 and later: Unicode, Inc. and others.
5 * License & terms of use: http://www.unicode.org/copyright.html#License
7 *******************************************************************************
8 *******************************************************************************
10 * Copyright (C) 1999-2009, International Business Machines
11 * Corporation and others. All Rights Reserved.
13 *******************************************************************************
16 * tab size: 8 (not used)
19 * created on: 2000sep5
20 * created by: Vladimir Weinstein
23 /*******************************************************************************
24 * Derived from Madhu Katragadda gentest
25 *******************************************************************************/
36 #include "unicode/utypes.h"
37 #include "unicode/putil.h"
38 #include "unicode/udata.h"
40 #define DATA_NAME "mypkg_example"
41 #define DATA_TYPE "dat"
43 /* UDataInfo cf. udata.h */
44 static const UDataInfo dataInfo={
53 0x4D, 0x79, 0x44, 0x74, /* dataFormat="MyDt" */
54 1, 0, 0, 0, /* formatVersion */
55 1, 0, 0, 0 /* dataVersion */
59 isAcceptable(void *context,
60 const char *type, const char *name,
61 const UDataInfo *pInfo){
63 if( pInfo->size>=20 &&
64 pInfo->isBigEndian==U_IS_BIG_ENDIAN &&
65 pInfo->charsetFamily==U_CHARSET_FAMILY &&
66 pInfo->dataFormat[0]==0x4D && /* dataFormat="MyDt" */
67 pInfo->dataFormat[1]==0x79 &&
68 pInfo->dataFormat[2]==0x44 &&
69 pInfo->dataFormat[3]==0x74 &&
70 pInfo->formatVersion[0]==1 &&
71 pInfo->dataVersion[0]==1 ) {
81 main(int argc, const char *argv[]) {
82 UDataMemory *result = NULL;
83 UErrorCode status=U_ZERO_ERROR;
85 uint16_t intValue = 0;
88 uint16_t *intPointer = NULL;
90 const void *dataMemory = NULL;
91 char curPathBuffer[1024];
94 char *currdir = _getcwd(NULL, 0);
96 char *currdir = getcwd(NULL, 0);
99 /* need to put "current/dir" as path */
100 strcpy(curPathBuffer, currdir);
102 result=udata_openChoice(curPathBuffer, DATA_TYPE, DATA_NAME, isAcceptable, NULL, &status);
104 if(currdir != NULL) {
108 if(U_FAILURE(status)){
109 printf("Failed to open data file example.dat in %s with error number %d\n", curPathBuffer, status);
113 dataMemory = udata_getMemory(result);
115 intPointer = (uint16_t *)dataMemory;
117 printf("Read value %d from data file\n", *intPointer);
119 string = (char *) (intPointer+1);
121 printf("Read string %s from data file\n", string);
123 if(U_SUCCESS(status)){