2 * OpenAL cross platform audio library
3 * Copyright (C) 2011 by authors.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 * Or go to http://www.gnu.org/copyleft/lgpl.html
23 #define _WIN32_IE 0x501
25 #define _WIN32_IE 0x400
39 #ifndef AL_NO_UID_DEFS
40 #if defined(HAVE_GUIDDEF_H) || defined(HAVE_INITGUID_H)
49 DEFINE_GUID(KSDATAFORMAT_SUBTYPE_PCM
, 0x00000001, 0x0000, 0x0010, 0x80,0x00, 0x00,0xaa,0x00,0x38,0x9b,0x71);
50 DEFINE_GUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
, 0x00000003, 0x0000, 0x0010, 0x80,0x00, 0x00,0xaa,0x00,0x38,0x9b,0x71);
52 DEFINE_GUID(IID_IDirectSoundNotify
, 0xb0210783, 0x89cd, 0x11d0, 0xaf,0x08, 0x00,0xa0,0xc9,0x25,0xcd,0x16);
54 DEFINE_GUID(CLSID_MMDeviceEnumerator
, 0xbcde0395, 0xe52f, 0x467c, 0x8e,0x3d, 0xc4,0x57,0x92,0x91,0x69,0x2e);
55 DEFINE_GUID(IID_IMMDeviceEnumerator
, 0xa95664d2, 0x9614, 0x4f35, 0xa7,0x46, 0xde,0x8d,0xb6,0x36,0x17,0xe6);
56 DEFINE_GUID(IID_IAudioClient
, 0x1cb9ad4c, 0xdbfa, 0x4c32, 0xb1,0x78, 0xc2,0xf5,0x68,0xa7,0x03,0xb2);
57 DEFINE_GUID(IID_IAudioRenderClient
, 0xf294acfc, 0x3146, 0x4483, 0xa7,0xbf, 0xad,0xdc,0xa7,0xc2,0x60,0xe2);
60 #include <devpropdef.h>
61 DEFINE_DEVPROPKEY(DEVPKEY_Device_FriendlyName
, 0xa45c254e, 0xdf1c, 0x4efd, 0x80,0x20, 0x67,0xd1,0x46,0xa8,0x50,0xe0, 14);
64 #endif /* AL_NO_UID_DEFS */
75 #ifdef HAVE_SYS_SYSCONF_H
76 #include <sys/sysconf.h>
99 extern inline ALuint
NextPowerOf2(ALuint value
);
100 extern inline ALint
fastf2i(ALfloat f
);
101 extern inline ALuint
fastf2u(ALfloat f
);
104 ALuint CPUCapFlags
= 0;
107 void FillCPUCaps(ALuint capfilter
)
111 /* FIXME: We really should get this for all available CPUs in case different
112 * CPUs have different caps (is that possible on one machine?). */
113 #if defined(HAVE_GCC_GET_CPUID) && (defined(__i386__) || defined(__x86_64__) || \
114 defined(_M_IX86) || defined(_M_X64))
116 unsigned int regs
[4];
117 char str
[sizeof(unsigned int[4])];
120 if(!__get_cpuid(0, &cpuinf
[0].regs
[0], &cpuinf
[0].regs
[1], &cpuinf
[0].regs
[2], &cpuinf
[0].regs
[3]))
121 ERR("Failed to get CPUID\n");
124 unsigned int maxfunc
= cpuinf
[0].regs
[0];
125 unsigned int maxextfunc
= 0;
127 if(__get_cpuid(0x80000000, &cpuinf
[0].regs
[0], &cpuinf
[0].regs
[1], &cpuinf
[0].regs
[2], &cpuinf
[0].regs
[3]))
128 maxextfunc
= cpuinf
[0].regs
[0];
129 TRACE("Detected max CPUID function: 0x%x (ext. 0x%x)\n", maxfunc
, maxextfunc
);
131 TRACE("Vendor ID: \"%.4s%.4s%.4s\"\n", cpuinf
[0].str
+4, cpuinf
[0].str
+12, cpuinf
[0].str
+8);
132 if(maxextfunc
>= 0x80000004 &&
133 __get_cpuid(0x80000002, &cpuinf
[0].regs
[0], &cpuinf
[0].regs
[1], &cpuinf
[0].regs
[2], &cpuinf
[0].regs
[3]) &&
134 __get_cpuid(0x80000003, &cpuinf
[1].regs
[0], &cpuinf
[1].regs
[1], &cpuinf
[1].regs
[2], &cpuinf
[1].regs
[3]) &&
135 __get_cpuid(0x80000004, &cpuinf
[2].regs
[0], &cpuinf
[2].regs
[1], &cpuinf
[2].regs
[2], &cpuinf
[2].regs
[3]))
136 TRACE("Name: \"%.16s%.16s%.16s\"\n", cpuinf
[0].str
, cpuinf
[1].str
, cpuinf
[2].str
);
139 __get_cpuid(1, &cpuinf
[0].regs
[0], &cpuinf
[0].regs
[1], &cpuinf
[0].regs
[2], &cpuinf
[0].regs
[3]))
141 if((cpuinf
[0].regs
[3]&(1<<25)))
144 if((cpuinf
[0].regs
[3]&(1<<26)))
146 caps
|= CPU_CAP_SSE2
;
147 if((cpuinf
[0].regs
[2]&(1<<19)))
148 caps
|= CPU_CAP_SSE4_1
;
153 #elif defined(HAVE_CPUID_INTRINSIC) && (defined(__i386__) || defined(__x86_64__) || \
154 defined(_M_IX86) || defined(_M_X64))
157 char str
[sizeof(int[4])];
160 (__cpuid
)(cpuinf
[0].regs
, 0);
161 if(cpuinf
[0].regs
[0] == 0)
162 ERR("Failed to get CPUID\n");
165 unsigned int maxfunc
= cpuinf
[0].regs
[0];
166 unsigned int maxextfunc
;
168 (__cpuid
)(cpuinf
[0].regs
, 0x80000000);
169 maxextfunc
= cpuinf
[0].regs
[0];
171 TRACE("Detected max CPUID function: 0x%x (ext. 0x%x)\n", maxfunc
, maxextfunc
);
173 TRACE("Vendor ID: \"%.4s%.4s%.4s\"\n", cpuinf
[0].str
+4, cpuinf
[0].str
+12, cpuinf
[0].str
+8);
174 if(maxextfunc
>= 0x80000004)
176 (__cpuid
)(cpuinf
[0].regs
, 0x80000002);
177 (__cpuid
)(cpuinf
[1].regs
, 0x80000003);
178 (__cpuid
)(cpuinf
[2].regs
, 0x80000004);
179 TRACE("Name: \"%.16s%.16s%.16s\"\n", cpuinf
[0].str
, cpuinf
[1].str
, cpuinf
[2].str
);
184 (__cpuid
)(cpuinf
[0].regs
, 1);
185 if((cpuinf
[0].regs
[3]&(1<<25)))
188 if((cpuinf
[0].regs
[3]&(1<<26)))
190 caps
|= CPU_CAP_SSE2
;
191 if((cpuinf
[0].regs
[2]&(1<<19)))
192 caps
|= CPU_CAP_SSE4_1
;
198 /* Assume support for whatever's supported if we can't check for it */
199 #if defined(HAVE_SSE4_1)
200 #warning "Assuming SSE 4.1 run-time support!"
201 capfilter
|= CPU_CAP_SSE
| CPU_CAP_SSE2
| CPU_CAP_SSE4_1
;
202 #elif defined(HAVE_SSE2)
203 #warning "Assuming SSE 2 run-time support!"
204 capfilter
|= CPU_CAP_SSE
| CPU_CAP_SSE2
;
205 #elif defined(HAVE_SSE)
206 #warning "Assuming SSE run-time support!"
207 capfilter
|= CPU_CAP_SSE
;
211 /* Assume Neon support if compiled with it */
212 caps
|= CPU_CAP_NEON
;
215 TRACE("Extensions:%s%s%s%s%s\n",
216 ((capfilter
&CPU_CAP_SSE
) ? ((caps
&CPU_CAP_SSE
) ? " +SSE" : " -SSE") : ""),
217 ((capfilter
&CPU_CAP_SSE2
) ? ((caps
&CPU_CAP_SSE2
) ? " +SSE2" : " -SSE2") : ""),
218 ((capfilter
&CPU_CAP_SSE4_1
) ? ((caps
&CPU_CAP_SSE4_1
) ? " +SSE4.1" : " -SSE4.1") : ""),
219 ((capfilter
&CPU_CAP_NEON
) ? ((caps
&CPU_CAP_NEON
) ? " +Neon" : " -Neon") : ""),
220 ((!capfilter
) ? " -none-" : "")
222 CPUCapFlags
= caps
& capfilter
;
226 void *al_malloc(size_t alignment
, size_t size
)
228 #if defined(HAVE_ALIGNED_ALLOC)
229 size
= (size
+(alignment
-1))&~(alignment
-1);
230 return aligned_alloc(alignment
, size
);
231 #elif defined(HAVE_POSIX_MEMALIGN)
233 if(posix_memalign(&ret
, alignment
, size
) == 0)
236 #elif defined(HAVE__ALIGNED_MALLOC)
237 return _aligned_malloc(size
, alignment
);
239 char *ret
= malloc(size
+alignment
);
243 while(((ptrdiff_t)ret
&(alignment
-1)) != 0)
250 void *al_calloc(size_t alignment
, size_t size
)
252 void *ret
= al_malloc(alignment
, size
);
253 if(ret
) memset(ret
, 0, size
);
257 void al_free(void *ptr
)
259 #if defined(HAVE_ALIGNED_ALLOC) || defined(HAVE_POSIX_MEMALIGN)
261 #elif defined(HAVE__ALIGNED_MALLOC)
269 } while(*finder
== 0x55);
276 void SetMixerFPUMode(FPUCtl
*ctl
)
279 fegetenv(STATIC_CAST(fenv_t
, ctl
));
280 #if defined(__GNUC__) && defined(HAVE_SSE)
281 if((CPUCapFlags
&CPU_CAP_SSE
))
282 __asm__
__volatile__("stmxcsr %0" : "=m" (*&ctl
->sse_state
));
286 fesetround(FE_TOWARDZERO
);
288 #if defined(__GNUC__) && defined(HAVE_SSE)
289 if((CPUCapFlags
&CPU_CAP_SSE
))
291 int sseState
= ctl
->sse_state
;
292 sseState
|= 0x6000; /* set round-to-zero */
293 sseState
|= 0x8000; /* set flush-to-zero */
294 if((CPUCapFlags
&CPU_CAP_SSE2
))
295 sseState
|= 0x0040; /* set denormals-are-zero */
296 __asm__
__volatile__("ldmxcsr %0" : : "m" (*&sseState
));
300 #elif defined(HAVE___CONTROL87_2)
303 __control87_2(0, 0, &ctl
->state
, NULL
);
304 __control87_2(_RC_CHOP
, _MCW_RC
, &mode
, NULL
);
306 if((CPUCapFlags
&CPU_CAP_SSE
))
308 __control87_2(0, 0, NULL
, &ctl
->sse_state
);
309 __control87_2(_RC_CHOP
|_DN_FLUSH
, _MCW_RC
|_MCW_DN
, NULL
, &mode
);
313 #elif defined(HAVE__CONTROLFP)
315 ctl
->state
= _controlfp(0, 0);
316 (void)_controlfp(_RC_CHOP
, _MCW_RC
);
320 void RestoreFPUMode(const FPUCtl
*ctl
)
323 fesetenv(STATIC_CAST(fenv_t
, ctl
));
324 #if defined(__GNUC__) && defined(HAVE_SSE)
325 if((CPUCapFlags
&CPU_CAP_SSE
))
326 __asm__
__volatile__("ldmxcsr %0" : : "m" (*&ctl
->sse_state
));
329 #elif defined(HAVE___CONTROL87_2)
332 __control87_2(ctl
->state
, _MCW_RC
, &mode
, NULL
);
334 if((CPUCapFlags
&CPU_CAP_SSE
))
335 __control87_2(ctl
->sse_state
, _MCW_RC
|_MCW_DN
, NULL
, &mode
);
338 #elif defined(HAVE__CONTROLFP)
340 _controlfp(ctl
->state
, _MCW_RC
);
347 static WCHAR
*FromUTF8(const char *str
)
352 if((len
=MultiByteToWideChar(CP_UTF8
, 0, str
, -1, NULL
, 0)) > 0)
354 out
= calloc(sizeof(WCHAR
), len
);
355 MultiByteToWideChar(CP_UTF8
, 0, str
, -1, out
, len
);
361 void *LoadLib(const char *name
)
366 wname
= FromUTF8(name
);
368 ERR("Failed to convert UTF-8 filename: \"%s\"\n", name
);
371 hdl
= LoadLibraryW(wname
);
376 void CloseLib(void *handle
)
377 { FreeLibrary((HANDLE
)handle
); }
378 void *GetSymbol(void *handle
, const char *name
)
382 ret
= (void*)GetProcAddress((HANDLE
)handle
, name
);
384 ERR("Failed to load %s\n", name
);
388 WCHAR
*strdupW(const WCHAR
*str
)
398 ret
= calloc(sizeof(WCHAR
), len
+1);
400 memcpy(ret
, str
, sizeof(WCHAR
)*len
);
404 FILE *al_fopen(const char *fname
, const char *mode
)
406 WCHAR
*wname
=NULL
, *wmode
=NULL
;
409 wname
= FromUTF8(fname
);
410 wmode
= FromUTF8(mode
);
412 ERR("Failed to convert UTF-8 filename: \"%s\"\n", fname
);
414 ERR("Failed to convert UTF-8 mode: \"%s\"\n", mode
);
416 file
= _wfopen(wname
, wmode
);
428 void *LoadLib(const char *name
)
434 handle
= dlopen(name
, RTLD_NOW
);
435 if((err
=dlerror()) != NULL
)
439 void CloseLib(void *handle
)
441 void *GetSymbol(void *handle
, const char *name
)
447 sym
= dlsym(handle
, name
);
448 if((err
=dlerror()) != NULL
)
450 WARN("Failed to load %s: %s\n", name
, err
);
460 void al_print(const char *type
, const char *func
, const char *fmt
, ...)
465 fprintf(LogFile
, "AL lib: %s %s: ", type
, func
);
466 vfprintf(LogFile
, fmt
, ap
);
473 static inline int is_slash(int c
)
474 { return (c
== '\\' || c
== '/'); }
476 FILE *OpenDataFile(const char *fname
, const char *subdir
)
478 static const int ids
[2] = { CSIDL_APPDATA
, CSIDL_COMMON_APPDATA
};
479 WCHAR
*wname
=NULL
, *wsubdir
=NULL
;
483 /* If the path is absolute, open it directly. */
484 if(fname
[0] != '\0' && fname
[1] == ':' && is_slash(fname
[2]))
486 if((f
=al_fopen(fname
, "rb")) != NULL
)
488 TRACE("Opened %s\n", fname
);
491 WARN("Could not open %s\n", fname
);
495 /* If it's relative, try the current directory first before the data directories. */
496 if((f
=al_fopen(fname
, "rb")) != NULL
)
498 TRACE("Opened %s\n", fname
);
501 WARN("Could not open %s\n", fname
);
503 wname
= FromUTF8(fname
);
504 wsubdir
= FromUTF8(subdir
);
506 ERR("Failed to convert UTF-8 filename: \"%s\"\n", fname
);
508 ERR("Failed to convert UTF-8 subdir: \"%s\"\n", subdir
);
509 else for(i
= 0;i
< 2;i
++)
511 WCHAR buffer
[PATH_MAX
];
514 if(SHGetSpecialFolderPathW(NULL
, buffer
, ids
[i
], FALSE
) == FALSE
)
517 len
= lstrlenW(buffer
);
518 if(len
> 0 && is_slash(buffer
[len
-1]))
519 buffer
[--len
] = '\0';
520 _snwprintf(buffer
+len
, PATH_MAX
-len
, L
"/%ls/%ls", wsubdir
, wname
);
521 len
= lstrlenW(buffer
);
525 if(buffer
[len
] == '/')
529 if((f
=_wfopen(buffer
, L
"rb")) != NULL
)
531 TRACE("Opened %ls\n", buffer
);
534 WARN("Could not open %ls\n", buffer
);
542 FILE *OpenDataFile(const char *fname
, const char *subdir
)
544 char buffer
[PATH_MAX
] = "";
545 const char *str
, *next
;
550 if((f
=al_fopen(fname
, "rb")) != NULL
)
552 TRACE("Opened %s\n", fname
);
555 WARN("Could not open %s\n", fname
);
559 if((f
=al_fopen(fname
, "rb")) != NULL
)
561 TRACE("Opened %s\n", fname
);
564 WARN("Could not open %s\n", fname
);
566 if((str
=getenv("XDG_DATA_HOME")) != NULL
&& str
[0] != '\0')
567 snprintf(buffer
, sizeof(buffer
), "%s/%s/%s", str
, subdir
, fname
);
568 else if((str
=getenv("HOME")) != NULL
&& str
[0] != '\0')
569 snprintf(buffer
, sizeof(buffer
), "%s/.local/share/%s/%s", str
, subdir
, fname
);
572 if((f
=al_fopen(buffer
, "rb")) != NULL
)
574 TRACE("Opened %s\n", buffer
);
577 WARN("Could not open %s\n", buffer
);
580 if((str
=getenv("XDG_DATA_DIRS")) == NULL
|| str
[0] == '\0')
581 str
= "/usr/local/share/:/usr/share/";
584 while((str
=next
) != NULL
&& str
[0] != '\0')
587 next
= strchr(str
, ':');
597 if(len
> sizeof(buffer
)-1)
598 len
= sizeof(buffer
)-1;
599 strncpy(buffer
, str
, len
);
601 snprintf(buffer
+len
, sizeof(buffer
)-len
, "/%s/%s", subdir
, fname
);
603 if((f
=al_fopen(buffer
, "rb")) != NULL
)
605 TRACE("Opened %s\n", buffer
);
608 WARN("Could not open %s\n", buffer
);
616 void SetRTPriority(void)
618 ALboolean failed
= AL_FALSE
;
622 failed
= !SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL
);
623 #elif defined(HAVE_PTHREAD_SETSCHEDPARAM) && !defined(__OpenBSD__)
626 struct sched_param param
;
627 /* Use the minimum real-time priority possible for now (on Linux this
628 * should be 1 for SCHED_RR) */
629 param
.sched_priority
= sched_get_priority_min(SCHED_RR
);
630 failed
= !!pthread_setschedparam(pthread_self(), SCHED_RR
, ¶m
);
633 /* Real-time priority not available */
634 failed
= (RTPrioLevel
>0);
637 ERR("Failed to set priority level for thread\n");
641 ALboolean
vector_reserve(char *ptr
, size_t base_size
, size_t obj_size
, size_t obj_count
, ALboolean exact
)
643 vector_
*vecptr
= (vector_
*)ptr
;
644 if((*vecptr
? (*vecptr
)->Capacity
: 0) < obj_count
)
646 size_t old_size
= (*vecptr
? (*vecptr
)->Size
: 0);
649 /* Use the next power-of-2 size if we don't need to allocate the exact
650 * amount. This is preferred when regularly increasing the vector since
651 * it means fewer reallocations. Though it means it also wastes some
653 if(exact
== AL_FALSE
&& obj_count
< INT_MAX
)
654 obj_count
= NextPowerOf2((ALuint
)obj_count
);
656 /* Need to be explicit with the caller type's base size, because it
657 * could have extra padding before the start of the array (that is,
658 * sizeof(*vector_) may not equal base_size). */
659 temp
= realloc(*vecptr
, base_size
+ obj_size
*obj_count
);
660 if(temp
== NULL
) return AL_FALSE
;
663 (*vecptr
)->Capacity
= obj_count
;
664 (*vecptr
)->Size
= old_size
;
669 ALboolean
vector_resize(char *ptr
, size_t base_size
, size_t obj_size
, size_t obj_count
)
671 vector_
*vecptr
= (vector_
*)ptr
;
672 if(*vecptr
|| obj_count
> 0)
674 if(!vector_reserve((char*)vecptr
, base_size
, obj_size
, obj_count
, AL_TRUE
))
676 (*vecptr
)->Size
= obj_count
;
681 ALboolean
vector_insert(char *ptr
, size_t base_size
, size_t obj_size
, void *ins_pos
, const void *datstart
, const void *datend
)
683 vector_
*vecptr
= (vector_
*)ptr
;
684 if(datstart
!= datend
)
686 ptrdiff_t ins_elem
= (*vecptr
? ((char*)ins_pos
- ((char*)(*vecptr
) + base_size
)) :
687 ((char*)ins_pos
- (char*)NULL
)) /
689 ptrdiff_t numins
= ((const char*)datend
- (const char*)datstart
) / obj_size
;
692 if((size_t)numins
+ VECTOR_SIZE(*vecptr
) < (size_t)numins
||
693 !vector_reserve((char*)vecptr
, base_size
, obj_size
, VECTOR_SIZE(*vecptr
)+numins
, AL_TRUE
))
696 /* NOTE: ins_pos may have been invalidated if *vecptr moved. Use ins_elem instead. */
697 if((size_t)ins_elem
< (*vecptr
)->Size
)
699 memmove((char*)(*vecptr
) + base_size
+ ((ins_elem
+numins
)*obj_size
),
700 (char*)(*vecptr
) + base_size
+ ((ins_elem
)*obj_size
),
701 ((*vecptr
)->Size
-ins_elem
)*obj_size
);
703 memcpy((char*)(*vecptr
) + base_size
+ (ins_elem
*obj_size
),
704 datstart
, numins
*obj_size
);
705 (*vecptr
)->Size
+= numins
;
711 extern inline void al_string_deinit(al_string
*str
);
712 extern inline size_t al_string_length(const_al_string str
);
713 extern inline ALboolean
al_string_empty(const_al_string str
);
714 extern inline const al_string_char_type
*al_string_get_cstr(const_al_string str
);
716 void al_string_clear(al_string
*str
)
718 /* Reserve one more character than the total size of the string. This is to
719 * ensure we have space to add a null terminator in the string data so it
720 * can be used as a C-style string. */
721 VECTOR_RESERVE(*str
, 1);
722 VECTOR_RESIZE(*str
, 0);
723 *VECTOR_ITER_END(*str
) = 0;
726 static inline int al_string_compare(const al_string_char_type
*str1
, size_t str1len
,
727 const al_string_char_type
*str2
, size_t str2len
)
729 size_t complen
= (str1len
< str2len
) ? str1len
: str2len
;
730 int ret
= memcmp(str1
, str2
, complen
);
733 if(str1len
> str2len
) return 1;
734 if(str1len
< str2len
) return -1;
738 int al_string_cmp(const_al_string str1
, const_al_string str2
)
740 return al_string_compare(&VECTOR_FRONT(str1
), al_string_length(str1
),
741 &VECTOR_FRONT(str2
), al_string_length(str2
));
743 int al_string_cmp_cstr(const_al_string str1
, const al_string_char_type
*str2
)
745 return al_string_compare(&VECTOR_FRONT(str1
), al_string_length(str1
),
749 void al_string_copy(al_string
*str
, const_al_string from
)
751 size_t len
= al_string_length(from
);
752 VECTOR_RESERVE(*str
, len
+1);
753 VECTOR_RESIZE(*str
, 0);
754 VECTOR_INSERT(*str
, VECTOR_ITER_END(*str
), VECTOR_ITER_BEGIN(from
), VECTOR_ITER_BEGIN(from
)+len
);
755 *VECTOR_ITER_END(*str
) = 0;
758 void al_string_copy_cstr(al_string
*str
, const al_string_char_type
*from
)
760 size_t len
= strlen(from
);
761 VECTOR_RESERVE(*str
, len
+1);
762 VECTOR_RESIZE(*str
, 0);
763 VECTOR_INSERT(*str
, VECTOR_ITER_END(*str
), from
, from
+len
);
764 *VECTOR_ITER_END(*str
) = 0;
767 void al_string_append_char(al_string
*str
, const al_string_char_type c
)
769 VECTOR_RESERVE(*str
, al_string_length(*str
)+2);
770 VECTOR_PUSH_BACK(*str
, c
);
771 *VECTOR_ITER_END(*str
) = 0;
774 void al_string_append_cstr(al_string
*str
, const al_string_char_type
*from
)
776 size_t len
= strlen(from
);
779 VECTOR_RESERVE(*str
, al_string_length(*str
)+len
+1);
780 VECTOR_INSERT(*str
, VECTOR_ITER_END(*str
), from
, from
+len
);
781 *VECTOR_ITER_END(*str
) = 0;
785 void al_string_append_range(al_string
*str
, const al_string_char_type
*from
, const al_string_char_type
*to
)
789 VECTOR_RESERVE(*str
, al_string_length(*str
)+(to
-from
)+1);
790 VECTOR_INSERT(*str
, VECTOR_ITER_END(*str
), from
, to
);
791 *VECTOR_ITER_END(*str
) = 0;
796 void al_string_copy_wcstr(al_string
*str
, const wchar_t *from
)
799 if((len
=WideCharToMultiByte(CP_UTF8
, 0, from
, -1, NULL
, 0, NULL
, NULL
)) > 0)
801 VECTOR_RESERVE(*str
, len
);
802 VECTOR_RESIZE(*str
, len
-1);
803 WideCharToMultiByte(CP_UTF8
, 0, from
, -1, &VECTOR_FRONT(*str
), len
, NULL
, NULL
);
804 *VECTOR_ITER_END(*str
) = 0;