#ifdef AMIGA

/* This file contains wrappers for some unix functions that make lcc work
   with as little modification to the original source as possible.
*/

#undef write

#ifndef __LCC__
#include <unistd.h>
#endif
#include <stddef.h>
#include <sys/types.h>

/* The original version of lcc opens the output file, then dup2's it to
   file descriptor 1 (stdout). Since dup2 is not available on the amiga,
   we work around this by storing the file descriptor of the output file
   in __fdo, and replacing write with amy_write (using -Dwrite=amy_write),
   which writes to __fdo whenever it is asked to write to stdout.
*/

int __fdo;

int
amy_write(int fh, char *buffer, size_t length)
{
  if (fh == 1) {
    fh = __fdo;
  }
  return write(fh, buffer, length);
}
#endif
