loentar / axis2c-unofficial

Unofficial backports and unofficial support for Apache Axis2/C
Apache License 2.0
15 stars 10 forks source link

Win64 directory scan exception #13

Closed cxsup closed 9 years ago

cxsup commented 9 years ago

The Windows platform implementation for directory scan is partially wired for Win32 causing truncation of the handle returned by _wfindfirst64. The issue is solved by promoting the handle to an intptr_t:

-    long handle;          /* _findfirst/_findnext handle */
+    intptr_t handle;          /* _findfirst/_findnext handle */

Here's the entire diff:

diff --git a/util/include/platforms/windows/axutil_dir_windows.h b/util/include/platforms/windows/axutil_dir_windows.h
index 1506259..70f858d 100644
--- a/util/include/platforms/windows/axutil_dir_windows.h
+++ b/util/include/platforms/windows/axutil_dir_windows.h
@@ -45,7 +45,7 @@ struct dirent
 /* def struct DIR - different from Unix DIR */
 typedef struct
 {
-    long handle;          /* _findfirst/_findnext handle */
+    intptr_t handle;          /* _findfirst/_findnext handle */
     short offset;         /* offset into directory */
     short finished;       /* 1 if there are not more files */
     struct _finddata_t fileinfo;  /* from _findfirst/_findnext */
diff --git a/util/src/platforms/windows/dir_windows.c b/util/src/platforms/windows/dir_windows.c
index 2e91512..e156350 100644
--- a/util/src/platforms/windows/dir_windows.c
+++ b/util/src/platforms/windows/dir_windows.c
@@ -30,7 +30,7 @@ axis2_opendir(
 {
     AXIS2_DIR *dirp;
     char *filespec;
-    long handle;
+    intptr_t handle;
     int index;

     filespec = malloc(strlen(_dirname) + 2 + 1);
@@ -46,7 +46,7 @@ axis2_opendir(
     dirp->offset = 0;
     dirp->finished = 0;

-    if ((handle = (long)_findfirst(filespec, &(dirp->fileinfo))) < 0)
+    if ((handle = _findfirst(filespec, &(dirp->fileinfo))) < 0)
         /* We are sure that the difference lies within the long range */
     {
         if (errno == ENOENT || errno == EINVAL)
@@ -147,7 +147,7 @@ axis2_rewinddir(
     AXIS2_DIR * dirp)
 {
     char *filespec;
-    long handle;
+    intptr_t handle;
     int index;

     _findclose(dirp->handle);
@@ -162,7 +162,7 @@ axis2_rewinddir(
         filespec[index] = '\0';
     strcat(filespec, "/*");

-    if ((handle = (long)_findfirst(filespec, &(dirp->fileinfo))) < 0)
+    if ((handle = _findfirst(filespec, &(dirp->fileinfo))) < 0)
         /* We are sure that the difference lies within the int range */
     {
         if (errno == ENOENT || errno == EINVAL)
loentar commented 9 years ago

intptr_t requires C99 and because of that the patch as is may broke build for non-Windows OSes.

Probably you need to define handle type and guard platform-specific code with #ifdef.

cxsup commented 9 years ago

Are you sure the #ifdef is necessary given the patch is specific to platforms/windows files? But it wouldn't hurt to use: #ifdef _WIN64

loentar commented 9 years ago

Oh, yes. You're right! I didn't noticed that.

In this case #ifdef _WIN64 is not required, probably..

Could you please fork and create pull request?

cxsup commented 9 years ago

Done.