Author: mjansen
Date: Sun Jul 10 16:06:39 2016
New Revision: 71885

URL: http://svn.reactos.org/svn/reactos?rev=71885&view=rev
Log:
[APPHELP] Prepare sdbwrite related api for a new hosttool. CORE-11302
- Adding an extra argument to SdbReAlloc
- Do not rely on platform wcs* functions.

Added:
    trunk/reactos/dll/appcompat/apphelp/sdbwrite.h   (with props)
Modified:
    trunk/reactos/dll/appcompat/apphelp/apphelp.c
    trunk/reactos/dll/appcompat/apphelp/sdbapi.c
    trunk/reactos/dll/appcompat/apphelp/sdbpapi.h
    trunk/reactos/dll/appcompat/apphelp/sdbstringtable.c
    trunk/reactos/dll/appcompat/apphelp/sdbwrite.c

Modified: trunk/reactos/dll/appcompat/apphelp/apphelp.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/appcompat/apphelp/apphelp.c?rev=71885&r1=71884&r2=71885&view=diff
==============================================================================
--- trunk/reactos/dll/appcompat/apphelp/apphelp.c       [iso-8859-1] (original)
+++ trunk/reactos/dll/appcompat/apphelp/apphelp.c       [iso-8859-1] Sun Jul 10 
16:06:39 2016
@@ -102,7 +102,8 @@
 {
     char Buffer[512];
     va_list ArgList;
-    char* Current = Buffer, *LevelStr;
+    char* Current = Buffer;
+    const char* LevelStr;
     size_t Length = sizeof(Buffer);
 
     if (g_ShimDebugLevel == 0xffffffff)

Modified: trunk/reactos/dll/appcompat/apphelp/sdbapi.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/appcompat/apphelp/sdbapi.c?rev=71885&r1=71884&r2=71885&view=diff
==============================================================================
--- trunk/reactos/dll/appcompat/apphelp/sdbapi.c        [iso-8859-1] (original)
+++ trunk/reactos/dll/appcompat/apphelp/sdbapi.c        [iso-8859-1] Sun Jul 10 
16:06:39 2016
@@ -178,7 +178,7 @@
     return mem;
 }
 
-LPVOID SdbpReAlloc(LPVOID mem, SIZE_T size
+LPVOID SdbpReAlloc(LPVOID mem, SIZE_T size, SIZE_T oldSize
 #if SDBAPI_DEBUG_ALLOC
     , int line, const char* file
 #endif

Modified: trunk/reactos/dll/appcompat/apphelp/sdbpapi.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/appcompat/apphelp/sdbpapi.h?rev=71885&r1=71884&r2=71885&view=diff
==============================================================================
--- trunk/reactos/dll/appcompat/apphelp/sdbpapi.h       [iso-8859-1] (original)
+++ trunk/reactos/dll/appcompat/apphelp/sdbpapi.h       [iso-8859-1] Sun Jul 10 
16:06:39 2016
@@ -30,21 +30,21 @@
 #if SDBAPI_DEBUG_ALLOC
 
 LPVOID SdbpAlloc(SIZE_T size, int line, const char* file);
-LPVOID SdbpReAlloc(LPVOID mem, SIZE_T size, int line, const char* file);
+LPVOID SdbpReAlloc(LPVOID mem, SIZE_T size, SIZE_T oldSize, int line, const 
char* file);
 void SdbpFree(LPVOID mem, int line, const char* file);
 
 #define SdbAlloc(size) SdbpAlloc(size, __LINE__, __FILE__)
-#define SdbReAlloc(mem, size) SdbpReAlloc(mem, size, __LINE__, __FILE__)
+#define SdbReAlloc(mem, size, oldSize) SdbpReAlloc(mem, size, oldSize, 
__LINE__, __FILE__)
 #define SdbFree(mem) SdbpFree(mem, __LINE__, __FILE__)
 
 #else
 
 LPVOID SdbpAlloc(SIZE_T size);
-LPVOID SdbpReAlloc(LPVOID mem, SIZE_T size);
+LPVOID SdbpReAlloc(LPVOID mem, SIZE_T size, SIZE_T oldSize);
 void SdbpFree(LPVOID mem);
 
 #define SdbAlloc(size) SdbpAlloc(size)
-#define SdbReAlloc(mem, size) SdbpReAlloc(mem, size)
+#define SdbReAlloc(mem, size, oldSize) SdbpReAlloc(mem, size, oldSize)
 #define SdbFree(mem) SdbpFree(mem)
 
 #endif
@@ -71,6 +71,9 @@
 BOOL WINAPI SdbpCheckTagType(TAG tag, WORD type);
 BOOL WINAPI SdbpCheckTagIDType(PDB db, TAGID tagid, WORD type);
 
+#ifndef WINAPIV
+#define WINAPIV
+#endif
 
 typedef enum _SHIM_LOG_LEVEL {
     SHIM_ERR = 1,

Modified: trunk/reactos/dll/appcompat/apphelp/sdbstringtable.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/appcompat/apphelp/sdbstringtable.c?rev=71885&r1=71884&r2=71885&view=diff
==============================================================================
--- trunk/reactos/dll/appcompat/apphelp/sdbstringtable.c        [iso-8859-1] 
(original)
+++ trunk/reactos/dll/appcompat/apphelp/sdbstringtable.c        [iso-8859-1] 
Sun Jul 10 16:06:39 2016
@@ -23,11 +23,20 @@
 #include "sdbpapi.h"
 #else /* !defined(SDBWRITE_HOSTTOOL) */
 #include <typedefs.h>
+#include <guiddef.h>
 #include "sdbtypes.h"
 #include "sdbpapi.h"
 #endif /* !defined(SDBWRITE_HOSTTOOL) */
 
 #include "sdbstringtable.h"
+
+#if !defined(offsetof)
+#if defined(__GNUC__)
+#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
+#else
+#define offsetof(TYPE, MEMBER) ((size_t)&(((TYPE *)0)->MEMBER))
+#endif
+#endif // !defined(offsetof)
 
 #define DEFAULT_TABLE_SIZE    0x100
 
@@ -98,13 +107,48 @@
     return hash;
 }
 
+int Sdbwcscmp(const WCHAR* s1, const WCHAR* s2)
+{
+    while (*s1 == *s2)
+    {
+        if (*s1 == 0)
+            return 0;
+        s1++;
+        s2++;
+    }
+    return *s1 - *s2;
+}
+
+
+// implementation taken from reactos/sdk/lib/crt/string/wcs.c
+INT Sdbwcscpy(WCHAR* wcDest, size_t numElement, const WCHAR *wcSrc)
+{
+    size_t size = 0;
+    if(!wcDest || !numElement)
+        return 22;  /* EINVAL */
+
+    wcDest[0] = 0;
+
+    if(!wcSrc)
+        return 22;  /* EINVAL */
+
+    size = SdbpStrlen(wcSrc) + 1;
+
+    if(size > numElement)
+        return 34;  /* ERANGE */
+
+    memcpy(wcDest, wcSrc, size * sizeof(WCHAR));
+
+    return 0;
+}
+
 static struct SdbHashEntry** TableFindPtr(struct SdbStringHashTable* table, 
const WCHAR* str)
 {
     DWORD hash = StringHash(str);
     struct SdbHashEntry** entry = &table->Entries[hash % table->Size];
     while (*entry)
     {
-        if (!wcscmp((*entry)->Name, str))
+        if (!Sdbwcscmp((*entry)->Name, str))
             return entry;
         entry = &(*entry)->Next;
     }
@@ -114,12 +158,13 @@
 static BOOL HashAddString(struct SdbStringHashTable* table, struct 
SdbHashEntry** position, const WCHAR* str, TAGID tagid)
 {
     struct SdbHashEntry* entry;
-    SIZE_T size;
+    SIZE_T size, len;
 
     if (!position)
         position = TableFindPtr(table, str);
 
-    size = offsetof(struct SdbHashEntry, Name[SdbpStrlen(str) + 2]);
+    len = SdbpStrlen(str) + 1;
+    size = offsetof(struct SdbHashEntry, Name[len]);
     entry = (*position) = SdbAlloc(size);
     if (!entry)
     {
@@ -127,7 +172,7 @@
         return FALSE;
     }
     entry->Tagid = tagid;
-    wcscpy(entry->Name, str);
+    Sdbwcscpy(entry->Name, len, str);
     return TRUE;
 }
 

Modified: trunk/reactos/dll/appcompat/apphelp/sdbwrite.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/appcompat/apphelp/sdbwrite.c?rev=71885&r1=71884&r2=71885&view=diff
==============================================================================
--- trunk/reactos/dll/appcompat/apphelp/sdbwrite.c      [iso-8859-1] (original)
+++ trunk/reactos/dll/appcompat/apphelp/sdbwrite.c      [iso-8859-1] Sun Jul 10 
16:06:39 2016
@@ -47,9 +47,10 @@
 {
     if (db->write_iter + size > db->size)
     {
+        DWORD oldSize = db->size;
         /* Round to powers of two to prevent too many reallocations */
         while (db->size < db->write_iter + size) db->size <<= 1;
-        db->data = SdbReAlloc(db->data, db->size);
+        db->data = SdbReAlloc(db->data, db->size, oldSize);
     }
 
     memcpy(db->data + db->write_iter, data, size);

Added: trunk/reactos/dll/appcompat/apphelp/sdbwrite.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/appcompat/apphelp/sdbwrite.h?rev=71885
==============================================================================
--- trunk/reactos/dll/appcompat/apphelp/sdbwrite.h      (added)
+++ trunk/reactos/dll/appcompat/apphelp/sdbwrite.h      [iso-8859-1] Sun Jul 10 
16:06:39 2016
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2013 Mislav Blažević
+ * Copyright 2015,2016 Mark Jansen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef SDBWRITE_H
+#define SDBWRITE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+PDB WINAPI SdbCreateDatabase(LPCWSTR path, PATH_TYPE type);
+void WINAPI SdbCloseDatabaseWrite(PDB db);
+BOOL WINAPI SdbWriteNULLTag(PDB db, TAG tag);
+BOOL WINAPI SdbWriteWORDTag(PDB db, TAG tag, WORD data);
+BOOL WINAPI SdbWriteDWORDTag(PDB db, TAG tag, DWORD data);
+BOOL WINAPI SdbWriteQWORDTag(PDB db, TAG tag, QWORD data);
+BOOL WINAPI SdbWriteStringTag(PDB db, TAG tag, LPCWSTR string);
+BOOL WINAPI SdbWriteStringRefTag(PDB db, TAG tag, TAGID tagid);
+BOOL WINAPI SdbWriteBinaryTag(PDB db, TAG tag, BYTE* data, DWORD size);
+BOOL WINAPI SdbWriteBinaryTagFromFile(PDB db, TAG tag, LPCWSTR path);
+TAGID WINAPI SdbBeginWriteListTag(PDB db, TAG tag);
+BOOL WINAPI SdbEndWriteListTag(PDB db, TAGID tagid);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // SDBWRITE_H

Propchange: trunk/reactos/dll/appcompat/apphelp/sdbwrite.h
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to