Gets s c что это
Перейти к содержимому

Gets s c что это

  • автор:

gets, gets_s

If the failure has been caused by end of file condition, additionally sets the eof indicator (see feof() ) on stdin . If the failure has been caused by some other error, sets the error indicator (see ferror() ) on stdin .

[edit] Notes

The gets() function does not perform bounds checking, therefore this function is extremely vulnerable to buffer-overflow attacks. It cannot be used safely (unless the program runs in an environment which restricts what can appear on stdin ). For this reason, the function has been deprecated in the third corrigendum to the C99 standard and removed altogether in the C11 standard. fgets() and gets_s() are the recommended replacements.

man pages section 3: Basic Library Functions

The gets() function reads bytes from the standard input stream (see Intro(3)), stdin, into the array pointed to by s , until a newline character is read or an end-of-file condition is encountered. The newline character is discarded and the string is terminated with a null byte.

If the length of an input line exceeds the size of s , indeterminate behavior may result. For this reason, it is strongly recommended that gets() be avoided in favor of fgets().

The fgets() function reads bytes from the stream into the array pointed to by s , until n −1 bytes are read, or a newline character is read and transferred to s , or an end-of-file condition is encountered. The string is then terminated with a null byte.

The fgets() and gets() functions may mark the st_atime field of the file associated with stream for update. The st_atime field will be marked for update by the first successful execution of fgetc(3C), fgets(), fread(3C), fscanf(3C), getc(3C), getchar(3C), getdelim(3C), getline(3C), gets(), or scanf(3C) using stream that returns data not supplied by a prior call to ungetc(3C) or ungetwc(3C).

The gets_s() function is part of the bounds checking interfaces specified in the C11 standard, Annex K. It is similar to the gets() function, but with additional safety checks provided via explicit runtime-constraints as defined in the C11 standard. See runtime_constraint_handler(3C) and INCITS/ISO/IEC 9899:2011.

Return Values

Upon success, the gets() and fgets() functions return s. If end-of-file is encountered and no bytes have been read, no bytes are transferred to s and a null pointer is returned. For standard-conforming (see standards(7)) applications, if the end-of-file indicator for the stream is set, no bytes are transferred to s and a null pointer is returned whether or not the stream is at end-of-file. If a read error occurs, such as trying to use these functions on a file that has not been opened for reading, a null pointer is returned and the error indicator for the stream is set. If end-of-file is encountered, the EOF indicator for the stream is set. Otherwise s is returned.

Upon success, the gets_s() function returns s. If there is a runtime-constraint violation, or if end-of-file is encountered and no bytes have been read into the array, or if a read error occurs during the operation, a null pointer is returned.

Errors

The function gets_s() will fail if:

Null pointer is passed.

Size argument is not a valid value.

Usage

The fgets() function allows properly-written programs to safely process input lines too long to store in the result array. In general, it requires that callers of fgets() pay attention to the presence or absence of a new-line character in the result array. Consider using the fgets() function (along with any needed processing based on new-line characters) instead of the gets_s() function.

gets, gets_s

str в случае успеха, нулевой указатель в случае неудачи.

Если сбой был вызван состоянием конца файла,дополнительно установите параметр eof индикатор (см. feof() ) на stdin . Если сбой был вызван какой-либо другой ошибкой, устанавливает error индикатор (см. ferror() ) на stdin .

Notes

Функция gets() не выполняет проверку границ, поэтому эта функция чрезвычайно уязвима для атак переполнения буфера. Его нельзя безопасно использовать (если только программа не работает в среде, которая ограничивает то, что может появиться в stdin ) По этой причине эта функция устарела в третьем исправлении к стандарту C99 и вообще удалена в стандарте C11. fgets() и gets_s() — рекомендуемые замены.

gets, gets_s

If the failure has been caused by end of file condition, additionally sets the eof indicator (see feof() ) on stdin . If the failure has been caused by some other error, sets the error indicator (see ferror() ) on stdin .

[edit] Notes

The gets() function does not perform bounds checking, therefore this function is extremely vulnerable to buffer-overflow attacks. It cannot be used safely (unless the program runs in an environment which restricts what can appear on stdin ). For this reason, the function has been deprecated in the third corrigendum to the C99 standard and removed altogether in the C11 standard. fgets() and gets_s() are the recommended replacements.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *