/*
*******************************************************************************
*
-* Copyright (C) 1999,2004, International Business Machines
+* Copyright (C) 1999-2010, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
* created by: Markus W. Scherer
*/
+#include <stdio.h>
#include "unicode/utypes.h"
#include "unicode/putil.h"
#include "unicode/ustring.h"
uint16_t headerSize, commentLength;
char filename[512];
uint8_t bytes[16];
+ int length;
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
return NULL;
*pErrorCode=U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
+
+ /* Check that the full path won't be too long */
+ length = 0; /* Start with nothing */
+ if(dir != NULL && *dir !=0) /* Add directory length if one was given */
+ {
+ length += strlen(dir);
+
+ /* Add 1 if dir doesn't end with path sep */
+ if (dir[strlen(dir) - 1]!= U_FILE_SEP_CHAR) {
+ length++;
+ }
+ }
+ length += strlen(name); /* Add the filename length */
+
+ if(type != NULL && *type !=0) { /* Add directory length if given */
+ length += strlen(type);
+ }
+
+ /* LDH buffer Length error check */
+ if(length > (sizeof(filename) - 1))
+ {
+ *pErrorCode = U_BUFFER_OVERFLOW_ERROR;
+ uprv_free(pData);
+ return NULL;
+ }
+
/* open the output file */
if(dir!=NULL && *dir!=0) { /* if dir has a value, we prepend it to the filename */
char *p=filename+strlen(dir);
return fileLength;
}
+/* dummy UDataInfo cf. udata.h */
+static const UDataInfo dummyDataInfo = {
+ sizeof(UDataInfo),
+ 0,
+
+ U_IS_BIG_ENDIAN,
+ U_CHARSET_FAMILY,
+ U_SIZEOF_UCHAR,
+ 0,
+
+ { 0, 0, 0, 0 }, /* dummy dataFormat */
+ { 0, 0, 0, 0 }, /* dummy formatVersion */
+ { 0, 0, 0, 0 } /* dummy dataVersion */
+};
+
+U_CAPI void U_EXPORT2
+udata_createDummy(const char *dir, const char *type, const char *name, UErrorCode *pErrorCode) {
+ if(U_SUCCESS(*pErrorCode)) {
+ udata_finish(udata_create(dir, type, name, &dummyDataInfo, NULL, pErrorCode), pErrorCode);
+ if(U_FAILURE(*pErrorCode)) {
+ fprintf(stderr, "error %s writing dummy data file %s" U_FILE_SEP_STRING "%s.%s\n",
+ u_errorName(*pErrorCode), dir, name, type);
+ exit(*pErrorCode);
+ }
+ }
+}
+
U_CAPI void U_EXPORT2
udata_write8(UNewDataMemory *pData, uint8_t byte) {
if(pData!=NULL && pData->file!=NULL) {