1 | /* |
---|
2 | * Copyright (c) 1990 The Regents of the University of California. |
---|
3 | * All rights reserved. |
---|
4 | * |
---|
5 | * Redistribution and use in source and binary forms are permitted |
---|
6 | * provided that the above copyright notice and this paragraph are |
---|
7 | * duplicated in all such forms and that any documentation, |
---|
8 | * advertising materials, and other materials related to such |
---|
9 | * distribution and use acknowledge that the software was developed |
---|
10 | * by the University of California, Berkeley. The name of the |
---|
11 | * University may not be used to endorse or promote products derived |
---|
12 | * from this software without specific prior written permission. |
---|
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
---|
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
---|
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | FUNCTION |
---|
20 | <<perror>>---print an error message on standard error |
---|
21 | |
---|
22 | INDEX |
---|
23 | perror |
---|
24 | INDEX |
---|
25 | _perror_r |
---|
26 | |
---|
27 | SYNOPSIS |
---|
28 | #include <stdio.h> |
---|
29 | void perror(char *<[prefix]>); |
---|
30 | |
---|
31 | void _perror_r(struct _reent *<[reent]>, char *<[prefix]>); |
---|
32 | |
---|
33 | DESCRIPTION |
---|
34 | Use <<perror>> to print (on standard error) an error message |
---|
35 | corresponding to the current value of the global variable <<errno>>. |
---|
36 | Unless you use <<NULL>> as the value of the argument <[prefix]>, the |
---|
37 | error message will begin with the string at <[prefix]>, followed by a |
---|
38 | colon and a space (<<: >>). The remainder of the error message is one |
---|
39 | of the strings described for <<strerror>>. |
---|
40 | |
---|
41 | The alternate function <<_perror_r>> is a reentrant version. The |
---|
42 | extra argument <[reent]> is a pointer to a reentrancy structure. |
---|
43 | |
---|
44 | RETURNS |
---|
45 | <<perror>> returns no result. |
---|
46 | |
---|
47 | PORTABILITY |
---|
48 | ANSI C requires <<perror>>, but the strings issued vary from one |
---|
49 | implementation to another. |
---|
50 | |
---|
51 | Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, |
---|
52 | <<lseek>>, <<read>>, <<sbrk>>, <<write>>. |
---|
53 | */ |
---|
54 | |
---|
55 | #include <_ansi.h> |
---|
56 | #include <reent.h> |
---|
57 | #include <stdio.h> |
---|
58 | #include <string.h> |
---|
59 | #include "local.h" |
---|
60 | |
---|
61 | void |
---|
62 | _perror_r (struct _reent *ptr, |
---|
63 | const char *s) |
---|
64 | { |
---|
65 | char *error; |
---|
66 | int dummy; |
---|
67 | |
---|
68 | _REENT_SMALL_CHECK_INIT (ptr); |
---|
69 | if (s != NULL && *s != '\0') |
---|
70 | { |
---|
71 | fputs (s, _stderr_r (ptr)); |
---|
72 | fputs (": ", _stderr_r (ptr)); |
---|
73 | } |
---|
74 | |
---|
75 | if ((error = _strerror_r (ptr, ptr->_errno, 1, &dummy)) != NULL) |
---|
76 | fputs (error, _stderr_r (ptr)); |
---|
77 | |
---|
78 | fputc ('\n', _stderr_r (ptr)); |
---|
79 | } |
---|
80 | |
---|
81 | #ifndef _REENT_ONLY |
---|
82 | |
---|
83 | void |
---|
84 | perror (const char *s) |
---|
85 | { |
---|
86 | _perror_r (_REENT, s); |
---|
87 | } |
---|
88 | |
---|
89 | #endif |
---|