Cygwin: strptime: add release note
[newlib-cygwin.git] / winsup / cygwin / tls_pbuf.cc
blob7c8149856dbbfccb166c3b1b4d9b209e4eb6ef47
1 /* tls_pbuf.cc
3 This software is a copyrighted work licensed under the terms of the
4 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
5 details. */
7 #include <winsup.h>
8 #include <malloc.h>
9 #include "tls_pbuf.h"
11 #define tls_pbuf _my_tls.locals.pathbufs
13 void
14 tls_pathbuf::create ()
16 tls_heap = HeapCreate (HEAP_NO_SERIALIZE | HEAP_GENERATE_EXCEPTIONS,
17 NT_MAX_PATH * sizeof (WCHAR) * 10, /* 640K */
18 NT_MAX_PATH * TP_NUM_C_BUFS /* 4.6M */
19 + NT_MAX_PATH * TP_NUM_W_BUFS * sizeof (WCHAR));
22 void
23 tls_pathbuf::destroy ()
25 if (tls_heap)
26 HeapDestroy (tls_heap);
29 char *
30 tmp_pathbuf::c_get ()
32 if (!tls_pbuf.tls_heap)
33 tls_pbuf.create ();
34 if (tls_pbuf.c_cnt >= TP_NUM_C_BUFS)
35 api_fatal ("Internal error: TP_NUM_C_BUFS too small: %u", TP_NUM_C_BUFS);
36 if (!tls_pbuf.c_buf[tls_pbuf.c_cnt]
37 && !(tls_pbuf.c_buf[tls_pbuf.c_cnt]
38 = (char *) HeapAlloc (tls_pbuf.tls_heap, 0, NT_MAX_PATH)))
39 api_fatal ("Internal error: Out of memory for new path buf.");
40 return tls_pbuf.c_buf[tls_pbuf.c_cnt++];
43 PWCHAR
44 tmp_pathbuf::w_get ()
46 if (!tls_pbuf.tls_heap)
47 tls_pbuf.create ();
48 if (tls_pbuf.w_cnt >= TP_NUM_W_BUFS)
49 api_fatal ("Internal error: TP_NUM_W_BUFS too small: %u.", TP_NUM_W_BUFS);
50 if (!tls_pbuf.w_buf[tls_pbuf.w_cnt]
51 && !(tls_pbuf.w_buf[tls_pbuf.w_cnt]
52 = (PWCHAR) HeapAlloc (tls_pbuf.tls_heap, 0,
53 NT_MAX_PATH * sizeof (WCHAR))))
54 api_fatal ("Internal error: Out of memory for new wide path buf.");
55 return tls_pbuf.w_buf[tls_pbuf.w_cnt++];