1/* t-syserror.c - System error specific regression test. 2 Copyright (C) 2006 g10 Code GmbH 3 4 This file is part of libgpg-error. 5 6 libgpg-error is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public License 8 as published by the Free Software Foundation; either version 2.1 of 9 the License, or (at your option) any later version. 10 11 libgpg-error is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with libgpgme-error; if not, write to the Free 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 02110-1301, USA. */ 20 21 22#if HAVE_CONFIG_H 23#include <config.h> 24#endif 25 26#include <stdio.h> 27#if HAVE_STDLIB_H 28#include <stdlib.h> 29#endif 30#include <errno.h> 31 32#include <gpg-error.h> 33 34int 35main (int argc, char *argv[]) 36{ 37 FILE *fp; 38 int save_errno; 39 gpg_err_code_t ec; 40 41 fp = fopen ("/does-not-exist/110761/nowhere.foo", "r"); 42 if (fp) 43 { 44 fclose (fp); 45 fp = fopen (" no this file does not exists foo 4711", "r"); 46 } 47 if (fp) 48 { 49 fprintf (stderr, "unable to run test\n"); 50 return 1; 51 } 52 save_errno = errno; 53 54 ec = gpg_err_code_from_syserror (); 55 if (ec != GPG_ERR_ENOENT) 56 { 57 fprintf (stderr, "fopen failed with bad code: %d\n", save_errno); 58 return 1; 59 } 60 61 if (ec != gpg_err_code_from_errno (save_errno)) 62 { 63 fprintf (stderr, "oops at %d\n",__LINE__); 64 return 1; 65 } 66 67 gpg_err_set_errno (0); 68 69 ec = gpg_err_code_from_syserror (); 70 if (ec != GPG_ERR_MISSING_ERRNO) 71 { 72 fprintf (stderr, "oops at %d\n",__LINE__); 73 return 1; 74 } 75 76 if ( gpg_err_code_from_errno (0) ) 77 { 78 fprintf (stderr, "oops at %d\n",__LINE__); 79 return 1; 80 } 81 82 83 return 0; 84} 85