Subversion Repositories Kolibri OS

Rev

Rev 8179 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8140 IgorA 1
#ifndef __KOLIBRI_FILE_H_INCLUDED_
2
#define __KOLIBRI_FILE_H_INCLUDED_
3
 
4
#include "kolibri.h"
5
#include "kos_heap.h"
6
 
7
// Kolibri file interface.
8
 
9
namespace Kolibri   // All kolibri functions, types and data are nested in the (Kolibri) namespace.
10
{
8179 IgorA 11
	struct FileDateTime{
12
		unsigned long int time;
13
		unsigned long int date;
14
	};
15
	struct FileInfoBlock
8140 IgorA 16
	{
8179 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;
8140 IgorA 24
	};
8179 IgorA 25
	struct FileInfoA
8140 IgorA 26
	{
8179 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
	};
8140 IgorA 36
 
37
// Functions.
38
 
8179 IgorA 39
	int _FileAccess(FileInfoBlock *file_access);
8140 IgorA 40
 
8179 IgorA 41
	FileInfoBlock* FileOpen(const char *name)
8140 IgorA 42
	{
8179 IgorA 43
		if (!name || !name[0]){
44
			//DebugPutString("name is 0");
45
			return 0;
8140 IgorA 46
		}
8179 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);
8140 IgorA 63
		return file;
64
	}
65
 
8179 IgorA 66
	int FileClose(FileInfoBlock* file_data)
8140 IgorA 67
	{
68
		if (!file_data) return -1;
69
		Free(file_data);
70
		return 0;
71
	}
72
 
8179 IgorA 73
	unsigned long int FileRead(FileInfoBlock* file_data, void *mem, int size)
8140 IgorA 74
	{
8179 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;
8140 IgorA 80
 
8179 IgorA 81
		if(!_FileAccess(file_data)) return file_data->Function;
8140 IgorA 82
		else return 0;
83
	}
9675 IgorA 84
 
85
	unsigned long int FileCreate(FileInfoBlock* file_data, void *mem, int size)
86
	{
87
		file_data->Function = 2; //SSF_CREATE_FILE
88
		file_data->Position = 0;
89
		file_data->Flags = 0;
90
		file_data->Count = size;
91
		file_data->Buffer = (char*)mem;
92
 
93
		if(!_FileAccess(file_data)) return file_data->Function;
94
		else return 0;
95
	}
96
 
8140 IgorA 97
// Inline functions.
98
 
8179 IgorA 99
	inline unsigned long int FileGetLength(FileInfoBlock* file_data)
8140 IgorA 100
	{
101
		if (!file_data) return -1;
8179 IgorA 102
		return (unsigned long int)*(long*)((char*)file_data+sizeof(FileInfoBlock)+32);
8140 IgorA 103
	}
104
}
105
 
106
#endif  // ndef __KOLIBRI_FILE_H_INCLUDED_
107