sscanf и возвращаемые ошибки

Модератор: Модераторы разделов

Аватара пользователя
TuxWare
Сообщения: 637
ОС: Windows 7

sscanf и возвращаемые ошибки

Сообщение TuxWare »

Есть очень простая функция sscanf. Но на нее нет чистого руководства. man замешан c scanf, fscanf и т.д.
Тем не менее man гласит, что эта функция (эти функции) могут возвращать в errno следующие ошибки: EAGAIN, EINTR, ENOMEM. Если sscanf реально может устанавливать EAGAIN, EINTR - значит функция может проскакивать или прерываться и ее надо повторить. Тогда код, например для C++, должен иметь вид

int i;
do {
i = sscanf(.....);
}
while (i == EOF && (errno == EAGAIN || errno == EINTR));
if (i == EOF && errno == ENOMEM)
throw std::bad_alloc();
else if (стандартные проверки) {
стандартные действия
}

А реально sscanf может установить такие ошибки?
Почему то strcmp не устанавливает errno в EAGAIN, EINTR.
Спасибо сказали:
Аватара пользователя
AestheteAnimus
Сообщения: 135
ОС: FreeBSD 8.0-RELEASE amd64

Re: sscanf и возвращаемые ошибки

Сообщение AestheteAnimus »

Тем не менее man гласит...

Где Вы такое нашли?

16 The fscanf function returns the value of the macro EOF if an input failure occurs
before any conversion. Otherwise, the function returns the number of input items
assigned, which can be fewer than provided for, or even zero, in the event of an early
matching failure.
Спасибо сказали:
Аватара пользователя
TuxWare
Сообщения: 637
ОС: Windows 7

Re: sscanf и возвращаемые ошибки

Сообщение TuxWare »

man sscanf

RETURN VALUE
These functions return the number of input items successfully matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure.

The value EOF is returned if the end of input is reached before either the first successful conversion or a matching failure occurs. EOF is also returned if a read error occurs, in which case the error indicator for the stream (see ferror(3)) is set, and errno is set indicate the error.

ERRORS
EAGAIN The file descriptor underlying stream is marked nonblocking, and the read operation would block.

EBADF The file descriptor underlying stream is invalid, or not open for reading.

EILSEQ Input byte sequence does not form a valid character.

EINTR The read operation was interrupted by a signal; see signal(7).

EINVAL Not enough arguments; or format is NULL.

ENOMEM Out of memory.

ERANGE The result of an integer conversion would exceed the size that can be stored in the corresponding integer type.
Спасибо сказали:
watashiwa_daredeska
Бывший модератор
Сообщения: 4038
Статус: Искусственный интеллект (pre-alpha)
ОС: Debian GNU/Linux

Re: sscanf и возвращаемые ошибки

Сообщение watashiwa_daredeska »

(man sscanf) писал(а):ERRORS
EAGAIN The file descriptor underlying stream is marked nonblocking, and the read operation would block.
EBADF The file descriptor underlying stream is invalid, or not open for reading.
EINTR The read operation was interrupted by a signal; see signal(7).
Учитывая, что никаких file descriptor и read operation в sscanf нет, эти ошибки никогда не произойдут.
Спасибо сказали:
Аватара пользователя
TuxWare
Сообщения: 637
ОС: Windows 7

Re: sscanf и возвращаемые ошибки

Сообщение TuxWare »

watashiwa_daredeska писал(а):
11.04.2010 17:11
(man sscanf) писал(а):ERRORS
EAGAIN The file descriptor underlying stream is marked nonblocking, and the read operation would block.
EBADF The file descriptor underlying stream is invalid, or not open for reading.
EINTR The read operation was interrupted by a signal; see signal(7).
Учитывая, что никаких file descriptor и read operation в sscanf нет, эти ошибки никогда не произойдут.


EINTR вызывается сигналом и дескриптор файла не имеет никакого значения, а чтение из буфера есть. ENOMEM вообще не понятно чем.
Спасибо сказали:
watashiwa_daredeska
Бывший модератор
Сообщения: 4038
Статус: Искусственный интеллект (pre-alpha)
ОС: Debian GNU/Linux

Re: sscanf и возвращаемые ошибки

Сообщение watashiwa_daredeska »

TuxWare писал(а):
11.04.2010 17:23
EINTR вызывается сигналом и дескриптор файла не имеет никакого значения
Ещё раз:
EINTR The read operation was interrupted by a signal; see signal(7).
В sscanf нет никаких read operation, следовательно, interrupt'ить нечего.
Спасибо сказали:
Аватара пользователя
TuxWare
Сообщения: 637
ОС: Windows 7

Re: sscanf и возвращаемые ошибки

Сообщение TuxWare »

watashiwa_daredeska писал(а):
11.04.2010 18:54
В sscanf нет никаких read operation, следовательно, interrupt'ить нечего.

Уговорили, в целом логично.
Спасибо сказали: