/*
- * Copyright (C) 2004-2013 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2004 Andre Noll <maan@tuebingen.mpg.de>
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
* A wrapper for realloc(3). It calls \p exit(\p EXIT_FAILURE) on errors,
* i.e. there is no need to check the return value in the caller.
*
- * \return A pointer to the newly allocated memory, which is suitably aligned
- * for any kind of variable and may be different from \a p.
+ * \return A pointer to newly allocated memory which is suitably aligned for
+ * any kind of variable and may be different from \a p.
*
* \sa realloc(3).
*/
-__must_check __malloc void *para_realloc(void *p, size_t size)
+__must_check void *para_realloc(void *p, size_t size)
{
/*
* No need to check for NULL pointers: If p is NULL, the call
return ret;
}
-/**
- * Cut trailing newline.
- *
- * \param buf The string to be chopped.
- *
- * Replace the last character in \p buf by zero if it is equal to
- * the newline character.
- */
-void chop(char *buf)
-{
- int n = strlen(buf);
-
- if (!n)
- return;
- if (buf[n - 1] == '\n')
- buf[n - 1] = '\0';
-}
-
/**
* Get the logname of the current user.
*
char *next_cr;
next_cr = memchr(start, '\n', buf + size - start);
- next_null = memchr(start, '\0', buf + size - start);
+ next_null = memchr(start, '\0', next_cr?
+ next_cr - start : buf + size - start);
if (!next_cr && !next_null)
break;
- if (next_cr && next_null) {
- end = next_cr < next_null? next_cr : next_null;
- } else if (next_null) {
+ if (next_null)
end = next_null;
- } else
+ else
end = next_cr;
num_lines++;
if (!(flags & FELF_DISCARD_FIRST) || start != buf) {
tmp = strtoll(str, &endptr, 10);
if (errno == ERANGE && (tmp == LLONG_MAX || tmp == LLONG_MIN))
return -E_ATOI_OVERFLOW;
- if (errno != 0 && tmp == 0) /* other error */
- return -E_STRTOLL;
+ /*
+ * If there were no digits at all, strtoll() stores the original value
+ * of str in *endptr.
+ */
if (endptr == str)
return -E_ATOI_NO_DIGITS;
+ /*
+ * The implementation may also set errno and return 0 in case no
+ * conversion was performed.
+ */
+ if (errno != 0 && tmp == 0)
+ return -E_ATOI_NO_DIGITS;
if (*endptr != '\0') /* Further characters after number */
return -E_ATOI_JUNK_AT_END;
*value = tmp;