Annotation of embedaddon/sudo/common/fmt_string.c, revision 1.1.1.2

1.1       misho       1: /*
                      2:  * Copyright (c) 2010-2011 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: #include <sys/param.h>
                     21: 
                     22: #include <stdio.h>
                     23: #ifdef STDC_HEADERS
                     24: # include <stdlib.h>
                     25: # include <stddef.h>
                     26: #else
                     27: # ifdef HAVE_STDLIB_H
                     28: #  include <stdlib.h>
                     29: # endif
                     30: #endif /* STDC_HEADERS */
                     31: #ifdef HAVE_STRING_H
                     32: # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
                     33: #  include <memory.h>
                     34: # endif
                     35: # include <string.h>
                     36: #endif /* HAVE_STRING_H */
                     37: #ifdef HAVE_STRINGS_H
                     38: # include <strings.h>
                     39: #endif /* HAVE_STRINGS_H */
                     40: 
                     41: #include "missing.h"
1.1.1.2 ! misho      42: #include "sudo_debug.h"
1.1       misho      43: 
                     44: /*
                     45:  * Allocate storage for a name=value string and return it.
                     46:  */
                     47: char *
                     48: fmt_string(const char *var, const char *val)
                     49: {
                     50:     size_t var_len = strlen(var);
                     51:     size_t val_len = strlen(val);
                     52:     char *cp, *str;
1.1.1.2 ! misho      53:     debug_decl(fmt_string, SUDO_DEBUG_UTIL)
1.1       misho      54: 
                     55:     cp = str = malloc(var_len + 1 + val_len + 1);
                     56:        if (str != NULL) {
                     57:        memcpy(cp, var, var_len);
                     58:        cp += var_len;
                     59:        *cp++ = '=';
                     60:        memcpy(cp, val, val_len);
                     61:        cp += val_len;
                     62:        *cp = '\0';
                     63:     }
                     64: 
1.1.1.2 ! misho      65:     debug_return_str(str);
1.1       misho      66: }

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