mirror of https://github.com/mkerrisk/man-pages
system_data_types.7: Minor tweaks to Alejandro Colomar's patch
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
parent
f5d2c2efb2
commit
89c6c2bdd2
|
@ -660,8 +660,8 @@ The program shown below scans from a string and prints a value stored in
|
|||
a variable of an integer type that doesn't have a length modifier.
|
||||
The appropriate conversions from and to
|
||||
.IR intmax_t ,
|
||||
and the appropriate range checkings,
|
||||
are used as explained in the notes section above:
|
||||
and the appropriate range checks,
|
||||
are used as explained in the notes section above.
|
||||
.PP
|
||||
.EX
|
||||
#include <stdint.h>
|
||||
|
@ -669,7 +669,6 @@ are used as explained in the notes section above:
|
|||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
|
@ -678,26 +677,32 @@ main (void)
|
|||
intmax_t tmp;
|
||||
|
||||
/* Scan the number from the string into the temporary variable */
|
||||
|
||||
sscanf(str, "%jd", &tmp);
|
||||
|
||||
/* Check that the value is within the valid range of suseconds_t */
|
||||
if (tmp < -1 || tmp > 1000000) {
|
||||
fprintf(stderr, "Scaned value might overflow!\en");
|
||||
|
||||
if (tmp < \-1 || tmp > 1000000) {
|
||||
fprintf(stderr, "Scanned value outside valid range!\en");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Copy the value to the suseconds_t variable 'us' */
|
||||
/* Copy the value to the suseconds_t variable \(aqus\(aq */
|
||||
|
||||
us = tmp;
|
||||
|
||||
/* Even though suseconds_t can hold the value -1,
|
||||
it represents an error code */
|
||||
/* Even though suseconds_t can hold the value \-1, this isn\(aqt
|
||||
a sensible number of microseconds */
|
||||
|
||||
if (us < 0) {
|
||||
fprintf(stderr, "Scanned an error code!\en");
|
||||
fprintf(stderr, "Scanned value shouldn\(aqt be negative!\en");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Print the value */
|
||||
printf("There are %jd us in half a second.\en", (intmax_t) us);
|
||||
|
||||
printf("There are %jd microseconds in half a second.\en",
|
||||
(intmax_t) us);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue