Subversion Repositories Kolibri OS

Rev

Rev 8170 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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. {
  11.         struct FileDateTime{
  12.                 unsigned long int time;
  13.                 unsigned long int date;
  14.         };
  15.         struct FileInfoBlock
  16.         {
  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;
  24.         };
  25.         struct FileInfoA
  26.         {
  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.         };
  36.  
  37. // Functions.
  38.  
  39.         int _FileAccess(FileInfoBlock *file_access);
  40.  
  41.         FileInfoBlock* FileOpen(const char *name)
  42.         {
  43.                 if (!name || !name[0]){
  44.                         DebugPutString("name is 0");
  45.                         return 0;
  46.                 }
  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);
  63.                 return file;
  64.         }
  65.  
  66.         int FileClose(FileInfoBlock* file_data)
  67.         {
  68.                 if (!file_data) return -1;
  69.                 Free(file_data);
  70.                 return 0;
  71.         }
  72.  
  73.         unsigned long int FileRead(FileInfoBlock* file_data, void *mem, int size)
  74.         {
  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;
  80.  
  81.                 if(!_FileAccess(file_data)) return file_data->Function;
  82.                 else return 0;
  83.         }
  84.        
  85. // Inline functions.
  86.  
  87.         inline unsigned long int FileGetLength(FileInfoBlock* file_data)
  88.         {
  89.                 if (!file_data) return -1;
  90.                 return (unsigned long int)*(long*)((char*)file_data+sizeof(FileInfoBlock)+32);
  91.         }
  92. }
  93.  
  94. #endif  // ndef __KOLIBRI_FILE_H_INCLUDED_
  95.  
  96.