#include "vdr_compat.h"
#include <stdarg.h>
#include <vdr/interface.h>

#if VDRVERSNUM < 10300

// --- cString ----------------------------------------------------------------

cString::cString(const char *S, bool TakePointer)
{
  s = TakePointer ? (char *)S : S ? strdup(S) : NULL;
}

cString::~cString()
{
  free(s);
}

cString &cString::operator=(const cString &String)
{
  free(s);
  s = String.s ? strdup(String.s) : NULL;
  return *this;
}

cString cString::sprintf(const char *fmt, ...)
{
  va_list ap;
  va_start(ap, fmt);
  char *buffer;
  vasprintf(&buffer, fmt, ap);
  return cString(buffer, true);
}

// --- cSkins -----------------------------------------------------------------

cSkins Skins;

eKeys cSkins::Message(eMessageType Type, const char *s, int Seconds)
{
	switch (Type) {
		case mtStatus: Interface->Status(s); break;
		case mtInfo:   Interface->Info(s); break;
		case mtWarning:
		case mtError:  Interface->Error(s); break;
	}
	return kNone;
}

void cSkins::Flush(void)
{
	Interface->Flush();
}

// --- cRecordings -----------------------------------------------------------

cRecordings Recordings;

// --- cReadDir --------------------------------------------------------------

cReadDir::cReadDir(const char *Directory)
{
  directory = opendir(Directory);
}

cReadDir::~cReadDir()
{
  if (directory)
     closedir(directory);
}

struct dirent *cReadDir::Next(void)
{
  return directory && readdir_r(directory, &u.d, &result) == 0 ? result : NULL;
}

#endif
