Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

unix_shared.c File Reference

#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <pwd.h>
#include "../game/q_shared.h"
#include "../qcommon/qcommon.h"

Include dependency graph for unix_shared.c:

Include dependency graph

Go to the source code of this file.

Defines

#define MAX_FOUND_FILES   0x1000

Functions

char * strlwr (char *s)
char * Sys_Cwd (void)
char * Sys_DefaultCDPath (void)
char * Sys_DefaultHomePath (void)
char * Sys_DefaultInstallPath (void)
void Sys_FreeFileList (char **list)
char * Sys_GetCurrentUser (void)
int Sys_GetProcessorId (void)
char ** Sys_ListFiles (const char *directory, const char *extension, char *filter, int *numfiles, qboolean wantsubs)
void Sys_ListFilteredFiles (const char *basedir, char *subdirs, char *filter, char **list, int *numfiles)
int Sys_Milliseconds (void)
void Sys_Mkdir (const char *path)
void Sys_SetDefaultCDPath (const char *path)
void Sys_SetDefaultHomePath (const char *path)
void Sys_SetDefaultInstallPath (const char *path)
void Sys_ShowConsole (int visLevel, qboolean quitOnClose)

Variables

char cdPath [MAX_OSPATH]
int curtime
char homePath [MAX_OSPATH]
char installPath [MAX_OSPATH]
unsigned long sys_timeBase = 0


Define Documentation

#define MAX_FOUND_FILES   0x1000
 

Definition at line 179 of file unix_shared.c.


Function Documentation

char* strlwr char *  s  ) 
 

Definition at line 165 of file unix_shared.c.

References assert, s, and tolower().

Referenced by AddToDirListAlphabetized(), ASE_KeyMAP_DIFFUSE(), GLimp_Init(), LoadModel(), Str::MakeLower(), OpenPK3(), PakLoadAnyFile(), QE_ExpandBspString(), Texture_LoadSkin(), and TRI_LoadPolysets().

00165                        {
00166   if ( s==NULL ) { // bk001204 - paranoia
00167     assert(0);
00168     return s;
00169   }
00170   while (*s) {
00171     *s = tolower(*s);
00172     s++;
00173   }
00174   return s; // bk001204 - duh
00175 }

Here is the call graph for this function:

char* Sys_Cwd void   ) 
 

Definition at line 346 of file unix_shared.c.

References MAX_OSPATH.

00347 {
00348     static char cwd[MAX_OSPATH];
00349 
00350     getcwd( cwd, sizeof( cwd ) - 1 );
00351     cwd[MAX_OSPATH-1] = 0;
00352 
00353     return cwd;
00354 }

char* Sys_DefaultCDPath void   ) 
 

Definition at line 361 of file unix_shared.c.

00362 {
00363         return cdPath;
00364 }

char* Sys_DefaultHomePath void   ) 
 

Definition at line 384 of file unix_shared.c.

References errno, getenv(), homePath, p, Q_strcat(), Q_strncpyz(), strerror(), and Sys_Error().

00385 {
00386     char *p;
00387 
00388         if (*homePath)
00389             return homePath;
00390             
00391     if ((p = getenv("HOME")) != NULL) {
00392         Q_strncpyz(homePath, p, sizeof(homePath));
00393 #ifdef MACOS_X
00394         Q_strcat(homePath, sizeof(homePath), "/Library/Application Support/Quake3");
00395 #else
00396         Q_strcat(homePath, sizeof(homePath), "/.q3a");
00397 #endif
00398         if (mkdir(homePath, 0777)) {
00399             if (errno != EEXIST) 
00400                 Sys_Error("Unable to create directory \"%s\", error is %s(%d)\n", homePath, strerror(errno), errno);
00401         }
00402         return homePath;
00403     }
00404     return ""; // assume current dir
00405 }

Here is the call graph for this function:

char* Sys_DefaultInstallPath void   ) 
 

Definition at line 371 of file unix_shared.c.

References Sys_Cwd().

00372 {
00373     if (*installPath)
00374         return installPath;
00375     else
00376         return Sys_Cwd();
00377 }

Here is the call graph for this function:

void Sys_FreeFileList char **  list  ) 
 

Definition at line 332 of file unix_shared.c.

References i, and Z_Free().

00332                                         {
00333     int     i;
00334 
00335     if ( !list ) {
00336         return;
00337     }
00338 
00339     for ( i = 0 ; list[i] ; i++ ) {
00340         Z_Free( list[i] );
00341     }
00342 
00343     Z_Free( list );
00344 }

Here is the call graph for this function:

char* Sys_GetCurrentUser void   ) 
 

Definition at line 418 of file unix_shared.c.

References p.

00419 {
00420     struct passwd *p;
00421 
00422     if ( (p = getpwuid( getuid() )) == NULL ) {
00423         return "player";
00424     }
00425     return p->pw_name;
00426 }

int Sys_GetProcessorId void   ) 
 

Definition at line 409 of file unix_shared.c.

00410 {
00411     return CPUID_GENERIC;
00412 }

char** Sys_ListFiles const char *  directory,
const char *  extension,
char *  filter,
int *  numfiles,
qboolean  wantsubs
 

Definition at line 235 of file unix_shared.c.

References Com_sprintf(), CopyString(), d, i, MAX_FOUND_FILES, Q_stricmp(), qboolean, strlen(), Sys_ListFilteredFiles(), and Z_Malloc().

00236 {
00237     struct dirent *d;
00238     // char *p; // bk001204 - unused
00239     DIR     *fdir;
00240     qboolean dironly = wantsubs;
00241     char        search[MAX_OSPATH];
00242     int         nfiles;
00243     char        **listCopy;
00244     char        *list[MAX_FOUND_FILES];
00245     //int           flag; // bk001204 - unused
00246     int         i;
00247     struct stat st;
00248 
00249     int         extLen;
00250 
00251     if (filter) {
00252 
00253         nfiles = 0;
00254         Sys_ListFilteredFiles( directory, "", filter, list, &nfiles );
00255 
00256         list[ nfiles ] = 0;
00257         *numfiles = nfiles;
00258 
00259         if (!nfiles)
00260             return NULL;
00261 
00262         listCopy = Z_Malloc( ( nfiles + 1 ) * sizeof( *listCopy ) );
00263         for ( i = 0 ; i < nfiles ; i++ ) {
00264             listCopy[i] = list[i];
00265         }
00266         listCopy[i] = NULL;
00267 
00268         return listCopy;
00269     }
00270 
00271     if ( !extension)
00272         extension = "";
00273 
00274     if ( extension[0] == '/' && extension[1] == 0 ) {
00275         extension = "";
00276         dironly = qtrue;
00277     }
00278 
00279     extLen = strlen( extension );
00280     
00281     // search
00282     nfiles = 0;
00283 
00284     if ((fdir = opendir(directory)) == NULL) {
00285         *numfiles = 0;
00286         return NULL;
00287     }
00288 
00289     while ((d = readdir(fdir)) != NULL) {
00290         Com_sprintf(search, sizeof(search), "%s/%s", directory, d->d_name);
00291         if (stat(search, &st) == -1)
00292             continue;
00293         if ((dironly && !(st.st_mode & S_IFDIR)) ||
00294             (!dironly && (st.st_mode & S_IFDIR)))
00295             continue;
00296 
00297         if (*extension) {
00298             if ( strlen( d->d_name ) < strlen( extension ) ||
00299                 Q_stricmp( 
00300                     d->d_name + strlen( d->d_name ) - strlen( extension ),
00301                     extension ) ) {
00302                 continue; // didn't match
00303             }
00304         }
00305 
00306         if ( nfiles == MAX_FOUND_FILES - 1 )
00307             break;
00308         list[ nfiles ] = CopyString( d->d_name );
00309         nfiles++;
00310     }
00311 
00312     list[ nfiles ] = 0;
00313 
00314     closedir(fdir);
00315 
00316     // return a copy of the list
00317     *numfiles = nfiles;
00318 
00319     if ( !nfiles ) {
00320         return NULL;
00321     }
00322 
00323     listCopy = Z_Malloc( ( nfiles + 1 ) * sizeof( *listCopy ) );
00324     for ( i = 0 ; i < nfiles ; i++ ) {
00325         listCopy[i] = list[i];
00326     }
00327     listCopy[i] = NULL;
00328 
00329     return listCopy;
00330 }

Here is the call graph for this function:

void Sys_ListFilteredFiles const char *  basedir,
char *  subdirs,
char *  filter,
char **  list,
int *  numfiles
 

Definition at line 182 of file unix_shared.c.

References Com_FilterPath(), Com_sprintf(), CopyString(), d, MAX_FOUND_FILES, Q_stricmp(), qfalse, strlen(), and Sys_ListFilteredFiles().

00182                                                                                                            {
00183     char        search[MAX_OSPATH], newsubdirs[MAX_OSPATH];
00184     char        filename[MAX_OSPATH];
00185     DIR         *fdir;
00186     struct dirent *d;
00187     struct stat st;
00188 
00189     if ( *numfiles >= MAX_FOUND_FILES - 1 ) {
00190         return;
00191     }
00192 
00193     if (strlen(subdirs)) {
00194         Com_sprintf( search, sizeof(search), "%s/%s", basedir, subdirs );
00195     }
00196     else {
00197         Com_sprintf( search, sizeof(search), "%s", basedir );
00198     }
00199 
00200     if ((fdir = opendir(search)) == NULL) {
00201         return;
00202     }
00203 
00204     while ((d = readdir(fdir)) != NULL) {
00205         Com_sprintf(filename, sizeof(filename), "%s/%s", search, d->d_name);
00206         if (stat(filename, &st) == -1)
00207             continue;
00208 
00209         if (st.st_mode & S_IFDIR) {
00210             if (Q_stricmp(d->d_name, ".") && Q_stricmp(d->d_name, "..")) {
00211                 if (strlen(subdirs)) {
00212                     Com_sprintf( newsubdirs, sizeof(newsubdirs), "%s/%s", subdirs, d->d_name);
00213                 }
00214                 else {
00215                     Com_sprintf( newsubdirs, sizeof(newsubdirs), "%s", d->d_name);
00216                 }
00217                 Sys_ListFilteredFiles( basedir, newsubdirs, filter, list, numfiles );
00218             }
00219         }
00220         if ( *numfiles >= MAX_FOUND_FILES - 1 ) {
00221             break;
00222         }
00223         Com_sprintf( filename, sizeof(filename), "%s/%s", subdirs, d->d_name );
00224         if (!Com_FilterPath( filter, filename, qfalse ))
00225             continue;
00226         list[ *numfiles ] = CopyString( filename );
00227         (*numfiles)++;
00228     }
00229 
00230     closedir(fdir);
00231 }

Here is the call graph for this function:

int Sys_Milliseconds void   ) 
 

Definition at line 62 of file unix_shared.c.

References curtime, NULL, and sys_timeBase.

00063 {
00064     struct timeval tp;
00065 
00066     gettimeofday(&tp, NULL);
00067     
00068     if (!sys_timeBase)
00069     {
00070         sys_timeBase = tp.tv_sec;
00071         return tp.tv_usec/1000;
00072     }
00073 
00074     curtime = (tp.tv_sec - sys_timeBase)*1000 + tp.tv_usec/1000;
00075     
00076     return curtime;
00077 }

void Sys_Mkdir const char *  path  ) 
 

Definition at line 160 of file unix_shared.c.

00161 {
00162     mkdir (path, 0777);
00163 }

void Sys_SetDefaultCDPath const char *  path  ) 
 

Definition at line 356 of file unix_shared.c.

References cdPath, and Q_strncpyz().

Referenced by main(), and Sys_CheckCD().

00357 {
00358     Q_strncpyz(cdPath, path, sizeof(cdPath));
00359 }

Here is the call graph for this function:

void Sys_SetDefaultHomePath const char *  path  ) 
 

Definition at line 379 of file unix_shared.c.

References homePath, and Q_strncpyz().

00380 {
00381     Q_strncpyz(homePath, path, sizeof(homePath));
00382 }

Here is the call graph for this function:

void Sys_SetDefaultInstallPath const char *  path  ) 
 

Definition at line 366 of file unix_shared.c.

References installPath, and Q_strncpyz().

00367 {
00368     Q_strncpyz(installPath, path, sizeof(installPath));
00369 }

Here is the call graph for this function:

void Sys_ShowConsole int  visLevel,
qboolean  quitOnClose
 

Definition at line 414 of file unix_shared.c.

00415 {
00416 }


Variable Documentation

char cdPath[MAX_OSPATH] [static]
 

Definition at line 38 of file unix_shared.c.

Referenced by Sys_SetDefaultCDPath().

int curtime
 

Definition at line 61 of file unix_shared.c.

Referenced by builtin(), main(), PC_ExpandBuiltinDefine(), and Sys_Milliseconds().

char homePath[MAX_OSPATH] [static]
 

Definition at line 44 of file unix_shared.c.

Referenced by Sys_DefaultHomePath(), and Sys_SetDefaultHomePath().

char installPath[MAX_OSPATH] [static]
 

Definition at line 41 of file unix_shared.c.

Referenced by Sys_SetDefaultInstallPath().

unsigned long sys_timeBase = 0
 

Definition at line 55 of file unix_shared.c.

Referenced by Sys_Milliseconds().


Generated on Thu Aug 25 15:39:20 2005 for Quake III Arena by  doxygen 1.3.9.1