wininet: Move freeing netconn into create_netconn_socket (Coverity).
[wine.git] / dlls / jscript / jsstr.c
blob3586dad058470a8ae190f2ba9ac79fd8d7903c8d
1 /*
2 * Copyright 2012 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "jscript.h"
21 #include "wine/debug.h"
23 const char *debugstr_jsstr(jsstr_t *str)
25 return debugstr_wn(str->str, jsstr_length(str));
28 jsstr_t *jsstr_alloc_buf(unsigned len)
30 jsstr_t *ret;
32 if(len > JSSTR_MAX_LENGTH)
33 return NULL;
35 ret = heap_alloc(FIELD_OFFSET(jsstr_t, str[len+1]));
36 if(!ret)
37 return NULL;
39 ret->length_flags = len << JSSTR_LENGTH_SHIFT;
40 ret->ref = 1;
41 ret->str[len] = 0;
42 return ret;
45 jsstr_t *jsstr_alloc_len(const WCHAR *buf, unsigned len)
47 jsstr_t *ret;
49 ret = jsstr_alloc_buf(len);
50 if(ret)
51 memcpy(ret->str, buf, len*sizeof(WCHAR));
53 return ret;
56 int jsstr_cmp(jsstr_t *str1, jsstr_t *str2)
58 int len1 = jsstr_length(str1);
59 int len2 = jsstr_length(str2);
60 int ret;
62 ret = memcmp(str1->str, str2->str, min(len1, len2)*sizeof(WCHAR));
63 if(!ret)
64 ret = len1 - len2;
66 return ret;
69 static jsstr_t *empty_str, *nan_str;
71 jsstr_t *jsstr_nan(void)
73 return jsstr_addref(nan_str);
76 jsstr_t *jsstr_empty(void)
78 return jsstr_addref(empty_str);
81 BOOL init_strings(void)
83 static const WCHAR NaNW[] = { 'N','a','N',0 };
85 if(!(empty_str = jsstr_alloc_buf(0)))
86 return FALSE;
87 if(!(nan_str = jsstr_alloc(NaNW)))
88 return FALSE;
89 return TRUE;
92 void free_strings(void)
94 jsstr_release(empty_str);
95 jsstr_release(nan_str);