~ubuntu-branches/ubuntu/karmic/firebird2.1/karmic

« back to all changes in this revision

Viewing changes to src/config/AdminException.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov
  • Date: 2008-05-26 23:59:25 UTC
  • Revision ID: james.westby@ubuntu.com-20080526235925-2pnqj6nxpppoeaer
Tags: upstream-2.1.0.17798-0.ds2
ImportĀ upstreamĀ versionĀ 2.1.0.17798-0.ds2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  
 
3
 *     The contents of this file are subject to the Initial 
 
4
 *     Developer's Public License Version 1.0 (the "License"); 
 
5
 *     you may not use this file except in compliance with the 
 
6
 *     License. You may obtain a copy of the License at 
 
7
 *     http://www.ibphoenix.com/idpl.html. 
 
8
 *
 
9
 *     Software distributed under the License is distributed on 
 
10
 *     an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either 
 
11
 *     express or implied.  See the License for the specific 
 
12
 *     language governing rights and limitations under the License.
 
13
 *
 
14
 *     The contents of this file or any work derived from this file
 
15
 *     may not be distributed under any other license whatsoever 
 
16
 *     without the express prior written permission of the original 
 
17
 *     author.
 
18
 *
 
19
 *
 
20
 *  The Original Code was created by James A. Starkey for IBPhoenix.
 
21
 *
 
22
 *  Copyright (c) 1997 - 2000, 2001, 2003 James A. Starkey
 
23
 *  Copyright (c) 1997 - 2000, 2001, 2003 Netfrastructure, Inc.
 
24
 *  All Rights Reserved.
 
25
 */
 
26
 
 
27
// AdminException.cpp: implementation of the AdminException class.
 
28
//
 
29
//////////////////////////////////////////////////////////////////////
 
30
 
 
31
#include "firebird.h"
 
32
#include <stdio.h>
 
33
#include <stdarg.h>
 
34
#include "../common/classes/alloc.h"
 
35
#include "AdminException.h"
 
36
 
 
37
#ifdef _WIN32
 
38
#define vsnprintf       _vsnprintf
 
39
#define snprintf        _snprintf
 
40
#endif
 
41
 
 
42
 
 
43
//////////////////////////////////////////////////////////////////////
 
44
// Construction/Destruction
 
45
//////////////////////////////////////////////////////////////////////
 
46
 
 
47
AdminException::AdminException(const char *txt, ...)
 
48
{
 
49
        va_list         args;
 
50
        va_start        (args, txt);
 
51
        char            temp [1024];
 
52
 
 
53
        int ret = vsnprintf (temp, sizeof (temp) - 1, txt, args);
 
54
        
 
55
        if (ret < 0)
 
56
                {
 
57
                int l = sizeof (temp) * 2;
 
58
                char *buffer = new char [l];
 
59
                vsnprintf (buffer, l, txt, args);
 
60
                text = buffer;
 
61
                delete [] buffer;
 
62
                }
 
63
        else if (static_cast<unsigned>(ret) >= sizeof (temp))
 
64
                {
 
65
                int l = ret + 1;
 
66
                char *buffer = new char [l];
 
67
                vsnprintf (buffer, l, txt, args);
 
68
                text = buffer;
 
69
                delete [] buffer;
 
70
                }
 
71
        else
 
72
                text = temp;
 
73
 
 
74
        va_end(args);
 
75
}
 
76
 
 
77
AdminException::~AdminException()
 
78
{
 
79
 
 
80
}
 
81
 
 
82
const char* AdminException::getText()
 
83
{
 
84
        return text;
 
85
}
 
86
 
 
87
void AdminException::setLocation(JString file, int lineNumber)
 
88
{
 
89
        fileName = file;
 
90
        char    temp [1024];
 
91
        char    *buffer = temp;
 
92
        int             l = sizeof (temp);
 
93
        
 
94
        for (int n = 0; n < 3; ++n)
 
95
                {
 
96
                int ret = snprintf (buffer, l, "%s, line %d: %s", 
 
97
                                                        (const char*) fileName, lineNumber, (const char*) text);
 
98
                if (ret < 0)
 
99
                        l += sizeof(temp);
 
100
                else if (ret >= l)
 
101
                        l = ret + 1;
 
102
                else
 
103
                        {
 
104
                        text = buffer;
 
105
                        break;
 
106
                        }
 
107
                if (text != buffer)
 
108
                        delete [] buffer;
 
109
                buffer = new char [l];
 
110
                }
 
111
        
 
112
        if (buffer != temp)
 
113
                delete [] buffer;
 
114
}