2 Copyright (c) 2001, Loki software, inc.
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
8 Redistributions of source code must retain the above copyright notice, this list
9 of conditions and the following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice, this
12 list of conditions and the following disclaimer in the documentation and/or
13 other materials provided with the distribution.
15 Neither the name of Loki software nor the names of its contributors may be used
16 to endorse or promote products derived from this software without specific prior
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
23 DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 // Leonardo Zide (leo@lokigames.com)
37 #if defined (__linux__) || defined (__APPLE__)
42 #include <sys/types.h>
47 #include "qsysprintf.h"
49 bool CopyFile(const char *lpExistingFileName, const char *lpNewFileName)
55 char realsrc[PATH_MAX], realdest[PATH_MAX];
57 realpath (lpExistingFileName, realsrc);
58 realpath (lpNewFileName, realdest);
60 src = fopen (realsrc, "rb");
64 dst = fopen (realdest, "wb");
70 fseek (src, 0, SEEK_END);
76 if (fread (buf, l, 1, src) == 1)
77 if (fwrite (buf, l, 1, dst) == 1)
87 bool CreateDirectory( const char *directory ) {
88 if ( mkdir( directory, 0777 ) == -1 ) {
89 Sys_Printf( "mkdir %s failed\n", directory );
95 bool CopyTree( const char *source, const char *dest ) {
97 struct dirent *dirlist;
102 dir = opendir( source );
104 while ( ( dirlist = readdir( dir ) ) != NULL ) {
105 if ( strcmp( dirlist->d_name, "." ) == 0 || strcmp( dirlist->d_name, ".." ) == 0 ) {
108 if ( strcmp( dirlist->d_name, ".svn" ) == 0 ) {
113 srcEntry += dirlist->d_name;
116 dstEntry += dirlist->d_name;
117 if ( stat( srcEntry.GetBuffer(), &sbuf ) == -1 ) {
118 Sys_Printf( "stat %s failed\n", srcEntry.GetBuffer() );
120 if ( S_ISDIR( sbuf.st_mode ) ) {
122 if ( stat( dstEntry.GetBuffer(), &sbuf ) == -1 ) {
123 ret = CreateDirectory( dstEntry.GetBuffer() );
125 ret = CopyTree( srcEntry.GetBuffer(), dstEntry.GetBuffer() );
130 Sys_Printf( "copy %s -> %s\n", srcEntry.GetBuffer(), dstEntry.GetBuffer() );
131 bool ret = CopyFile( srcEntry.GetBuffer(), dstEntry.GetBuffer() );
142 int GetFullPathName(const char *lpFileName, int nBufferLength, char *lpBuffer, char **lpFilePart)
144 if (lpFileName[0] == '/')
146 strcpy (lpBuffer, lpFileName);
147 *lpFilePart = strrchr (lpBuffer, '/');
148 return strlen (lpBuffer);
151 if (getcwd (lpBuffer, nBufferLength) == NULL)
154 strcat (lpBuffer, "/");
155 *lpFilePart = lpBuffer + strlen (lpBuffer);
156 strcat (lpBuffer, lpFileName);
158 char *scr = lpBuffer, *dst = lpBuffer;
159 for (int i = 0; (i < nBufferLength) && (*scr != 0); i++)
161 if (*scr == '/' && *(scr+1) == '.' && *(scr+2) == '.')
164 while (dst != lpBuffer && *dst != '/')
177 return strlen (lpBuffer);