annotate lib/perror.c @ 10606:442a5ff4bcc1

Reduce code duplication.
author Paolo Bonzini <bonzini@gnu.org>
date Thu, 09 Oct 2008 13:31:16 +0200
parents a95a7e53bca3
children b5e42ef33b49
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10434
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Print a message describing error code.
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2008 Free Software Foundation, Inc.
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible and Simon Josefsson.
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 (at your option) any later version.
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 /* Specification. */
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <stdio.h>
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <errno.h>
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <string.h>
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 void
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 perror (const char *string)
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 {
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 const char *errno_description = strerror (errno);
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 if (string != NULL && *string != '\0')
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 fprintf (stderr, "%s: %s\n", string, errno_description);
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 else
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 fprintf (stderr, "%s\n", errno_description);
a95a7e53bca3 New module 'perror'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 }