MCPcopy Create free account
hub / github.com/F-Stack/f-stack / login_getcapnum

Function login_getcapnum

tools/libutil/login_cap.c:625–665  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

623 */
624
625rlim_t
626login_getcapnum(login_cap_t *lc, const char *cap, rlim_t def, rlim_t error)
627{
628 char *ep, *res;
629 int r;
630 rlim_t val;
631
632 if (lc == NULL || lc->lc_cap == NULL)
633 return def;
634
635 /*
636 * For BSDI compatibility, try for the tag=<val> first
637 */
638 if ((r = cgetstr(lc->lc_cap, cap, &res)) == -1) {
639 long lval;
640 /* string capability not present, so try for tag#<val> as numeric */
641 if ((r = cgetnum(lc->lc_cap, cap, &lval)) == -1)
642 return def; /* Not there, so return default */
643 else if (r >= 0)
644 return (rlim_t)lval;
645 }
646
647 if (r < 0) {
648 errno = ERANGE;
649 return error;
650 }
651
652 if (isinfinite(res))
653 return RLIM_INFINITY;
654
655 errno = 0;
656 val = strtoq(res, &ep, 0);
657 if (ep == NULL || ep == res || errno != 0) {
658 syslog(LOG_WARNING, "login_getcapnum: class '%s' bad value %s=%s",
659 lc->lc_class, cap, res);
660 errno = ERANGE;
661 return error;
662 }
663
664 return val;
665}
666
667
668

Callers 2

setlogincontextFunction · 0.85
setusercontextFunction · 0.85

Calls 2

isinfiniteFunction · 0.85
strtoqFunction · 0.85

Tested by

no test coverage detected