#ifndef PORTABLE_H
#define PORTABLE_H

#include <stdio.h>
#include <sys/types.h>
#include <stdint.h>

#include <fstream>

#include "containers.h"
#include "qcstring.h"

class Buf;

/** @file
 *  @brief Portable versions of functions that are platform dependent.
 */

namespace Portable
{
  int            system(const OGString &command,const OGString &args,bool commandHasConsole=true);
  uint32_t       pid();
  OGString       getenv(const OGString &variable);
  void           setenv(const OGString &variable,const OGString &value);
  void           unsetenv(const OGString &variable);
  FILE *         fopen(const OGString &fileName,const OGString &mode);
  int            fclose(FILE *f);
  void           unlink(const OGString &fileName);
  OGString       pathSeparator();
  OGString       pathListSeparator();
  const char *   ghostScriptCommand();
  const char *   commandExtension();
  bool           fileSystemIsCaseSensitive();
  FILE *         popen(const OGString &name,const OGString &type);
  int            pclose(FILE *stream);
  double         getSysElapsedTime();
  bool           isAbsolutePath(const OGString &fileName);
  void           correctPath(const StringVector &list);
  void           setShortDir();
  const char *   strnstr(const char *haystack, const char *needle, size_t haystack_len);
  const char *   devNull();
  bool           checkForExecutable(const OGString &fileName);
  size_t         recodeUtf8StringToW(const OGString &inputStr,uint16_t **buf);
  std::ofstream  openOutputStream(const OGString &name,bool append=false);
  std::ifstream  openInputStream(const OGString &name,bool binary=false,bool openAtEnd=false);
}


extern "C" {
  void *         portable_iconv_open(const char *tocode, const char *fromcode);
  size_t         portable_iconv (void *cd, const char** inbuf, size_t *inbytesleft,
                                 char* * outbuf, size_t *outbytesleft);
  int            portable_iconv_close (void *cd);
}

#endif

