add more spacing
[personal-kdebase.git] / workspace / ksplash / ksplashx / qglobal.cpp
blob046f5404581ebaf71d740ff3d75ea8360a0ca11e
1 /****************************************************************************
2 **
3 ** This file is based on sources of the Qt GUI Toolkit, used under the terms
4 ** of the GNU General Public License version 2 (see the original copyright
5 ** notice below).
6 ** All further contributions to this file are (and are required to be)
7 ** licensed under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
11 ** The original Qt license header follows:
14 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
16 ** This file is part of the kernel module of the Qt GUI Toolkit.
18 ** This file may be distributed under the terms of the Q Public License
19 ** as defined by Trolltech AS of Norway and appearing in the file
20 ** LICENSE.QPL included in the packaging of this file.
22 ** This file may be distributed and/or modified under the terms of the
23 ** GNU General Public License version 2 as published by the Free Software
24 ** Foundation and appearing in the file LICENSE.GPL included in the
25 ** packaging of this file.
27 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
28 ** licenses may use this file in accordance with the Qt Commercial License
29 ** Agreement provided with the Software.
31 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
32 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
34 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
35 ** information about Qt Commercial License Agreements.
36 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
37 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
39 ** Contact info@trolltech.com if any conditions of this licensing are
40 ** not clear to you.
42 **********************************************************************/
44 #include "qglobal.h"
46 static bool si_alreadyDone = false;
47 static int si_wordSize;
48 static bool si_bigEndian;
50 /*!
51 \relates QApplication
53 Obtains information about the system.
55 The system's word size in bits (typically 32) is returned in \a
56 *wordSize. The \a *bigEndian is set to TRUE if this is a big-endian
57 machine, or to FALSE if this is a little-endian machine.
59 In debug mode, this function calls qFatal() with a message if the
60 computer is truly weird (i.e. different endianness for 16 bit and
61 32 bit integers); in release mode it returns FALSE.
64 bool qSysInfo( int *wordSize, bool *bigEndian )
66 #if defined(QT_CHECK_NULL)
67 Q_ASSERT( wordSize != 0 );
68 Q_ASSERT( bigEndian != 0 );
69 #endif
71 if ( si_alreadyDone ) { // run it only once
72 *wordSize = si_wordSize;
73 *bigEndian = si_bigEndian;
74 return true;
77 si_wordSize = 0;
78 Q_ULONG n = (Q_ULONG)(~0);
79 while ( n ) { // detect word size
80 si_wordSize++;
81 n /= 2;
83 *wordSize = si_wordSize;
85 if ( *wordSize != 64 &&
86 *wordSize != 32 &&
87 *wordSize != 16 ) { // word size: 16, 32 or 64
88 #if defined(QT_CHECK_RANGE)
89 qFatal( "qSysInfo: Unsupported system word size %d", *wordSize );
90 #endif
91 return false;
93 if ( sizeof(Q_INT8) != 1 || sizeof(Q_INT16) != 2 || sizeof(Q_INT32) != 4 ||
94 sizeof(Q_ULONG)*8 != si_wordSize || sizeof(float) != 4 || sizeof(double) != 8 ) {
95 #if defined(QT_CHECK_RANGE)
96 qFatal( "qSysInfo: Unsupported system data type size" );
97 #endif
98 return false;
101 bool be16, be32; // determine byte ordering
102 short ns = 0x1234;
103 int nl = 0x12345678;
105 unsigned char *p = (unsigned char *)(&ns); // 16-bit integer
106 be16 = *p == 0x12;
108 p = (unsigned char *)(&nl); // 32-bit integer
109 if ( p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78 )
110 be32 = true;
111 else
112 if ( p[0] == 0x78 && p[1] == 0x56 && p[2] == 0x34 && p[3] == 0x12 )
113 be32 = false;
114 else
115 be32 = !be16;
117 if ( be16 != be32 ) { // strange machine!
118 #if defined(QT_CHECK_RANGE)
119 qFatal( "qSysInfo: Inconsistent system byte order" );
120 #endif
121 return false;
124 *bigEndian = si_bigEndian = be32;
125 si_alreadyDone = true;
126 return true;