Annotation of embedaddon/sudo/common/atobool.c, revision 1.1.1.4

1.1       misho       1: /*
1.1.1.4 ! misho       2:  * Copyright (c) 2010-2014 Todd C. Miller <Todd.Miller@courtesan.com>
1.1       misho       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: #ifdef HAVE_STRING_H
                     31: # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
                     32: #  include <memory.h>
                     33: # endif
                     34: # include <string.h>
                     35: #endif /* HAVE_STRING_H */
                     36: #ifdef HAVE_STRINGS_H
                     37: # include <strings.h>
                     38: #endif /* HAVE_STRINGS_H */
                     39: 
                     40: #include "missing.h"
1.1.1.2   misho      41: #include "sudo_debug.h"
1.1.1.4 ! misho      42: #include "sudo_util.h"
1.1       misho      43: 
                     44: int
                     45: atobool(const char *str)
                     46: {
1.1.1.2   misho      47:     debug_decl(atobool, SUDO_DEBUG_UTIL)
                     48: 
1.1       misho      49:     switch (*str) {
                     50:        case '0':
                     51:        case '1':
                     52:            if (str[1] == '\0')
1.1.1.4 ! misho      53:                debug_return_int(*str - '0');
1.1       misho      54:            break;
                     55:        case 'y':
                     56:        case 'Y':
                     57:            if (strcasecmp(str, "yes") == 0)
1.1.1.4 ! misho      58:                debug_return_int(1);
1.1       misho      59:            break;
                     60:        case 't':
                     61:        case 'T':
                     62:            if (strcasecmp(str, "true") == 0)
1.1.1.4 ! misho      63:                debug_return_int(1);
1.1       misho      64:            break;
                     65:        case 'o':
                     66:        case 'O':
                     67:            if (strcasecmp(str, "on") == 0)
1.1.1.4 ! misho      68:                debug_return_int(1);
1.1       misho      69:            if (strcasecmp(str, "off") == 0)
1.1.1.4 ! misho      70:                debug_return_int(0);
1.1       misho      71:            break;
                     72:        case 'n':
                     73:        case 'N':
                     74:            if (strcasecmp(str, "no") == 0)
1.1.1.4 ! misho      75:                debug_return_int(0);
1.1       misho      76:            break;
                     77:        case 'f':
                     78:        case 'F':
                     79:            if (strcasecmp(str, "false") == 0)
1.1.1.4 ! misho      80:                debug_return_int(0);
1.1       misho      81:            break;
                     82:     }
1.1.1.2   misho      83:     debug_return_int(-1);
1.1       misho      84: }

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