1b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*
2b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*******************************************************************************
3b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*
450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho*   Copyright (C) 1999-2010, International Business Machines
5b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   Corporation and others.  All Rights Reserved.
6b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*
7b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*******************************************************************************
8b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   file name:  unewdata.c
9b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   encoding:   US-ASCII
10b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   tab size:   8 (not used)
11b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   indentation:4
12b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*
13b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   created on: 1999oct25
14b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   created by: Markus W. Scherer
15b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*/
16b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
1750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include <stdio.h>
18b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/utypes.h"
19b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/putil.h"
20b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/ustring.h"
21b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "cmemory.h"
22b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "cstring.h"
23b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "filestrm.h"
24b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/udata.h"
25b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unewdata.h"
26b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
27b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustruct UNewDataMemory {
28b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    FileStream *file;
29b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    uint16_t headerSize;
30b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    uint8_t magic1, magic2;
31b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru};
32b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
33b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI UNewDataMemory * U_EXPORT2
34b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruudata_create(const char *dir, const char *type, const char *name,
35b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru             const UDataInfo *pInfo,
36b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru             const char *comment,
37b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru             UErrorCode *pErrorCode) {
38b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    UNewDataMemory *pData;
39b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    uint16_t headerSize, commentLength;
40b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    char filename[512];
41b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    uint8_t bytes[16];
42c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    int length;
43b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
44b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
45b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return NULL;
46b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } else if(name==NULL || *name==0 || pInfo==NULL) {
47b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
48b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return NULL;
49b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
50b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
51b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* allocate the data structure */
52b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    pData=(UNewDataMemory *)uprv_malloc(sizeof(UNewDataMemory));
53b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(pData==NULL) {
54b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
55b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return NULL;
56b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
57c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru
58c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    /* Check that the full path won't be too long */
59c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    length = 0;					/* Start with nothing */
60c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    if(dir != NULL  && *dir !=0)	/* Add directory length if one was given */
61c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    {
62c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    	length += strlen(dir);
63c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru
64c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    	/* Add 1 if dir doesn't end with path sep */
65c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru        if (dir[strlen(dir) - 1]!= U_FILE_SEP_CHAR) {
66c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru            length++;
67c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru        }
68c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru	}
69c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    length += strlen(name);		/* Add the filename length */
70b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
71c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    if(type != NULL  && *type !=0) { /* Add directory length if  given */
72c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru        length += strlen(type);
73c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    }
74c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru
75c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru
76c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru     /* LDH buffer Length error check */
77c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    if(length  > (sizeof(filename) - 1))
78c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    {
79c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru   	    *pErrorCode = U_BUFFER_OVERFLOW_ERROR;
80c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru   	    uprv_free(pData);
81c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru	    return NULL;
82c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru    }
83c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru
84b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* open the output file */
85b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(dir!=NULL && *dir!=0) { /* if dir has a value, we prepend it to the filename */
86b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        char *p=filename+strlen(dir);
87b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uprv_strcpy(filename, dir);
88b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if (*(p-1)!=U_FILE_SEP_CHAR) {
89b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            *p++=U_FILE_SEP_CHAR;
90b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            *p=0;
91b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
92b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } else { /* otherwise, we'll output to the current dir */
93b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        filename[0]=0;
94b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
95b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    uprv_strcat(filename, name);
96b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(type!=NULL && *type!=0) {
97b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uprv_strcat(filename, ".");
98b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uprv_strcat(filename, type);
99b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
100b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    pData->file=T_FileStream_open(filename, "wb");
101b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(pData->file==NULL) {
102b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uprv_free(pData);
103b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        *pErrorCode=U_FILE_ACCESS_ERROR;
104b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return NULL;
105b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
106b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
107b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* write the header information */
108b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    headerSize=(uint16_t)(pInfo->size+4);
109b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(comment!=NULL && *comment!=0) {
110b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        commentLength=(uint16_t)(uprv_strlen(comment)+1);
111b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        headerSize+=commentLength;
112b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    } else {
113b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        commentLength=0;
114b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
115b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
116b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* write the size of the header, take padding into account */
117b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    pData->headerSize=(uint16_t)((headerSize+15)&~0xf);
118b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    pData->magic1=0xda;
119b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    pData->magic2=0x27;
120b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    T_FileStream_write(pData->file, &pData->headerSize, 4);
121b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
122b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* write the information data */
123b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    T_FileStream_write(pData->file, pInfo, pInfo->size);
124b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
125b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* write the comment */
126b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(commentLength>0) {
127b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        T_FileStream_write(pData->file, comment, commentLength);
128b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
129b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
130b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    /* write padding bytes to align the data section to 16 bytes */
131b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    headerSize&=0xf;
132b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(headerSize!=0) {
133b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        headerSize=(uint16_t)(16-headerSize);
134b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uprv_memset(bytes, 0, headerSize);
135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        T_FileStream_write(pData->file, bytes, headerSize);
136b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    return pData;
139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI uint32_t U_EXPORT2
142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruudata_finish(UNewDataMemory *pData, UErrorCode *pErrorCode) {
143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    uint32_t fileLength=0;
144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        return 0;
147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(pData!=NULL) {
150b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(pData->file!=NULL) {
151b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            /* fflush(pData->file);*/
152b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            fileLength=T_FileStream_size(pData->file);
153b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            if(T_FileStream_error(pData->file)) {
154b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                *pErrorCode=U_FILE_ACCESS_ERROR;
155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            } else {
156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru                fileLength-=pData->headerSize;
157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            }
158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            T_FileStream_close(pData->file);
159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        uprv_free(pData);
161b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    return fileLength;
164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
16650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/* dummy UDataInfo cf. udata.h */
16750294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehostatic const UDataInfo dummyDataInfo = {
16850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    sizeof(UDataInfo),
16950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    0,
17050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
17150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    U_IS_BIG_ENDIAN,
17250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    U_CHARSET_FAMILY,
17350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    U_SIZEOF_UCHAR,
17450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    0,
17550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
17650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    { 0, 0, 0, 0 },                 /* dummy dataFormat */
17750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    { 0, 0, 0, 0 },                 /* dummy formatVersion */
17850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    { 0, 0, 0, 0 }                  /* dummy dataVersion */
17950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho};
18050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
18150294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoU_CAPI void U_EXPORT2
18250294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoudata_createDummy(const char *dir, const char *type, const char *name, UErrorCode *pErrorCode) {
18350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    if(U_SUCCESS(*pErrorCode)) {
18450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho        udata_finish(udata_create(dir, type, name, &dummyDataInfo, NULL, pErrorCode), pErrorCode);
18550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho        if(U_FAILURE(*pErrorCode)) {
18650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho            fprintf(stderr, "error %s writing dummy data file %s" U_FILE_SEP_STRING "%s.%s\n",
18750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho                    u_errorName(*pErrorCode), dir, name, type);
18850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho            exit(*pErrorCode);
18950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho        }
19050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    }
19150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho}
19250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
193b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void U_EXPORT2
194b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruudata_write8(UNewDataMemory *pData, uint8_t byte) {
195b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(pData!=NULL && pData->file!=NULL) {
196b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        T_FileStream_write(pData->file, &byte, 1);
197b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
198b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
199b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
200b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void U_EXPORT2
201b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruudata_write16(UNewDataMemory *pData, uint16_t word) {
202b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(pData!=NULL && pData->file!=NULL) {
203b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        T_FileStream_write(pData->file, &word, 2);
204b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
205b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
206b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
207b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void U_EXPORT2
208b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruudata_write32(UNewDataMemory *pData, uint32_t wyde) {
209b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(pData!=NULL && pData->file!=NULL) {
210b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        T_FileStream_write(pData->file, &wyde, 4);
211b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
212b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
213b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
214b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void U_EXPORT2
215b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruudata_writeBlock(UNewDataMemory *pData, const void *s, int32_t length) {
216b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(pData!=NULL && pData->file!=NULL) {
217b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(length>0) {
218b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            T_FileStream_write(pData->file, s, length);
219b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
220b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
221b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
222b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
223b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void U_EXPORT2
224b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruudata_writePadding(UNewDataMemory *pData, int32_t length) {
225b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    static const uint8_t padding[16]={
226b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0xaa, 0xaa, 0xaa, 0xaa,
227b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0xaa, 0xaa, 0xaa, 0xaa,
228b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0xaa, 0xaa, 0xaa, 0xaa,
229b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        0xaa, 0xaa, 0xaa, 0xaa
230b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    };
231b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(pData!=NULL && pData->file!=NULL) {
232b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        while(length>=16) {
233b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            T_FileStream_write(pData->file, padding, 16);
234b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            length-=16;
235b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
236b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(length>0) {
237b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            T_FileStream_write(pData->file, padding, length);
238b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
239b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
240b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
241b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
242b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void U_EXPORT2
243b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruudata_writeString(UNewDataMemory *pData, const char *s, int32_t length) {
244b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(pData!=NULL && pData->file!=NULL) {
245b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(length==-1) {
246b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            length=(int32_t)uprv_strlen(s);
247b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
248b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(length>0) {
249b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            T_FileStream_write(pData->file, s, length);
250b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
251b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
252b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
253b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
254b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void U_EXPORT2
255b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruudata_writeUString(UNewDataMemory *pData, const UChar *s, int32_t length) {
256b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    if(pData!=NULL && pData->file!=NULL) {
257b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(length==-1) {
258b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            length=u_strlen(s);
259b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
260b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        if(length>0) {
261b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru            T_FileStream_write(pData->file, s, length*sizeof(UChar));
262b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru        }
263b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru    }
264b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru}
265b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
266b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*
267b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Hey, Emacs, please set the following:
268b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *
269b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Local Variables:
270b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * indent-tabs-mode: nil
271b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * End:
272b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *
273b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
274b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
275