Path: blob/main/crypto/krb5/src/ccapi/lib/ccapi_string.c
39536 views
/* ccapi/lib/ccapi_string.c */1/*2* Copyright 2006 Massachusetts Institute of Technology.3* All Rights Reserved.4*5* Export of this software from the United States of America may6* require a specific license from the United States Government.7* It is the responsibility of any person or organization contemplating8* export to obtain such a license before exporting.9*10* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and11* distribute this software and its documentation for any purpose and12* without fee is hereby granted, provided that the above copyright13* notice appear in all copies and that both that copyright notice and14* this permission notice appear in supporting documentation, and that15* the name of M.I.T. not be used in advertising or publicity pertaining16* to distribution of the software without specific, written prior17* permission. Furthermore if you modify this software you must label18* your software as modified software and not distribute it in such a19* fashion that it might be confused with the original M.I.T. software.20* M.I.T. makes no representations about the suitability of21* this software for any purpose. It is provided "as is" without express22* or implied warranty.23*/2425#include "ccapi_string.h"2627/* ------------------------------------------------------------------------ */2829cc_string_d cci_string_d_initializer = {30NULL,31NULL32VECTOR_FUNCTIONS_INITIALIZER };3334cc_string_f cci_string_f_initializer = {35ccapi_string_release36};3738/* ------------------------------------------------------------------------ */3940cc_int32 cci_string_new (cc_string_t *out_string,41char *in_cstring)42{43cc_int32 err = ccNoError;44cc_string_t string = NULL;4546if (!out_string) { err = cci_check_error (ccErrBadParam); }47if (!in_cstring) { err = cci_check_error (ccErrBadParam); }4849if (!err) {50string = malloc (sizeof (*string));51if (string) {52*string = cci_string_d_initializer;53} else {54err = cci_check_error (ccErrNoMem);55}56}5758if (!err) {59string->functions = malloc (sizeof (*string->functions));60if (string->functions) {61*((cc_string_f *) string->functions) = cci_string_f_initializer;62} else {63err = cci_check_error (ccErrNoMem);64}65}6667if (!err) {68string->data = strdup (in_cstring);69if (!string->data) {70err = cci_check_error (ccErrNoMem);71}7273}7475if (!err) {76*out_string = string;77string = NULL; /* take ownership */78}7980if (string) { ccapi_string_release (string); }8182return cci_check_error (err);83}8485/* ------------------------------------------------------------------------ */8687cc_int32 ccapi_string_release (cc_string_t in_string)88{89cc_int32 err = ccNoError;9091if (!in_string) { err = ccErrBadParam; }9293if (!err) {94free ((char *) in_string->data);95free ((char *) in_string->functions);96free (in_string);97}9899return err;100}101102103