Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / stdio / perror.c
blob2033a6f2f6d8c3562b9294d113fbcb89e91985f6
1 /*
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
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 * and/or 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.
19 FUNCTION
20 <<perror>>---print an error message on standard error
22 INDEX
23 perror
24 INDEX
25 _perror_r
27 SYNOPSIS
28 #include <stdio.h>
29 void perror(char *<[prefix]>);
31 void _perror_r(struct _reent *<[reent]>, char *<[prefix]>);
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>>.
41 The alternate function <<_perror_r>> is a reentrant version. The
42 extra argument <[reent]> is a pointer to a reentrancy structure.
44 RETURNS
45 <<perror>> returns no result.
47 PORTABILITY
48 ANSI C requires <<perror>>, but the strings issued vary from one
49 implementation to another.
51 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
52 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
55 #include <_ansi.h>
56 #include <reent.h>
57 #include <stdio.h>
58 #include <string.h>
59 #include "local.h"
61 #define WRITE_STR(str) \
62 { \
63 const char *p = (str); \
64 size_t len = strlen (p); \
65 while (len) \
66 { \
67 ssize_t len1 = _write_r (ptr, fileno (fp), p, len); \
68 if (len1 < 0) \
69 break; \
70 len -= len1; \
71 p += len1; \
72 } \
75 void
76 _perror_r (struct _reent *ptr,
77 const char *s)
79 char *error;
80 int dummy;
81 FILE *fp = _stderr_r (ptr);
83 CHECK_INIT (ptr, fp);
85 _newlib_flockfile_start(fp);
86 _fflush_r (ptr, fp);
87 if (s != NULL && *s != '\0')
89 WRITE_STR (s);
90 WRITE_STR (": ");
93 if ((error = _strerror_r (ptr, _REENT_ERRNO(ptr), 1, &dummy)) != NULL)
94 WRITE_STR (error);
96 #ifdef __SCLE
97 WRITE_STR ((fp->_flags & __SCLE) ? "\r\n" : "\n");
98 #else
99 WRITE_STR ("\n");
100 #endif
101 fp->_flags &= ~__SOFF;
102 _newlib_flockfile_end(fp);
105 #ifndef _REENT_ONLY
107 void
108 perror (const char *s)
110 _perror_r (_REENT, s);
113 #endif