Nikolay Sivov : qmgr: Use helper to return string value for File.

Alexandre Julliard julliard at winehq.org
Tue Nov 26 15:51:44 CST 2013


Module: wine
Branch: master
Commit: c132ed8d5bd9cd92cb85800db33c4b79c5d6b801
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=c132ed8d5bd9cd92cb85800db33c4b79c5d6b801

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Tue Nov 26 13:21:43 2013 +0400

qmgr: Use helper to return string value for File.

---

 dlls/qmgr/file.c |   16 ++++------------
 dlls/qmgr/job.c  |   18 ------------------
 dlls/qmgr/qmgr.h |   14 ++++++++++++++
 3 files changed, 18 insertions(+), 30 deletions(-)

diff --git a/dlls/qmgr/file.c b/dlls/qmgr/file.c
index ccba81b..0e415a9 100644
--- a/dlls/qmgr/file.c
+++ b/dlls/qmgr/file.c
@@ -94,14 +94,10 @@ static HRESULT WINAPI BITS_IBackgroundCopyFile_GetRemoteName(
     LPWSTR *pVal)
 {
     BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
-    int n = (lstrlenW(This->info.RemoteName) + 1) * sizeof(WCHAR);
 
-    *pVal = CoTaskMemAlloc(n);
-    if (!*pVal)
-        return E_OUTOFMEMORY;
+    TRACE("(%p)->(%p)\n", This, pVal);
 
-    memcpy(*pVal, This->info.RemoteName, n);
-    return S_OK;
+    return return_strval(This->info.RemoteName, pVal);
 }
 
 static HRESULT WINAPI BITS_IBackgroundCopyFile_GetLocalName(
@@ -109,14 +105,10 @@ static HRESULT WINAPI BITS_IBackgroundCopyFile_GetLocalName(
     LPWSTR *pVal)
 {
     BackgroundCopyFileImpl *This = impl_from_IBackgroundCopyFile(iface);
-    int n = (lstrlenW(This->info.LocalName) + 1) * sizeof(WCHAR);
 
-    *pVal = CoTaskMemAlloc(n);
-    if (!*pVal)
-        return E_OUTOFMEMORY;
+    TRACE("(%p)->(%p)\n", This, pVal);
 
-    memcpy(*pVal, This->info.LocalName, n);
-    return S_OK;
+    return return_strval(This->info.LocalName, pVal);
 }
 
 static HRESULT WINAPI BITS_IBackgroundCopyFile_GetProgress(
diff --git a/dlls/qmgr/job.c b/dlls/qmgr/job.c
index 5be1676..ac7deaf 100644
--- a/dlls/qmgr/job.c
+++ b/dlls/qmgr/job.c
@@ -25,7 +25,6 @@
 
 #include "qmgr.h"
 #include "wine/debug.h"
-#include "wine/unicode.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(qmgr);
 
@@ -34,23 +33,6 @@ static inline BOOL is_job_done(const BackgroundCopyJobImpl *job)
     return job->state == BG_JOB_STATE_CANCELLED || job->state == BG_JOB_STATE_ACKNOWLEDGED;
 }
 
-static HRESULT return_strval(const WCHAR *str, WCHAR **ret)
-{
-    int len;
-
-    if (!ret) return E_INVALIDARG;
-
-    len = strlenW(str);
-    *ret = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
-    if (!*ret) return E_OUTOFMEMORY;
-
-    if (len)
-        strcpyW(*ret, str);
-    else
-        **ret = 0;
-    return S_OK;
-}
-
 static inline BackgroundCopyJobImpl *impl_from_IBackgroundCopyJob2(IBackgroundCopyJob2 *iface)
 {
     return CONTAINING_RECORD(iface, BackgroundCopyJobImpl, IBackgroundCopyJob2_iface);
diff --git a/dlls/qmgr/qmgr.h b/dlls/qmgr/qmgr.h
index 1f64d41..63d9f91 100644
--- a/dlls/qmgr/qmgr.h
+++ b/dlls/qmgr/qmgr.h
@@ -29,6 +29,7 @@
 
 #include <string.h>
 #include "wine/list.h"
+#include "wine/unicode.h"
 
 /* Background copy job vtbl and related data */
 typedef struct
@@ -100,6 +101,19 @@ qmgr_strdup(const char *s)
     return d ? memcpy(d, s, n) : NULL;
 }
 
+static inline HRESULT return_strval(const WCHAR *str, WCHAR **ret)
+{
+    int len;
+
+    if (!ret) return E_INVALIDARG;
+
+    len = strlenW(str);
+    *ret = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
+    if (!*ret) return E_OUTOFMEMORY;
+    strcpyW(*ret, str);
+    return S_OK;
+}
+
 static inline BOOL
 transitionJobState(BackgroundCopyJobImpl *job, BG_JOB_STATE fromState,
                    BG_JOB_STATE toState)




More information about the wine-cvs mailing list