Subversion Repositories SvarDOS

Rev

Rev 2045 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2045 Rev 2046
Line 65... Line 65...
65
  findData->nFileSizeLow = (DWORD)finfo->ff_fsize;
65
  findData->nFileSizeLow = (DWORD)finfo->ff_fsize;
66
  findData->dwReserved0 = 0;
66
  findData->dwReserved0 = 0;
67
  findData->dwReserved1 = 0;
67
  findData->dwReserved1 = 0;
68
}
68
}
69
 
69
 
70
HANDLE FindFirstFile(const char *pathname, struct WIN32_FIND_DATA *findData)
70
struct FFDTA *FindFirstFile(const char *pathname, struct WIN32_FIND_DATA *findData)
71
{
71
{
72
  static char path[1024];
72
  static char path[1024];
73
  HANDLE hnd;
73
  struct FFDTA *hnd;
74
  short cflag = 0;  /* used to indicate if findfirst is succesful or not */
74
  short cflag = 0;  /* used to indicate if findfirst is succesful or not */
75
 
75
 
76
  /* verify findData is valid */
76
  /* verify findData is valid */
77
  if (findData == NULL)
77
  if (findData == NULL)
78
    return INVALID_HANDLE_VALUE;
78
    return INVALID_HANDLE_VALUE;
79
 
79
 
80
  /* allocate memory for the handle */
80
  /* allocate memory for the handle */
81
  if ((hnd = (HANDLE)malloc(sizeof(struct FindFileStruct))) == NULL)
81
  if ((hnd = malloc(sizeof(*hnd))) == NULL) return INVALID_HANDLE_VALUE;
82
    return INVALID_HANDLE_VALUE;
-
 
83
 
82
 
84
  /* initialize structure (clear) */
83
  /* initialize structure (clear) */
85
  /* hnd->handle = 0;  hnd->ffdtaptr = NULL; */
84
  /* hnd->handle = 0;  hnd->ffdtaptr = NULL; */
86
  memset(hnd, 0, sizeof(struct FindFileStruct));
85
  memset(hnd, 0, sizeof(*hnd));
87
 
86
 
88
  /* Clear findData, this is to fix a glitch under NT, with 'special' $???? files */
87
  /* Clear findData, this is to fix a glitch under NT, with 'special' $???? files */
89
  memset(findData, 0, sizeof(struct WIN32_FIND_DATA));
88
  memset(findData, 0, sizeof(struct WIN32_FIND_DATA));
90
 
89
 
91
  /* Use DOS (0x4E) findfirst, returning if error */
-
 
92
  hnd->flag = FINDFILEOLD;
-
 
93
 
-
 
94
  /* allocate memory for the FFDTA */
-
 
95
  if ((hnd->fhnd.ffdtaptr = (struct FFDTA *)malloc(sizeof(struct FFDTA))) == NULL)
-
 
96
  {
-
 
97
    free(hnd);
-
 
98
    return INVALID_HANDLE_VALUE;
-
 
99
  }
-
 
100
 
-
 
101
  /* if pathname ends in \* convert to \*.* */
90
  /* if pathname ends in \* convert to \*.* */
102
  strcpy(path, pathname);
91
  strcpy(path, pathname);
103
  {
92
  {
104
  int eos = strlen(path) - 1;
93
  int eos = strlen(path) - 1;
105
  if ((path[eos] == '*') && (path[eos - 1] == '\\')) strcat(path, ".*");
94
  if ((path[eos] == '*') && (path[eos - 1] == '\\')) strcat(path, ".*");
Line 107... Line 96...
107
 
96
 
108
  {
97
  {
109
    unsigned short ffdta_seg, ffdta_off;
98
    unsigned short ffdta_seg, ffdta_off;
110
    unsigned short path_seg, path_off;
99
    unsigned short path_seg, path_off;
111
    unsigned short sattr = searchAttr;
100
    unsigned short sattr = searchAttr;
112
    ffdta_seg = FP_SEG((*hnd).fhnd.ffdtaptr);
101
    ffdta_seg = FP_SEG(hnd);
113
    ffdta_off = FP_OFF((*hnd).fhnd.ffdtaptr);
102
    ffdta_off = FP_OFF(hnd);
114
    path_seg = FP_SEG(path);
103
    path_seg = FP_SEG(path);
115
    path_off = FP_OFF(path);
104
    path_off = FP_OFF(path);
116
 
105
 
117
  _asm {
106
  _asm {
118
    push ax
107
    push ax
Line 154... Line 143...
154
    pop bx
143
    pop bx
155
    pop ax
144
    pop ax
156
  }
145
  }
157
  }
146
  }
158
 
147
 
159
  if (cflag)
148
  if (cflag) {
160
  {
-
 
161
    free(hnd->fhnd.ffdtaptr);
-
 
162
    free(hnd);
149
    free(hnd);
163
    return INVALID_HANDLE_VALUE;
150
    return INVALID_HANDLE_VALUE;
164
  }
151
  }
165
 
152
 
166
  /* copy its results over */
153
  /* copy its results over */
167
  copyFileData(findData, hnd->fhnd.ffdtaptr);
154
  copyFileData(findData, hnd);
168
 
155
 
169
  return hnd;
156
  return hnd;
170
}
157
}
171
 
158
 
172
 
159
 
173
int FindNextFile(HANDLE hnd, struct WIN32_FIND_DATA *findData)
160
int FindNextFile(struct FFDTA *hnd, struct WIN32_FIND_DATA *findData) {
174
{
-
 
175
  short cflag = 0;  /* used to indicate if dos findnext succesful or not */
161
  short cflag = 0;  /* used to indicate if dos findnext succesful or not */
176
 
162
 
177
  /* if bad handle given return */
163
  /* if bad handle given return */
178
  if ((hnd == NULL) || (hnd == INVALID_HANDLE_VALUE)) return 0;
164
  if (hnd == NULL) return 0;
179
 
165
 
180
  /* verify findData is valid */
166
  /* verify findData is valid */
181
  if (findData == NULL) return 0;
167
  if (findData == NULL) return 0;
182
 
168
 
183
  /* Clear findData, this is to fix a glitch under NT, with 'special' $???? files */
169
  /* Clear findData, this is to fix a glitch under NT, with 'special' $???? files */
184
  memset(findData, 0, sizeof(struct WIN32_FIND_DATA));
170
  memset(findData, 0, sizeof(struct WIN32_FIND_DATA));
185
 
171
 
186
  /* Flag indicate if using LFN DOS (0x714F) or not */
-
 
187
  if (hnd->flag == FINDFILELFN)
-
 
188
  {
-
 
189
    unsigned short handle = hnd->fhnd.handle;
-
 
190
    unsigned char cf = 0;
-
 
191
    _asm {
-
 
192
      push ax
-
 
193
      push bx
-
 
194
      push cx
-
 
195
      push dx
-
 
196
      push es
-
 
197
      push si
-
 
198
      push di
-
 
199
 
-
 
200
      mov bx, handle               //; Move the Handle returned by prev findfirst into BX
-
 
201
      stc                          //; In case not supported
-
 
202
      mov si, 1                    //; same format as when old style used, set to 0 for 64bit value
-
 
203
      mov ax, ds                   //; Set address of findData into ES:DI
-
 
204
      mov es, ax
-
 
205
      mov di, [findData]
-
 
206
      mov ax, 0x714F               //; LFN version of FindNext
-
 
207
      int 0x21                     //; Execute interrupt
-
 
208
      jnc DONE
-
 
209
      mov cf, 1
-
 
210
      DONE:
-
 
211
 
-
 
212
      pop di
-
 
213
      pop si
-
 
214
      pop es
-
 
215
      pop dx
-
 
216
      pop cx
-
 
217
      pop bx
-
 
218
      pop ax
-
 
219
    }
-
 
220
    if (cf == 0) return 1;   /* success */
-
 
221
    return 0;   /* Any errors here, no other option but to return error/no more files */
-
 
222
  } else { /* Use DOS (0x4F) findnext, returning if error */
172
  { /* Use DOS (0x4F) findnext, returning if error */
223
    unsigned short dta_seg = FP_SEG((*hnd).fhnd.ffdtaptr);
173
    unsigned short dta_seg = FP_SEG(hnd);
224
    unsigned short dta_off = FP_OFF((*hnd).fhnd.ffdtaptr);
174
    unsigned short dta_off = FP_OFF(hnd);
225
    _asm {
175
    _asm {
226
      push ax
176
      push ax
227
      push bx
177
      push bx
228
      push cx
178
      push cx
229
      push dx
179
      push dx
Line 255... Line 205...
255
      pop dx
205
      pop dx
256
      pop cx
206
      pop cx
257
      pop bx
207
      pop bx
258
      pop ax
208
      pop ax
259
    }
209
    }
-
 
210
  }
260
 
211
 
261
  if (cflag) return 0;
212
  if (cflag) return 0;
262
 
213
 
263
  /* copy its results over */
214
  /* copy its results over */
264
  copyFileData(findData, hnd->fhnd.ffdtaptr);
215
  copyFileData(findData, hnd);
265
 
216
 
266
  return 1;
217
  return 1;
267
  }
-
 
268
}
218
}
269
 
219
 
270
 
220
 
271
/* free resources to prevent memory leaks */
221
/* free resources to prevent memory leaks */
272
void FindClose(HANDLE hnd)
222
void FindClose(struct FFDTA *hnd) {
273
{
-
 
274
  /* 1st check if valid handle given */
223
  /* 1st check if valid handle given */
275
  if ((hnd != NULL) && (hnd != INVALID_HANDLE_VALUE))
-
 
276
  {
-
 
277
    /* See if its for the new or old style findfirst */
-
 
278
    if (hnd->flag == FINDFILEOLD) /* Just free memory allocated */
-
 
279
    {
-
 
280
      if (hnd->fhnd.ffdtaptr != NULL)
-
 
281
        free(hnd->fhnd.ffdtaptr);
-
 
282
      hnd->fhnd.ffdtaptr = NULL;
-
 
283
    }
-
 
284
    else /* must call LFN findclose */
-
 
285
    {
-
 
286
      unsigned short handle = hnd->fhnd.handle;
-
 
287
      _asm {
-
 
288
        push ax
-
 
289
        push bx
-
 
290
 
-
 
291
        mov bx, handle            /* Move handle returned from findfirst into BX */
-
 
292
        stc
-
 
293
        mov ax, 0x71A1
-
 
294
        int 0x21                  /* carry set on error */
-
 
295
 
-
 
296
        pop bx
-
 
297
        pop ax
-
 
298
      }
-
 
299
      hnd->fhnd.handle = 0;
224
  if (hnd == NULL) return;
300
    }
-
 
301
 
-
 
302
    free(hnd);                    /* Free memory used for the handle itself */
225
  free(hnd);                    /* Free memory used for the handle itself */
303
  }
-
 
304
}
226
}
305
 
227
 
306
#include <stdio.h>
228
#include <stdio.h>
307
 
229
 
308
/**
230
/**