Debian Codegraph @

tests/t-syserror.c

raw
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
34 int
35 main (int argc, char *argv[])
36 {
37 FILE *fp;
38 int save_errno;
39 gpg_err_code_t ec;
40
41 (void)argc;
42 (void)argv;
43
44 fp = fopen ("/does-not-exist/110761/nowhere.foo", "r");
45 if (fp)
46 {
47 fclose (fp);
48 fp = fopen (" no this file does not exists foo 4711", "r");
49 }
50 if (fp)
51 {
52 fclose (fp);
53 fprintf (stderr, "unable to run test\n");
54 return 1;
55 }
56 save_errno = errno;
57
58 ec = gpg_err_code_from_syserror ();
59 if (ec != GPG_ERR_ENOENT)
60 {
61 fprintf (stderr, "fopen failed with bad code: %d\n", save_errno);
62 return 1;
63 }
64
65 if (ec != gpg_err_code_from_errno (save_errno))
66 {
67 fprintf (stderr, "oops at %d\n",__LINE__);
68 return 1;
69 }
70
71 gpg_err_set_errno (0);
72
73 ec = gpg_err_code_from_syserror ();
74 if (ec != GPG_ERR_MISSING_ERRNO)
75 {
76 fprintf (stderr, "oops at %d\n",__LINE__);
77 return 1;
78 }
79
80 if ( gpg_err_code_from_errno (0) )
81 {
82 fprintf (stderr, "oops at %d\n",__LINE__);
83 return 1;
84 }
85
86
87 return 0;
88 }