octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MSVC compiler support [patch 20]: opendir, readdir, ...


From: Michael Goffioul
Subject: MSVC compiler support [patch 20]: opendir, readdir, ...
Date: Tue, 17 Oct 2006 21:53:31 +0200
User-agent: Thunderbird 1.5.0.7 (Windows/20060909)

Win32 implementation of opendir, readdir...

Index: liboctave/dir-ops.cc
===================================================================
RCS file: /cvs/octave/liboctave/dir-ops.cc,v
retrieving revision 1.9
diff -p -c -r1.9 dir-ops.cc
*** liboctave/dir-ops.cc        30 Jun 2006 16:48:39 -0000      1.9
--- liboctave/dir-ops.cc        17 Oct 2006 11:07:41 -0000
*************** Software Foundation, Inc., 51 Franklin S
*** 37,42 ****
--- 37,100 ----
  #include "lo-sysdep.h"
  #include "str-vec.h"
  
+ #ifdef _MSC_VER
+ #include <windows.h>
+ 
+ struct direct {
+       char *d_name;
+ };
+ 
+ typedef struct {
+       HANDLE hnd;
+       WIN32_FIND_DATA fd;
+       int dirty;
+       struct direct d;
+       const char* current;
+ } DIR;
+ 
+ DIR* opendir(const char *name)
+ {
+       DIR *d = (DIR*)malloc(sizeof(DIR));
+       static char buffer[MAX_PATH];
+ 
+       strncpy(buffer, name, MAX_PATH);
+       strncat(buffer, "\\*", MAX_PATH);
+       d->current = buffer;
+       d->hnd = FindFirstFile(buffer, &(d->fd));
+       if (d->hnd == INVALID_HANDLE_VALUE)
+               return NULL;
+       d->dirty = 1;
+       return d;
+ }
+ 
+ void rewinddir(DIR* d)
+ {
+       if (d->hnd != INVALID_HANDLE_VALUE)
+               FindClose(d->hnd);
+       d->hnd = FindFirstFile(d->current, &(d->fd));
+       d->dirty = 1;
+ }
+ 
+ void closedir(DIR *d)
+ {
+       if (d->hnd != INVALID_HANDLE_VALUE)
+               FindClose(d->hnd);
+       free(d);
+ }
+ 
+ struct direct* readdir(DIR *d)
+ {
+       if (!d->dirty)
+       {
+               if (!FindNextFile(d->hnd, &(d->fd)))
+                       return NULL;
+       }
+       d->d.d_name = d->fd.cFileName;
+       d->dirty = 0;
+       return &(d->d);
+ }
+ #endif
+ 
  bool
  dir_entry::open (const std::string& n)
  {

reply via email to

[Prev in Thread] Current Thread [Next in Thread]