OSDN Git Service

* dcrt0.cc (dll_crt0_1): Move internal locale setting prior to potential
[pf3gnuchains/pf3gnuchains3x.git] / winsup / cygwin / tls_pbuf.cc
1 /* tls_pbuf.cc
2
3    Copyright 2008 Red Hat, Inc.
4
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
7 details. */
8
9 #include <winsup.h>
10 #include <malloc.h>
11 #include "cygtls.h"
12 #include "tls_pbuf.h"
13
14 #define tls_pbuf        _my_tls.locals.pathbufs
15
16 void
17 tls_pathbuf::destroy ()
18 {
19   for (int i = 0; i < TP_NUM_C_BUFS; ++i)
20     if (c_buf[i])
21       free (c_buf[i]);
22   for (int i = 0; i < TP_NUM_W_BUFS; ++i)
23     if (w_buf[i])
24       free (w_buf[i]);
25 }
26
27 tmp_pathbuf::tmp_pathbuf ()
28 : c_buf_old (tls_pbuf.c_cnt),
29   w_buf_old (tls_pbuf.w_cnt)
30 {}
31
32 tmp_pathbuf::~tmp_pathbuf ()
33 {
34   tls_pbuf.c_cnt = c_buf_old;
35   tls_pbuf.w_cnt = w_buf_old;
36 }
37
38 char *
39 tmp_pathbuf::c_get ()
40 {
41   if (tls_pbuf.c_cnt >= TP_NUM_C_BUFS)
42     api_fatal ("Internal error: TP_NUM_C_BUFS too small.");
43   if (!tls_pbuf.c_buf[tls_pbuf.c_cnt]
44       && !(tls_pbuf.c_buf[tls_pbuf.c_cnt] = (char *) malloc (NT_MAX_PATH)))
45     api_fatal ("Internal error: Out of memory for new path buf.");
46   return tls_pbuf.c_buf[tls_pbuf.c_cnt++];
47 }
48
49 PWCHAR
50 tmp_pathbuf::w_get ()
51 {
52   if (tls_pbuf.w_cnt >= TP_NUM_W_BUFS)
53     api_fatal ("Internal error: TP_NUM_W_BUFS too small.");
54   if (!tls_pbuf.w_buf[tls_pbuf.w_cnt]
55       && !(tls_pbuf.w_buf[tls_pbuf.w_cnt]
56            = (PWCHAR) malloc (NT_MAX_PATH * sizeof (WCHAR))))
57     api_fatal ("Internal error: Out of memory for new wide path buf.");
58   return tls_pbuf.w_buf[tls_pbuf.w_cnt++];
59 }