Gnu Error
Contents |
of a library call. The functions strerror and perror give you the standard error message for a given error code; the variable program_invocation_short_name gives you convenient access to the name of the program that encountered the error.
C Error Function
Function: char * strerror (int errnum) Preliminary: | MT-Unsafe race:strerror | AS-Unsafe heap i18n | c error codes AC-Unsafe mem | See POSIX Safety Concepts. The strerror function maps the error code (see Checking for Errors) specified by the errnum
Error.h C
argument to a descriptive error message string. The return value is a pointer to this string. The value errnum normally comes from the variable errno. You should not modify the string returned by strerror. Also, if you c programming error codes make subsequent calls to strerror, the string might be overwritten. (But it’s guaranteed that no library function ever calls strerror behind your back.) The function strerror is declared in string.h. Function: char * strerror_r (int errnum, char *buf, size_t n) Preliminary: | MT-Safe | AS-Unsafe i18n | AC-Unsafe | See POSIX Safety Concepts. The strerror_r function works like strerror but instead of returning the error message in a statically allocated buffer shared by all c error handling best practices threads in the process, it returns a private copy for the thread. This might be either some permanent global data or a message string in the user supplied buffer starting at buf with the length of n bytes. At most n characters are written (including the NUL byte) so it is up to the user to select a buffer large enough. This function should always be used in multi-threaded programs since there is no way to guarantee the string returned by strerror really belongs to the last call of the current thread. The function strerror_r is a GNU extension and it is declared in string.h. Function: void perror (const char *message) Preliminary: | MT-Safe race:stderr | AS-Unsafe corrupt i18n heap lock | AC-Unsafe corrupt lock mem fd | See POSIX Safety Concepts. This function prints an error message to the stream stderr; see Standard Streams. The orientation of stderr is not changed. If you call perror with a message that is either a null pointer or an empty string, perror just prints the error message corresponding to errno, adding a trailing newline. If you supply a non-null message argument, then perror prefixes its output with this string. It adds a colon and a space character to separate the message from the error string corresponding to errno. The function perror is declare
EOF that is defined for that purpose. But this return value tells you only that an error has occurred. To find out what kind of error it was, you need to look at
Error C-82e10193
the error code stored in the variable errno. This variable is declared in the c stderr header file errno.h. Variable: volatile int errno The variable errno contains the system error number. You can change the value of errno.
Strerror Example
Since errno is declared volatile, it might be changed asynchronously by a signal handler; see Defining Handlers. However, a properly written signal handler saves and restores the value of errno, so you generally do not http://www.gnu.org/s/libc/manual/html_node/Error-Messages.html need to worry about this possibility except when writing signal handlers. The initial value of errno at program startup is zero. Many library functions are guaranteed to set it to certain nonzero values when they encounter certain kinds of errors. These error conditions are listed for each function. These functions do not change errno when they succeed; thus, the value of errno after a successful call is not necessarily zero, and http://www.gnu.org/s/libc/manual/html_node/Checking-for-Errors.html you should not use errno to determine whether a call failed. The proper way to do that is documented for each function. If the call failed, you can examine errno. Many library functions can set errno to a nonzero value as a result of calling other library functions which might fail. You should assume that any library function might alter errno when the function returns an error. Portability Note: ISOC specifies errno as a “modifiable lvalue” rather than as a variable, permitting it to be implemented as a macro. For example, its expansion might involve a function call, like *__errno_location(). In fact, that is what it is on GNU/Linux and GNU/Hurd systems. The GNU C Library, on each system, does whatever is right for the particular system. There are a few library functions, like sqrt and atan, that return a perfectly legitimate value in case of an error, but also set errno. For these functions, if you want to check to see whether an error occurred, the recommended method is to set errno to zero before calling the function, and then check its value afterward. All the error codes have symbolic names; they are macros defined in errno.h. The names start with ‘E’ and an upper-case letter or digit; you
the operation. Since EOF is used to report both end of file and random errors, it’s often better to use the feof function to check explicitly for end of file and ferror to check for errors. These functions check indicators that https://www.gnu.org/s/libc/manual/html_node/EOF-and-Errors.html are part of the internal state of the stream object, indicators set if the appropriate condition was detected by a previous I/O operation on that stream. Macro: int EOF This macro is an integer value that is returned http://stackoverflow.com/questions/1864385/how-to-force-an-error-in-a-gnumake-file by a number of narrow stream functions to indicate an end-of-file condition, or some other error situation. With the GNU C Library, EOF is -1. In other libraries, its value may be some other negative number. This symbol c error is declared in stdio.h. Macro: int WEOF This macro is an integer value that is returned by a number of wide stream functions to indicate an end-of-file condition, or some other error situation. With the GNU C Library, WEOF is -1. In other libraries, its value may be some other negative number. This symbol is declared in wchar.h. Function: int feof (FILE *stream) Preliminary: | MT-Safe | AS-Safe | AC-Unsafe lock | See POSIX Safety Concepts. c error function The feof function returns nonzero if and only if the end-of-file indicator for the stream stream is set. This symbol is declared in stdio.h. Function: int feof_unlocked (FILE *stream) Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts. The feof_unlocked function is equivalent to the feof function except that it does not implicitly lock the stream. This function is a GNU extension. This symbol is declared in stdio.h. Function: int ferror (FILE *stream) Preliminary: | MT-Safe | AS-Safe | AC-Unsafe lock | See POSIX Safety Concepts. The ferror function returns nonzero if and only if the error indicator for the stream stream is set, indicating that an error has occurred on a previous operation on the stream. This symbol is declared in stdio.h. Function: int ferror_unlocked (FILE *stream) Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts. The ferror_unlocked function is equivalent to the ferror function except that it does not implicitly lock the stream. This function is a GNU extension. This symbol is declared in stdio.h. In addition to setting the error indicator associated with the stream, the functions that operate on streams also set errno in the same way as the corresponding low-level functions that operate on file descriptors. For example, all of the functions that perform output to a stream—such as fputc, printf, and fflush—are implemented i
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to force an error in a gnumake file up vote 34 down vote favorite 6 I want to detect a condition in my makefile where a tool is the wrong version and force the make to fail with an error message indicating the item is not the right version. Can anyone give an example of doing this? I tried the following but it is not the right syntax: ifeq "$(shell svnversion --version | sed s/[^0-9\.]*://)" "1.4" $error("Bad svnversion v1.4, please install v1.6") endif Thanks. makefile gnu-make share|improve this question asked Dec 8 '09 at 3:31 WilliamKF 10.9k33108208 You might want to check this against 1.4. I have 1.4.4 installed and the --version output contains a lot more than the version number. Try something like ifeq "$(shell svn --version | sed -nE -e '/version/s/^.*([0-9]+\.[0-9]\+)\..*$$/\1/p')" "1.4" instead –D.Shawley Dec 8 '09 at 4:05 My sed does not accept the -E: "sed: invalid option -- E" –WilliamKF Dec 8 '09 at 4:09 1 Does it have to be make? I tend to write these tests in configure. –Dirk Eddelbuettel Dec 8 '09 at 4:15 Ah.. then change the match portion of the expression to ^.*\([0-9][0-9]*\.[0-9][0-9]*\)\..*$$. The -E would enable extended regular expressions which allow for more compact expressions amongst other goodies. –D.Shawley Dec 8 '09 at 12:04 I'd recommend quoting the regular expression for the shell too. Just to be safe. I.e., ifeq ($(shell svnversion --version | sed '