2 Copyright (c) 2001, Loki software, inc.
\r
5 Redistribution and use in source and binary forms, with or without modification,
\r
6 are permitted provided that the following conditions are met:
\r
8 Redistributions of source code must retain the above copyright notice, this list
\r
9 of conditions and the following disclaimer.
\r
11 Redistributions in binary form must reproduce the above copyright notice, this
\r
12 list of conditions and the following disclaimer in the documentation and/or
\r
13 other materials provided with the distribution.
\r
15 Neither the name of Loki software nor the names of its contributors may be used
\r
16 to endorse or promote products derived from this software without specific prior
\r
17 written permission.
\r
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
\r
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
22 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
\r
23 DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
\r
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
\r
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
\r
26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
32 // Missing functions
\r
34 // Leonardo Zide (leo@lokigames.com)
\r
37 #if defined (__linux__) || defined (__APPLE__)
\r
41 #include <sys/time.h>
\r
43 #include "missing.h"
\r
45 bool CopyFile(const char *lpExistingFileName, const char *lpNewFileName)
\r
50 char realsrc[PATH_MAX], realdest[PATH_MAX];
\r
52 realpath (lpExistingFileName, realsrc);
\r
53 realpath (lpNewFileName, realdest);
\r
55 src = fopen (realsrc, "rb");
\r
58 dst = fopen (realdest, "wb");
\r
65 fseek (src, 0, SEEK_END);
\r
71 if (fread (buf, l, 1, src) == 1)
\r
72 if (fwrite (buf, l, 1, dst) == 1)
\r
82 int GetFullPathName(const char *lpFileName, int nBufferLength, char *lpBuffer, char **lpFilePart)
\r
84 if (lpFileName[0] == '/')
\r
86 strcpy (lpBuffer, lpFileName);
\r
87 *lpFilePart = strrchr (lpBuffer, '/');
\r
88 return strlen (lpBuffer);
\r
91 if (getcwd (lpBuffer, nBufferLength) == NULL)
\r
94 strcat (lpBuffer, "/");
\r
95 *lpFilePart = lpBuffer + strlen (lpBuffer);
\r
96 strcat (lpBuffer, lpFileName);
\r
98 char *scr = lpBuffer, *dst = lpBuffer;
\r
99 for (int i = 0; (i < nBufferLength) && (*scr != 0); i++)
\r
101 if (*scr == '/' && *(scr+1) == '.' && *(scr+2) == '.')
\r
104 while (dst != lpBuffer && *dst != '/')
\r
117 return strlen (lpBuffer);
\r
120 static void g_string_sprintfa_int (GString *string, const gchar *fmt, va_list args)
\r
124 buffer = g_strdup_vprintf (fmt, args);
\r
125 g_string_append (string, buffer);
\r
129 const CString& CString::operator=(const char* lpsz)
\r
131 g_string_assign (m_str, lpsz);
\r
135 const CString& CString::operator+=(const char* lpsz)
\r
137 g_string_append (m_str, lpsz);
\r
141 CString::operator char*() const
\r
146 void CString::Format(const char* fmt, ...)
\r
150 g_string_truncate (m_str, 0);
\r
152 va_start (args, fmt);
\r
153 g_string_sprintfa_int (m_str, fmt, args);
\r
157 CString CString::Right(int nCount) const
\r
161 else if (nCount > m_str->len)
\r
162 nCount = m_str->len;
\r
164 CString dest (&m_str->str[m_str->len-nCount]);
\r
168 CString CString::Left(int nCount) const
\r
172 else if (nCount > m_str->len)
\r
173 nCount = m_str->len;
\r
176 dest.m_str = g_string_sized_new (nCount);
\r
177 memcpy (dest.m_str->str, m_str->str, nCount);
\r
178 dest.m_str->str[nCount] = 0;
\r
182 void CString::SetAt(int nIndex, char ch)
\r
184 if (nIndex >= 0 && nIndex < m_str->len)
\r
185 m_str->str[nIndex] = ch;
\r
188 char CString::GetAt(int nIndex) const
\r
190 if (nIndex >= 0 && nIndex < m_str->len)
\r
191 return m_str->str[nIndex];
\r
195 char CString::operator[](int nIndex) const
\r
197 if (nIndex >= 0 && nIndex < m_str->len)
\r
198 return m_str->str[nIndex];
\r