/* save_bitmap.c -- How to save a BITMAP *. */

/* Copyright (C) 1988, 1990, 1992 Free Software Foundation, Inc.

   This file is part of GNU Finger.

   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, 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 <config.h>
#include <sys/types.h>
#include <sys/file.h>

#include <bitmap.h>

#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif

extern int errno;

#ifndef L_SET
#define L_SET SEEK_SET
#define L_INCR SEEK_CUR
#endif /* !L_SET */

int
save_bitmap (user, face)
     char *user;
     BITMAP *face;
{
  char *mugshot_filename (), *filename = mugshot_filename (user);
  int file;

  file = open (filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  free (filename);

  if (!file)
    return (errno);

  write (file, &face->width, sizeof (face->width));
  write (file, &face->height, sizeof (face->height));
  write (file, &face->rowlen, sizeof (face->rowlen));

  write (file, face->bits, face->rowlen * face->height);

  close (file);
  return (0);
}
