Back to index

lightning-sunbird  0.9+nobinonly
morkConfig.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-  */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _MDB_
00039 #include "mdb.h"
00040 #endif
00041 
00042 #ifndef _MORK_
00043 #include "mork.h"
00044 #endif
00045 
00046 #ifndef _MORKCONFIG_
00047 #include "morkConfig.h"
00048 #endif
00049 
00050 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789
00051 
00052 void mork_assertion_signal(const char* inMessage)
00053 {
00054 #if defined(MORK_WIN) || defined(MORK_MAC)
00055   // asm { int 3 }
00056   NS_ASSERTION(0, inMessage);
00057 #endif /*MORK_WIN*/
00058 }
00059 
00060 #if defined(MORK_OS2)
00061 #include <fcntl.h>
00062 #include <sys/stat.h>
00063 #include <share.h>
00064 #include <io.h>
00065 
00066 FILE* mork_fileopen(const char* name, const char* mode)
00067 {
00068     int access = O_RDWR;
00069     int descriptor;
00070     int pmode = 0;
00071 
00072     /* Only possible options are wb+ and rb+ */
00073     MORK_ASSERT((mode[0] == 'w' || mode[0] == 'r') && (mode[1] == 'b') && (mode[2] == '+'));
00074     if (mode[0] == 'w') {
00075         access |= (O_TRUNC | O_CREAT);
00076         pmode = S_IREAD | S_IWRITE;
00077     }
00078 
00079     descriptor = sopen(name, access, SH_DENYNO, pmode);
00080     if (descriptor != -1) {
00081         return fdopen(descriptor, mode);
00082     }
00083     return NULL;
00084 }
00085 #endif
00086 
00087 #ifdef MORK_PROVIDE_STDLIB
00088 
00089 MORK_LIB_IMPL(mork_i4)
00090 mork_memcmp(const void* inOne, const void* inTwo, mork_size inSize)
00091 {
00092   register const mork_u1* t = (const mork_u1*) inTwo;
00093   register const mork_u1* s = (const mork_u1*) inOne;
00094   const mork_u1* end = s + inSize;
00095   register mork_i4 delta;
00096   
00097   while ( s < end )
00098   {
00099     delta = ((mork_i4) *s) - ((mork_i4) *t);
00100     if ( delta )
00101       return delta;
00102     else
00103     {
00104       ++t;
00105       ++s;
00106     }
00107   }
00108   return 0;
00109 }
00110 
00111 MORK_LIB_IMPL(void)
00112 mork_memcpy(void* outDst, const void* inSrc, mork_size inSize)
00113 {
00114   register mork_u1* d = (mork_u1*) outDst;
00115   mork_u1* end = d + inSize;
00116   register const mork_u1* s = ((const mork_u1*) inSrc);
00117   
00118   while ( inSize >= 8 )
00119   {
00120     *d++ = *s++;
00121     *d++ = *s++;
00122     *d++ = *s++;
00123     *d++ = *s++;
00124     
00125     *d++ = *s++;
00126     *d++ = *s++;
00127     *d++ = *s++;
00128     *d++ = *s++;
00129     
00130     inSize -= 8;
00131   }
00132   
00133   while ( d < end )
00134     *d++ = *s++;
00135 }
00136 
00137 MORK_LIB_IMPL(void)
00138 mork_memmove(void* outDst, const void* inSrc, mork_size inSize)
00139 {
00140   register mork_u1* d = (mork_u1*) outDst;
00141   register const mork_u1* s = (const mork_u1*) inSrc;
00142   if ( d != s && inSize ) // copy is necessary?
00143   {
00144     const mork_u1* srcEnd = s + inSize; // one past last source byte
00145     
00146     if ( d > s && d < srcEnd ) // overlap? need to copy backwards?
00147     {
00148       s = srcEnd; // start one past last source byte
00149       d += inSize; // start one past last dest byte
00150       mork_u1* dstBegin = d; // last byte to write is first in dest range
00151       while ( d - dstBegin >= 8 )
00152       {
00153         *--d = *--s;
00154         *--d = *--s;
00155         *--d = *--s;
00156         *--d = *--s;
00157         
00158         *--d = *--s;
00159         *--d = *--s;
00160         *--d = *--s;
00161         *--d = *--s;
00162       }
00163       while ( d > dstBegin )
00164         *--d = *--s;
00165     }
00166     else // can copy forwards without any overlap
00167     {
00168       mork_u1* dstEnd = d + inSize;
00169       while ( dstEnd - d >= 8 )
00170       {
00171         *d++ = *s++;
00172         *d++ = *s++;
00173         *d++ = *s++;
00174         *d++ = *s++;
00175         
00176         *d++ = *s++;
00177         *d++ = *s++;
00178         *d++ = *s++;
00179         *d++ = *s++;
00180       }
00181       while ( d < dstEnd )
00182         *d++ = *s++;
00183     }
00184   }
00185 }
00186 
00187 MORK_LIB_IMPL(void)
00188 mork_memset(void* outDst, int inByte, mork_size inSize)
00189 {
00190   register mork_u1* d = (mork_u1*) outDst;
00191   mork_u1* end = d + inSize;
00192   while ( d < end )
00193     *d++ = (mork_u1) inByte;
00194 }
00195 
00196 MORK_LIB_IMPL(void)
00197 mork_strcpy(void* outDst, const void* inSrc)
00198 {
00199   // back up one first to support preincrement
00200   register mork_u1* d = ((mork_u1*) outDst) - 1;
00201   register const mork_u1* s = ((const mork_u1*) inSrc) - 1;
00202   while ( ( *++d = *++s ) != 0 )
00203     /* empty */;
00204 }
00205 
00206 MORK_LIB_IMPL(mork_i4)
00207 mork_strcmp(const void* inOne, const void* inTwo)
00208 {
00209   register const mork_u1* t = (const mork_u1*) inTwo;
00210   register const mork_u1* s = ((const mork_u1*) inOne);
00211   register mork_i4 a;
00212   register mork_i4 b;
00213   register mork_i4 delta;
00214   
00215   do
00216   {
00217     a = (mork_i4) *s++;
00218     b = (mork_i4) *t++;
00219     delta = a - b;
00220   }
00221   while ( !delta && a && b );
00222   
00223   return delta;
00224 }
00225 
00226 MORK_LIB_IMPL(mork_i4)
00227 mork_strncmp(const void* inOne, const void* inTwo, mork_size inSize)
00228 {
00229   register const mork_u1* t = (const mork_u1*) inTwo;
00230   register const mork_u1* s = (const mork_u1*) inOne;
00231   const mork_u1* end = s + inSize;
00232   register mork_i4 delta;
00233   register mork_i4 a;
00234   register mork_i4 b;
00235   
00236   while ( s < end )
00237   {
00238     a = (mork_i4) *s++;
00239     b = (mork_i4) *t++;
00240     delta = a - b;
00241     if ( delta || !a || !b )
00242       return delta;
00243   }
00244   return 0;
00245 }
00246 
00247 MORK_LIB_IMPL(mork_size)
00248 mork_strlen(const void* inString)
00249 {
00250   // back up one first to support preincrement
00251   register const mork_u1* s = ((const mork_u1*) inString) - 1;
00252   while ( *++s ) // preincrement is cheapest
00253     /* empty */;
00254   
00255   return s - ((const mork_u1*) inString); // distance from original address
00256 }
00257 
00258 #endif /*MORK_PROVIDE_STDLIB*/
00259 
00260 //3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789