]> icculus.org git repositories - btb/d2x.git/blob - arch/dos_findfile.c
updated documentation
[btb/d2x.git] / arch / dos_findfile.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14
15 #include <conf.h>
16 #ifdef __ENV_DJGPP__
17
18 #include <dos.h>
19 #include <string.h>
20
21 #include "findfile.h"
22
23
24 //      Global Variables        ----------------------------------------------------------
25
26 static int                              _FileFindFlag = 0;
27 static struct find_t _FileFindStruct;
28
29
30
31 //      Functions
32
33 int     FileFindFirst(char *search_str, FILEFINDSTRUCT *ffstruct)
34 {
35         unsigned retval;
36         
37         if (_FileFindFlag) return -1;
38         
39         retval = _dos_findfirst(search_str, 0, &_FileFindStruct);
40         if (retval) return (int)retval;
41         else {
42                 ffstruct->size = _FileFindStruct.size;
43                 strcpy(ffstruct->name, _FileFindStruct.name);
44                 _FileFindFlag = 1;
45                 return (int)retval;
46         }
47 }
48
49
50 int     FileFindNext(FILEFINDSTRUCT *ffstruct)
51 {
52         unsigned retval;
53
54         if (!_FileFindFlag) return -1;
55
56         retval = _dos_findnext(&_FileFindStruct);
57         if (retval) return (int)retval;
58         else {
59                 ffstruct->size = _FileFindStruct.size;
60                 strcpy(ffstruct->name, _FileFindStruct.name);
61                 return (int)retval;
62         }       
63 }
64  
65
66 int     FileFindClose(void)
67 {
68         unsigned retval = 0;
69
70         if (!_FileFindFlag) return -1;
71         
72         if (retval) return (int)retval;
73         else {
74                 _FileFindFlag = 0;
75                 return (int)retval;
76         }
77 }
78
79
80 //returns 0 if no error
81 int GetFileDateTime(int filehandle, FILETIMESTRUCT *ftstruct)
82 {
83         return _dos_getftime(filehandle, &ftstruct->date, &ftstruct->time);
84
85 }
86
87
88 //returns 0 if no error
89 int SetFileDateTime(int filehandle, FILETIMESTRUCT *ftstruct)
90 {
91         return _dos_setftime(filehandle, ftstruct->date, ftstruct->time);
92 }
93
94
95 #endif //__ENV_DJGPP__