Annotation of embedaddon/sudo/common/atomode.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (c) 2013-2014 Todd C. Miller <Todd.Miller@courtesan.com>
        !             3:  *
        !             4:  * Permission to use, copy, modify, and distribute this software for any
        !             5:  * purpose with or without fee is hereby granted, provided that the above
        !             6:  * copyright notice and this permission notice appear in all copies.
        !             7:  *
        !             8:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
        !             9:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
        !            10:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
        !            11:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
        !            12:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
        !            13:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
        !            14:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
        !            15:  */
        !            16: 
        !            17: #include <config.h>
        !            18: 
        !            19: #include <sys/types.h>
        !            20: 
        !            21: #include <stdio.h>
        !            22: #ifdef STDC_HEADERS
        !            23: # include <stdlib.h>
        !            24: # include <stddef.h>
        !            25: #else
        !            26: # ifdef HAVE_STDLIB_H
        !            27: #  include <stdlib.h>
        !            28: # endif
        !            29: #endif /* STDC_HEADERS */
        !            30: #include <errno.h>
        !            31: 
        !            32: #define DEFAULT_TEXT_DOMAIN    "sudo"
        !            33: #include "gettext.h"           /* must be included before missing.h */
        !            34: 
        !            35: #include "missing.h"
        !            36: #include "sudo_debug.h"
        !            37: #include "sudo_util.h"
        !            38: 
        !            39: /*
        !            40:  * Parse an octal file mode in the range [0, 0777].
        !            41:  * On success, returns the parsed mode and clears errstr.
        !            42:  * On error, returns 0 and sets errstr.
        !            43:  */
        !            44: int
        !            45: atomode(const char *cp, const char **errstr)
        !            46: {
        !            47:     char *ep;
        !            48:     long lval;
        !            49:     debug_decl(atomode, SUDO_DEBUG_UTIL)
        !            50: 
        !            51:     errno = 0;
        !            52:     lval = strtol(cp, &ep, 8);
        !            53:     if (ep == cp || *ep != '\0') {
        !            54:        if (errstr != NULL)
        !            55:            *errstr = N_("invalid value");
        !            56:        errno = EINVAL;
        !            57:        debug_return_int(0);
        !            58:     }
        !            59:     if (lval < 0 || lval > 0777) {
        !            60:        if (errstr != NULL)
        !            61:            *errstr = lval < 0 ? N_("value too small") : N_("value too large");
        !            62:        errno = ERANGE;
        !            63:        debug_return_int(0);
        !            64:     }
        !            65:     if (errstr != NULL)
        !            66:        *errstr = NULL;
        !            67:     debug_return_int((int)lval);
        !            68: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>