return nbytes;
}
+/* Whether the string S starts with a decimal integer, optionally
+ negative. */
+static bool
+integer_prefixed (char const *s)
+{
+ /* Doing it this way avoids a conditional branch on most platforms. */
+ return c_isdigit (s[s[0] == '-']);
+}
+
+/* Whether the integer P could identify an individual process. On most
+ platforms this simply checks for positive pid_t, but on some
+ Microsoft ports our headers #define it to to some other test. */
+#ifndef VALID_PROCESS_ID
+# define VALID_PROCESS_ID(p) (0 < (p) && (p) <= TYPE_MAXIMUM (pid_t))
+#endif
+
/* True if errno values are negative. Although the C standard
requires them to be positive, they are negative in Haiku. */
enum { NEGATIVE_ERRNO = EDOM < 0 };
return EINVAL;
/* The PID is everything from the last '.' to the ':' or equivalent. */
- if (! c_isdigit (dot[1]))
+ if (! integer_prefixed (dot + 1))
return EINVAL;
errno = 0;
pid = strtoimax (dot + 1, &owner->colon, 10);
boot += 2;
FALLTHROUGH;
case ':':
- if (!(c_isdigit (boot[0])
- /* A negative number. */
- || (boot[0] == '-' && c_isdigit (boot[1]))))
+ if (! integer_prefixed (boot))
return EINVAL;
boot_time = strtoimax (boot, &lfinfo_end, 10);
break;
{
if (pid == getpid ())
return I_OWN_IT;
- else if (0 < pid && pid <= TYPE_MAXIMUM (pid_t)
+ else if (VALID_PROCESS_ID (pid)
&& (kill (pid, 0) >= 0 || errno == EPERM)
&& (boot_time == 0
|| (boot_time <= TYPE_MAXIMUM (time_t)