This patch for the shared argument parser will canonicalize Win32 paths
strings (eg. C:\foo\bar) to UNIX paths (eg. /dev/fs/C/foo/bar) on Interix.
This is important because Interix is the UNIX subsystem for Windows and as
such Interix binaries can interact with Windows binaries and the Windows
command shell. With this patch, clamscan can automagically make the
translation, which makes it easy to call from Windows programs that aren't
POSIX-aware.


diff -ru clamav-devel/shared/options.c clamav-devel-interix/shared/options.c
--- clamav-devel/shared/options.c       Mon May 15 14:30:18 2006
+++ clamav-devel-interix/shared/options.c       Wed Jun  7 15:29:59 2006
@@ -32,6 +32,16 @@
 #include "memory.h"
 #include "output.h"
 
+#ifdef __INTERIX
+# include <interix/interix.h>
+# include <limits.h>
+# ifndef TRUE
+#  define TRUE  1
+# endif
+# ifndef FALSE
+#  define FALSE 0
+# endif
+#endif
 
 static int register_option(struct optstruct *opt, const char *optlong, char
optshort, const struct option *options_long, const char **accepted_long)
 {
@@ -125,6 +135,14 @@
 
 struct optstruct *opt_parse(int argc, char * const *argv, const char
*getopt_short, const struct option *options_long, const char
**accepted_long)
 {
+       #ifdef __INTERIX
+       /* Need these to handle win32-style paths passed to the Interix
subsystem on NT 5.x+*/
+       int iswinpath = FALSE;
+       char c;
+       char **filelist = argv;
+       char *file, *srch;
+       #endif
+       
        int ret, opt_index, i, len;
        struct optstruct *opt;
        const char *longname;
@@ -175,22 +193,51 @@
         len = 0;
 
        /* count length of non-option arguments */
-       for(i = optind; i < argc; i++)
-           len += strlen(argv[i]);
-
-       len += argc - optind - 1;
-       opt->filename = (char *) mcalloc(len + 64, sizeof(char));
-       if(!opt->filename) {
-           mprintf("!opt_parse: mcalloc failed\n");
-           opt_free(opt);
-           return NULL;
-       }
-
-        for(i = optind; i < argc; i++) {
-           strncat(opt->filename, argv[i], strlen(argv[i]));
-           if(i != argc - 1)
-               strncat(opt->filename, "\t", 1);
-       }
+               for(i=optind; i<argc; i++)
+               {
+                       #ifdef __INTERIX
+                       /* This block is to handle convertint win32-style
paths to POSIX paths
+                       on the Interix subsystem on NT 5.x+. */
+                       file = srch = filelist[i];
+                       while( (c = *srch++) != '\0' )
+                       {
+                         if( c == '\\' || c == ':' )
+                         {
+                                 iswinpath = TRUE;
+                                 break;
+                         }
+                       }
+                       if( iswinpath )
+                       {
+                               char buff[PATH_MAX];
+                               if ( winpath2unix( file, 0, buff,
sizeof(buff) ) != 0 )
+                               {
+                                       mprintf( "ERROR: Unable to convert
Windows path \"%s\" to POSIX.\n", file );
+                                       return NULL;
+                               }
+                               filelist[i] = &buff;
+                       }
+                       #endif
+                       len += strlen(argv[i]);
+               }
+               len += argc - optind - 1;
+               opt->filename = (char *) mcalloc(len + 64, sizeof(char));
+               if(!opt->filename) 
+               {
+                       mprintf("!opt_parse: mcalloc failed\n");
+                       opt_free(opt);
+                       return NULL;
+               }
+               for(i = optind; i < argc; i++) 
+               {
+                       #ifdef __INTERIX
+                       strncat(opt->filename, filelist[i],
strlen(argv[i]));
+                       #else
+                       strncat(opt->filename, argv[i], strlen(argv[i]));
+                       #endif
+                       if(i != argc - 1)
+                       strncat(opt->filename, "\t", 1);
+               }
     }
 
     return opt;
diff -ru clamav-devel/shared/output.h clamav-devel-interix/shared/output.h
--- clamav-devel/shared/output.h        Sun Apr  9 15:59:28 2006
+++ clamav-devel-interix/shared/output.h        Wed Jun  7 14:46:01 2006
@@ -22,6 +22,10 @@
 
 #if HAVE_CONFIG_H
 #include "clamav-config.h"
+# ifdef __INTERIX
+#  undef HAVE_POLL_H
+#  undef HAVE_POLL
+# endif
 #endif
 
 #include <stdlib.h>

Brian A. Reiter
WolfeReiter, LLC : Thoughtful Computing
[http://www.thoughtfulcomputing.com]

_______________________________________________
http://lurker.clamav.net/list/clamav-devel.html

Reply via email to