[libbluray-devel] Improved win32 file_get_data_home(): alloc string dynamically

hpi1 git at videolan.org
Wed Mar 13 22:13:29 CET 2013


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Wed Mar 13 23:10:18 2013 +0200| [f8cc1186f13f06f06ba113aac07d0f91eb9085a5] | committer: hpi1

Improved win32 file_get_data_home(): alloc string dynamically

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=f8cc1186f13f06f06ba113aac07d0f91eb9085a5
---

 src/file/dirs_win32.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/file/dirs_win32.c b/src/file/dirs_win32.c
index cc87a29..622f977 100644
--- a/src/file/dirs_win32.c
+++ b/src/file/dirs_win32.c
@@ -36,16 +36,18 @@
 
 const char *file_get_data_home(void)
 {
-    static char appdir[MAX_PATH] = "";
+    static char *appdir = NULL;
     wchar_t wdir[MAX_PATH];
 
-    if (*appdir)
+    if (appdir)
         return appdir;
 
     /* Get the "Application Data" folder for the user */
     if (S_OK == SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
-                NULL, SHGFP_TYPE_CURRENT, wdir)) {
-        WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, MAX_PATH, NULL, NULL);
+                                 NULL, SHGFP_TYPE_CURRENT, wdir)) {
+        int len = WideCharToMultiByte (CP_UTF8, 0, wdir, -1, NULL, 0, NULL, NULL);
+        appdir = malloc(len);
+        WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, len, NULL, NULL);
         return appdir;
     }
 



More information about the libbluray-devel mailing list