| error(3) | Library Functions Manual | error(3) |
НАИМЕНОВАНИЕ¶
error, error_at_line, error_message_count, error_one_per_line, error_print_progname - функции вывода ошибок glibc
БИБЛИОТЕКА¶
Стандартная библиотека языка C (libc, -lc)
ОБЗОР¶
#include <error.h>
void error(int status, int errnum, const char *format, ...);
void error_at_line(int status, int errnum, const char *file,
unsigned int line, const char *format, ...);
extern unsigned int error_message_count; extern int error_one_per_line;
extern typeof(void (void)) *error_print_progname;
ОПИСАНИЕ¶
Функция error() предназначена для сообщения об ошибках разного рода. Она сбрасывает stdout, а затем выводит в stderr имя программы, двоеточие, пробел, сообщение, задаваемое строкой format в формате printf(3) и, если значение errnum не равно нулю, второе двоеточие и пробел, за которыми выводится строка, возвращаемая вызовом strerror(errnum). Все аргументы, необходимые для format, должны указываться в списке аргументов после format. Вывод завершается символом новой строки.
Имя программы, выводимое error(), представляет собой значение глобальной переменной program_invocation_name(3). Первоначально, переменная program_invocation_name имеет то же значение что и argv[0] в функции main(). Значение этой переменной может быть изменено для показа в выводе error().
If status has a nonzero value, then error() calls exit(3) to terminate the program using the given value as the exit status; otherwise it returns after printing the error message.
The error_at_line() function is exactly the same as error(), except for the addition of the arguments file and line. The output produced is as for error(), except that after the program name are written: a colon, the value of file, a colon, and the value of line. The preprocessor values __LINE__ and __FILE__ may be useful when calling error_at_line(), but other values can also be used. For example, these arguments could refer to a location in an input file.
If the global variable error_one_per_line is set nonzero, a sequence of error_at_line() calls with the same value of file and line will result in only one message (the first) being output.
В глобальной переменной error_message_count подсчитывается количество сообщений, которые были показаны с помощью error() и error_at_line().
Если глобальной переменной error_print_progname назначен адрес функции (т.е., её значение не равно NULL), то вместо показа в начале сообщения имени программы и двоеточия вызывается эта функция. Функция должна вывести нужную строку в stderr.
АТРИБУТЫ¶
Описание терминов данного раздела смотрите в attributes(7).
| Интерфейс | Атрибут | Значение |
| error() | Безвредность в нитях | MT-Safe locale |
| error_at_line() | Безвредность в нитях | MT-Unsafe race: error_at_line/error_one_per_line locale |
The internal error_one_per_line variable is accessed (without any form of synchronization, but since it's an int used once, it should be safe enough) and, if error_one_per_line is set nonzero, the internal static variables (not exposed to users) used to hold the last printed filename and line number are accessed and modified without synchronization; the update is not atomic and it occurs before disabling cancelation, so it can be interrupted only after one of the two variables is modified. After that, error_at_line() is very much like error().
СТАНДАРТЫ¶
GNU.
СМОТРИТЕ ТАКЖЕ¶
err(3), errno(3), exit(3), perror(3), program_invocation_name(3), strerror(3)
ПЕРЕВОД¶
Русский перевод этой страницы руководства разработал(и) Azamat Hackimov <azamat.hackimov@gmail.com>, Yuri Kozlov <yuray@komyakino.ru>, Иван Павлов <pavia00@gmail.com> и Kirill Rekhov <krekhov.dev@gmail.com>
Этот перевод является свободной программной документацией; он распространяется на условиях общедоступной лицензии GNU (GNU General Public License - GPL, https://www.gnu.org/licenses/gpl-3.0.html версии 3 или более поздней) в отношении авторского права, но БЕЗ КАКИХ-ЛИБО ГАРАНТИЙ.
Если вы обнаружите какие-либо ошибки в переводе этой страницы руководства, пожалуйста, сообщите об этом разработчику(ам) по его(их) адресу(ам) электронной почты или по адресу списка рассылки русских переводчиков.
| 5 июня 2025 г. | Справочные страницы Linux (невыпущенные) |