/*
 *  smoke16/libObj/src/TmpFile.c - Functions to manage temporary files.
 *  $Revision: 1.6 $
 *  Copyright 1997, 2000, Benjamin Sittler
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <smoke16/libObj.h>

TmpFile *newTmpFile(void) {
  TmpFile *tmp = (TmpFile *) malloc(sizeof(TmpFile));

  if (tmp) {
    tmp -> name = "(tmpfile)";
    if ((tmp -> file = tmpfile())) {
      return tmp;
    } else
      perror("tmpfile");
    free(tmp);
  } else
    perror("malloc");
  return 0;
}

void freeTmpFile(TmpFile *tmp) {
  if (fclose(tmp -> file)) {
    fputs(tmp -> name, stderr);
    perror(": fclose");
  }
  free(tmp);
}
