Rev 8170 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8133 | IgorA | 1 | #ifndef __KOLIBRI_FILE_H_INCLUDED_ |
2 | #define __KOLIBRI_FILE_H_INCLUDED_ |
||
8129 | IgorA | 3 | |
8184 | IgorA | 4 | #include "kolibri.h" |
5 | #include "kos_heap.h" |
||
8129 | IgorA | 6 | |
7 | // Kolibri file interface. |
||
8 | |||
9 | namespace Kolibri // All kolibri functions, types and data are nested in the (Kolibri) namespace. |
||
10 | { |
||
8184 | IgorA | 11 | struct FileDateTime{ |
12 | unsigned long int time; |
||
13 | unsigned long int date; |
||
14 | }; |
||
15 | struct FileInfoBlock |
||
8129 | IgorA | 16 | { |
8184 | IgorA | 17 | unsigned long int Function; |
18 | unsigned long int Position; |
||
19 | unsigned long int Flags; |
||
20 | unsigned long int Count; |
||
21 | char *Buffer; |
||
22 | char *FileName1; |
||
23 | char *FileName2; |
||
8129 | IgorA | 24 | }; |
8184 | IgorA | 25 | struct FileInfoA |
8129 | IgorA | 26 | { |
8184 | IgorA | 27 | unsigned long int Attributes; |
28 | unsigned long int Flags; |
||
29 | FileDateTime DateCreate; |
||
30 | FileDateTime DateAccess; |
||
31 | FileDateTime DateModify; |
||
32 | unsigned long int FileSizeLow; |
||
33 | unsigned long int FileSizeHigh; |
||
34 | char FileName[520]; |
||
35 | }; |
||
8129 | IgorA | 36 | |
37 | // Functions. |
||
38 | |||
8184 | IgorA | 39 | int _FileAccess(FileInfoBlock *file_access); |
8129 | IgorA | 40 | |
8184 | IgorA | 41 | FileInfoBlock* FileOpen(const char *name) |
8129 | IgorA | 42 | { |
8184 | IgorA | 43 | if (!name || !name[0]){ |
44 | DebugPutString("name is 0"); |
||
45 | return 0; |
||
8129 | IgorA | 46 | } |
8184 | IgorA | 47 | FileInfoBlock* file = (FileInfoBlock*)Alloc(sizeof(FileInfoBlock)+sizeof(FileInfoA)); |
48 | if (!file){ |
||
49 | DebugPutString("mem_Alloc -> 0"); |
||
50 | return 0; |
||
51 | } |
||
52 | file->Function = 5; //SSF_GET_INFO |
||
53 | file->Position = 0; |
||
54 | file->Flags = 0; |
||
55 | file->Count = 0; |
||
56 | file->Buffer = (char*)file+sizeof(FileInfoBlock); |
||
57 | file->FileName1 = (char*)name; |
||
58 | file->FileName2 = (char*)name; |
||
59 | file->FileName1 = (char*)((long)file->FileName1 << 8); |
||
60 | file->FileName2 = (char*)((long)file->FileName2 >> 24); |
||
61 | |||
62 | _FileAccess(file); |
||
8129 | IgorA | 63 | return file; |
64 | } |
||
65 | |||
8184 | IgorA | 66 | int FileClose(FileInfoBlock* file_data) |
8129 | IgorA | 67 | { |
68 | if (!file_data) return -1; |
||
69 | Free(file_data); |
||
70 | return 0; |
||
71 | } |
||
72 | |||
8184 | IgorA | 73 | unsigned long int FileRead(FileInfoBlock* file_data, void *mem, int size) |
8129 | IgorA | 74 | { |
8184 | IgorA | 75 | file_data->Function = 0; //SSF_READ_FILE |
76 | file_data->Position = 0; |
||
77 | file_data->Flags = 0; |
||
78 | file_data->Count = size; |
||
79 | file_data->Buffer = (char*)mem; |
||
8129 | IgorA | 80 | |
8184 | IgorA | 81 | if(!_FileAccess(file_data)) return file_data->Function; |
8129 | IgorA | 82 | else return 0; |
83 | } |
||
84 | |||
85 | // Inline functions. |
||
86 | |||
8184 | IgorA | 87 | inline unsigned long int FileGetLength(FileInfoBlock* file_data) |
8129 | IgorA | 88 | { |
89 | if (!file_data) return -1; |
||
8184 | IgorA | 90 | return (unsigned long int)*(long*)((char*)file_data+sizeof(FileInfoBlock)+32); |
8129 | IgorA | 91 | } |
92 | } |
||
93 | |||
8133 | IgorA | 94 | #endif // ndef __KOLIBRI_FILE_H_INCLUDED_><> |
8129 | IgorA | 95 |