~vcs-imports/nano/master

« back to all changes in this revision

Viewing changes to src/utils.c

  • Committer: Benno Schulenberg
  • Date: 2020-10-21 10:24:52 UTC
  • Revision ID: git-v1:3c2eb96243e4411e41c6dc94c3054f79bc20af14
tweaks: rename two variables and improve two comments

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
}
109
109
#endif
110
110
 
111
 
/* Read an integer from str.  If it parses okay, store it in *result
112
 
 * and return TRUE; otherwise, return FALSE. */
113
 
bool parse_num(const char *str, ssize_t *result)
 
111
/* Read an integer from the given string.  If it parses okay,
 
112
 * store it in *result and return TRUE; otherwise, return FALSE. */
 
113
bool parse_num(const char *string, ssize_t *result)
114
114
{
115
 
        char *first_error;
116
115
        ssize_t value;
 
116
        char *excess;
117
117
 
118
 
        /* The manual page for strtol() says this is required. */
 
118
        /* Clear the error number so that we can check it afterward. */
119
119
        errno = 0;
120
120
 
121
 
        value = (ssize_t)strtol(str, &first_error, 10);
 
121
        value = (ssize_t)strtol(string, &excess, 10);
122
122
 
123
 
        if (errno == ERANGE || *str == '\0' || *first_error != '\0')
 
123
        if (errno == ERANGE || *string == '\0' || *excess != '\0')
124
124
                return FALSE;
125
125
 
126
126
        *result = value;