#ifndef __AUXFNS_H__
#define __AUXFNS_H__

// helper functions

char* DupStr(const char *source);
char* GetAppPathPlus(const char* filename = NULL);
char* GetBasePath(const char* name);
char* GetRelPath(const char* Base, const char* Abs);
char* GetAbsPath(const char* Base, const char* Rel);

BOOL StoreItem(HANDLE file, char* string);
BOOL LoadItem(HANDLE file, char*& string);

template<class T> void SafeDelArray(T *&array)
{
  if(!array) return;
  delete[] array;
  array = NULL;
}

template<class T> void SafeDel(T *&pointer)
{
  if(!pointer) return;
  delete pointer;
  pointer = NULL;
}

template<class T> BOOL StoreItem(HANDLE file, const T& item)
{
  DWORD bw, size = sizeof(T);
  WriteFile( file, &item, size, &bw, NULL);
  return (bw == size);
}

template<class T> BOOL LoadItem(HANDLE file, T& item)
{
  DWORD br, size = sizeof(T);
  ReadFile( file, &item, size, &br, NULL);
  return (br == size);
}

BOOL StoreFileName(HANDLE file, char* fname, char* BasePath);
BOOL LoadFileName(HANDLE file, char*& fname, char* BasePath);

#endif


