]> icculus.org git repositories - btb/d2x.git/blob - arch/win32/findfile.c
use closesocket() instead of close()
[btb/d2x.git] / arch / win32 / 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 #ifdef HAVE_CONFIG_H
15 #include <conf.h>
16 #endif
17
18 #define WIN32_LEAN_AND_MEAN
19 #include <windows.h>
20 #include "findfile.h"
21
22
23 //      Global Variables        ----------------------------------------------------------
24
25 static HANDLE   _FindFileHandle = INVALID_HANDLE_VALUE;
26
27
28
29 //      Functions
30
31 int     FileFindFirst(char *search_str, FILEFINDSTRUCT *ffstruct)
32 {
33         WIN32_FIND_DATA find;
34
35         _FindFileHandle =  FindFirstFile((LPSTR)search_str, &find);
36         if (_FindFileHandle == INVALID_HANDLE_VALUE) return 1;
37         else {
38                 ffstruct->size = find.nFileSizeLow;
39                 strcpy(ffstruct->name, find.cFileName);
40                 return 0; 
41         }
42 }
43
44
45 int     FileFindNext(FILEFINDSTRUCT *ffstruct)
46 {
47         WIN32_FIND_DATA find;
48
49         if (!FindNextFile(_FindFileHandle, &find)) return 1;
50         else {
51                 ffstruct->size = find.nFileSizeLow;
52                 strcpy(ffstruct->name, find.cFileName);
53                 return 0;
54         }
55 }
56  
57
58 int     FileFindClose(void)
59 {
60         if (!FindClose(_FindFileHandle)) return 1;
61         else return 0;
62 }
63
64
65 int GetFileDateTime(int filehandle, FILETIMESTRUCT *ftstruct)
66 {
67         FILETIME filetime;
68         int retval;
69
70         retval = GetFileTime((HANDLE)filehandle, NULL, NULL, &filetime);
71         if (retval) {
72                 FileTimeToDosDateTime(&filetime, &ftstruct->date, &ftstruct->time);
73                 return 0;
74         }
75         else return 1;
76 }
77
78
79 //returns 0 if no error
80 int SetFileDateTime(int filehandle, FILETIMESTRUCT *ftstruct)
81 {
82         FILETIME ft;
83         int retval;
84
85         DosDateTimeToFileTime(ftstruct->date, ftstruct->time, &ft);
86         retval = SetFileTime((HANDLE)filehandle, NULL, NULL, &ft);      
87         if (retval) return 0;
88         else return 1;
89 }