Blame tests/t-syserror.c

Packit fc043f
/* t-syserror.c - System error specific regression test.
Packit fc043f
   Copyright (C) 2006 g10 Code GmbH
Packit fc043f
Packit fc043f
   This file is part of libgpg-error.
Packit fc043f
Packit fc043f
   libgpg-error is free software; you can redistribute it and/or
Packit fc043f
   modify it under the terms of the GNU Lesser General Public License
Packit fc043f
   as published by the Free Software Foundation; either version 2.1 of
Packit fc043f
   the License, or (at your option) any later version.
Packit fc043f
Packit fc043f
   libgpg-error is distributed in the hope that it will be useful, but
Packit fc043f
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit fc043f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit fc043f
   Lesser General Public License for more details.
Packit fc043f
Packit fc043f
   You should have received a copy of the GNU Lesser General Public
Packit fc043f
   License along with libgpgme-error; if not, write to the Free
Packit fc043f
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit fc043f
   02110-1301, USA.  */
Packit fc043f
Packit fc043f
Packit fc043f
#if HAVE_CONFIG_H
Packit fc043f
#include <config.h>
Packit fc043f
#endif
Packit fc043f
Packit fc043f
#include <stdio.h>
Packit fc043f
#if HAVE_STDLIB_H
Packit fc043f
#include <stdlib.h>
Packit fc043f
#endif
Packit fc043f
#include <errno.h>
Packit fc043f
Packit fc043f
#include <gpg-error.h>
Packit fc043f
Packit fc043f
int
Packit fc043f
main (int argc, char *argv[])
Packit fc043f
{
Packit fc043f
  FILE *fp;
Packit fc043f
  int save_errno;
Packit fc043f
  gpg_err_code_t ec;
Packit fc043f
Packit fc043f
  (void)argc;
Packit fc043f
  (void)argv;
Packit fc043f
Packit fc043f
  fp = fopen ("/does-not-exist/110761/nowhere.foo", "r");
Packit fc043f
  if (fp)
Packit fc043f
    {
Packit fc043f
      fclose (fp);
Packit fc043f
      fp = fopen ("  no this file does not exists foo 4711", "r");
Packit fc043f
    }
Packit fc043f
  if (fp)
Packit fc043f
    {
Packit fc043f
      fprintf (stderr, "unable to run test\n");
Packit fc043f
      return 1;
Packit fc043f
    }
Packit fc043f
  save_errno = errno;
Packit fc043f
Packit fc043f
  ec = gpg_err_code_from_syserror ();
Packit fc043f
  if (ec != GPG_ERR_ENOENT)
Packit fc043f
    {
Packit fc043f
      fprintf (stderr, "fopen failed with bad code: %d\n", save_errno);
Packit fc043f
      return 1;
Packit fc043f
    }
Packit fc043f
Packit fc043f
  if (ec != gpg_err_code_from_errno (save_errno))
Packit fc043f
    {
Packit fc043f
      fprintf (stderr, "oops at %d\n",__LINE__);
Packit fc043f
      return 1;
Packit fc043f
    }
Packit fc043f
Packit fc043f
  gpg_err_set_errno (0);
Packit fc043f
Packit fc043f
  ec = gpg_err_code_from_syserror ();
Packit fc043f
  if (ec != GPG_ERR_MISSING_ERRNO)
Packit fc043f
    {
Packit fc043f
      fprintf (stderr, "oops at %d\n",__LINE__);
Packit fc043f
      return 1;
Packit fc043f
    }
Packit fc043f
Packit fc043f
  if ( gpg_err_code_from_errno (0) )
Packit fc043f
    {
Packit fc043f
      fprintf (stderr, "oops at %d\n",__LINE__);
Packit fc043f
      return 1;
Packit fc043f
    }
Packit fc043f
Packit fc043f
Packit fc043f
  return 0;
Packit fc043f
}