2001-03-30 23:24:57 +00:00
|
|
|
/*
|
|
|
|
sys.c
|
|
|
|
|
|
|
|
virtual filesystem functions
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2001-04-10 20:11:50 +00:00
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIMITS_H
|
|
|
|
# include <limits.h>
|
2001-03-30 23:24:57 +00:00
|
|
|
#endif
|
2002-06-04 16:17:10 +00:00
|
|
|
#ifdef HAVE_CONIO_H
|
|
|
|
# include <conio.h>
|
|
|
|
#endif
|
2001-03-30 23:24:57 +00:00
|
|
|
#ifdef HAVE_IO_H
|
2001-04-10 20:11:50 +00:00
|
|
|
# include <io.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_WINDOWS_H
|
2002-10-11 20:47:17 +00:00
|
|
|
# include "winquake.h"
|
2001-03-30 23:24:57 +00:00
|
|
|
#endif
|
2001-07-05 03:28:40 +00:00
|
|
|
#ifdef HAVE_SYS_MMAN_H
|
|
|
|
# include <sys/mman.h>
|
|
|
|
#endif
|
2010-08-24 07:01:01 +00:00
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
# include <pwd.h>
|
|
|
|
#endif
|
2001-03-30 23:24:57 +00:00
|
|
|
|
2002-08-20 23:04:57 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <setjmp.h>
|
2001-08-22 22:03:16 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdarg.h>
|
2001-11-27 04:50:41 +00:00
|
|
|
#include <time.h>
|
2001-08-22 22:03:16 +00:00
|
|
|
#include <sys/stat.h>
|
2007-03-22 23:20:57 +00:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
2001-08-22 22:03:16 +00:00
|
|
|
#include <sys/time.h>
|
2007-03-22 23:20:57 +00:00
|
|
|
#endif
|
2001-08-22 22:03:16 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2007-03-22 23:20:57 +00:00
|
|
|
#ifdef HAVE_DIRECT_H
|
|
|
|
#include <direct.h>
|
|
|
|
#endif
|
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
#include "QF/cvar.h"
|
2002-03-08 23:11:42 +00:00
|
|
|
#include "QF/dstring.h"
|
2001-03-30 23:24:57 +00:00
|
|
|
#include "QF/sys.h"
|
2002-11-14 05:28:54 +00:00
|
|
|
#include "QF/quakefs.h"
|
2010-08-24 07:01:01 +00:00
|
|
|
#include "QF/va.h"
|
2001-03-30 23:24:57 +00:00
|
|
|
|
2001-08-22 22:03:16 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2001-07-05 04:59:43 +00:00
|
|
|
static void Sys_StdPrintf (const char *fmt, va_list args);
|
2002-02-20 19:22:52 +00:00
|
|
|
static void Sys_ErrPrintf (const char *fmt, va_list args);
|
2001-07-05 04:59:43 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE cvar_t *sys_nostdout;
|
|
|
|
VISIBLE cvar_t *sys_extrasleep;
|
2001-08-29 17:45:53 +00:00
|
|
|
cvar_t *sys_dead_sleep;
|
|
|
|
cvar_t *sys_sleep;
|
|
|
|
|
2002-02-19 20:47:45 +00:00
|
|
|
int sys_checksum;
|
|
|
|
|
2002-02-20 19:22:52 +00:00
|
|
|
static sys_printf_t sys_std_printf_function = Sys_StdPrintf;
|
|
|
|
static sys_printf_t sys_err_printf_function = Sys_ErrPrintf;
|
2001-03-30 23:24:57 +00:00
|
|
|
|
2001-09-24 21:00:23 +00:00
|
|
|
typedef struct shutdown_list_s {
|
|
|
|
struct shutdown_list_s *next;
|
|
|
|
void (*func)(void);
|
|
|
|
} shutdown_list_t;
|
|
|
|
|
|
|
|
static shutdown_list_t *shutdown_list;
|
|
|
|
|
2004-03-26 02:52:47 +00:00
|
|
|
#ifndef _WIN32
|
2002-06-03 19:11:48 +00:00
|
|
|
static int do_stdin = 1;
|
|
|
|
qboolean stdin_ready;
|
2004-03-26 02:52:47 +00:00
|
|
|
#endif
|
2002-06-03 19:11:48 +00:00
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
/* The translation table between the graphical font and plain ASCII --KB */
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE const char sys_char_map[256] = {
|
2001-03-30 23:24:57 +00:00
|
|
|
'\0', '#', '#', '#', '#', '.', '#', '#',
|
|
|
|
'#', 9, 10, '#', ' ', 13, '.', '.',
|
|
|
|
'[', ']', '0', '1', '2', '3', '4', '5',
|
|
|
|
'6', '7', '8', '9', '.', '<', '=', '>',
|
|
|
|
' ', '!', '"', '#', '$', '%', '&', '\'',
|
|
|
|
'(', ')', '*', '+', ',', '-', '.', '/',
|
|
|
|
'0', '1', '2', '3', '4', '5', '6', '7',
|
|
|
|
'8', '9', ':', ';', '<', '=', '>', '?',
|
|
|
|
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
|
|
|
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
|
|
|
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
|
|
|
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
|
|
|
|
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
|
|
|
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
|
|
|
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
|
|
|
|
'x', 'y', 'z', '{', '|', '}', '~', '<',
|
|
|
|
|
|
|
|
'<', '=', '>', '#', '#', '.', '#', '#',
|
|
|
|
'#', '#', ' ', '#', ' ', '>', '.', '.',
|
|
|
|
'[', ']', '0', '1', '2', '3', '4', '5',
|
|
|
|
'6', '7', '8', '9', '.', '<', '=', '>',
|
|
|
|
' ', '!', '"', '#', '$', '%', '&', '\'',
|
|
|
|
'(', ')', '*', '+', ',', '-', '.', '/',
|
|
|
|
'0', '1', '2', '3', '4', '5', '6', '7',
|
|
|
|
'8', '9', ':', ';', '<', '=', '>', '?',
|
|
|
|
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
|
|
|
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
|
|
|
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
|
|
|
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
|
|
|
|
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
|
|
|
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
|
|
|
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
|
|
|
|
'x', 'y', 'z', '{', '|', '}', '~', '<'
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAXPRINTMSG 4096
|
|
|
|
|
2001-08-22 22:03:16 +00:00
|
|
|
|
2002-06-03 19:11:48 +00:00
|
|
|
#ifndef USE_INTEL_ASM
|
|
|
|
void
|
2002-08-20 23:04:57 +00:00
|
|
|
Sys_MaskFPUExceptions (void)
|
2002-06-03 19:11:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-05-09 22:58:37 +00:00
|
|
|
int
|
2001-03-30 23:24:57 +00:00
|
|
|
Sys_mkdir (const char *path)
|
|
|
|
{
|
2001-05-23 03:01:03 +00:00
|
|
|
#ifdef HAVE_MKDIR
|
2001-04-10 20:15:52 +00:00
|
|
|
# ifdef _WIN32
|
2001-04-10 20:11:50 +00:00
|
|
|
if (mkdir (path) == 0)
|
2004-05-09 22:58:37 +00:00
|
|
|
return 0;
|
2001-04-10 20:11:50 +00:00
|
|
|
# else
|
2001-03-30 23:24:57 +00:00
|
|
|
if (mkdir (path, 0777) == 0)
|
2004-05-09 22:58:37 +00:00
|
|
|
return 0;
|
2001-04-10 20:11:50 +00:00
|
|
|
# endif
|
2001-03-30 23:24:57 +00:00
|
|
|
#else
|
2001-05-23 03:01:03 +00:00
|
|
|
# ifdef HAVE__MKDIR
|
2001-03-30 23:24:57 +00:00
|
|
|
if (_mkdir (path) == 0)
|
2004-05-09 22:58:37 +00:00
|
|
|
return 0;
|
2001-03-30 23:24:57 +00:00
|
|
|
# else
|
|
|
|
# error do not know how to make directories
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
if (errno != EEXIST)
|
2004-05-09 22:58:37 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
2001-03-30 23:24:57 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int
|
2001-03-30 23:24:57 +00:00
|
|
|
Sys_FileTime (const char *path)
|
|
|
|
{
|
2001-05-23 03:01:03 +00:00
|
|
|
#ifdef HAVE_ACCESS
|
2001-03-30 23:24:57 +00:00
|
|
|
if (access (path, R_OK) == 0)
|
|
|
|
return 0;
|
|
|
|
#else
|
2001-05-23 03:01:03 +00:00
|
|
|
# ifdef HAVE__ACCESS
|
2001-03-30 23:24:57 +00:00
|
|
|
if (_access (path, R_OK) == 0)
|
|
|
|
return 0;
|
|
|
|
# else
|
2001-05-23 03:01:03 +00:00
|
|
|
# error do not know how to check access
|
2001-03-30 23:24:57 +00:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-07-05 04:59:43 +00:00
|
|
|
Sys_SetPrintf
|
|
|
|
|
|
|
|
for want of a better name, but it sets the function pointer for the
|
|
|
|
actual implementation of Sys_Printf.
|
2001-03-30 23:24:57 +00:00
|
|
|
*/
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2002-02-20 19:22:52 +00:00
|
|
|
Sys_SetStdPrintf (sys_printf_t func)
|
2001-07-05 04:59:43 +00:00
|
|
|
{
|
2002-02-20 19:22:52 +00:00
|
|
|
sys_std_printf_function = func;
|
2001-07-05 04:59:43 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2002-02-20 19:22:52 +00:00
|
|
|
Sys_SetErrPrintf (sys_printf_t func)
|
2001-03-30 23:24:57 +00:00
|
|
|
{
|
2002-02-20 19:22:52 +00:00
|
|
|
sys_err_printf_function = func;
|
|
|
|
}
|
2001-03-30 23:24:57 +00:00
|
|
|
|
2002-02-20 19:22:52 +00:00
|
|
|
void
|
|
|
|
Sys_Print (FILE *stream, const char *fmt, va_list args)
|
|
|
|
{
|
2002-03-08 23:11:42 +00:00
|
|
|
static dstring_t *msg;
|
2001-03-30 23:24:57 +00:00
|
|
|
unsigned char *p;
|
|
|
|
|
2002-03-08 23:11:42 +00:00
|
|
|
if (!msg)
|
|
|
|
msg = dstring_new ();
|
|
|
|
|
|
|
|
dvsprintf (msg, fmt, args);
|
2001-03-30 23:24:57 +00:00
|
|
|
|
2002-05-21 21:03:46 +00:00
|
|
|
if (stream == stderr) {
|
2004-01-20 03:47:27 +00:00
|
|
|
#ifdef _WIN32
|
2002-05-21 21:03:46 +00:00
|
|
|
MessageBox (NULL, msg->str, "Fatal Error", 0 /* MB_OK */ );
|
2002-02-20 19:22:52 +00:00
|
|
|
#endif
|
2002-05-21 21:03:46 +00:00
|
|
|
fputs ("Fatal Error: ", stream);
|
|
|
|
}
|
2002-02-20 19:22:52 +00:00
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
/* translate to ASCII instead of printing [xx] --KB */
|
2002-03-08 23:11:42 +00:00
|
|
|
for (p = (unsigned char *) msg->str; *p; p++)
|
2002-02-20 19:22:52 +00:00
|
|
|
putc (sys_char_map[*p], stream);
|
2001-03-30 23:24:57 +00:00
|
|
|
|
2002-05-21 21:03:46 +00:00
|
|
|
if (stream == stderr) {
|
|
|
|
fputs ("\n", stream);
|
|
|
|
}
|
2002-02-20 19:22:52 +00:00
|
|
|
fflush (stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Sys_StdPrintf (const char *fmt, va_list args)
|
|
|
|
{
|
|
|
|
if (sys_nostdout && sys_nostdout->int_val)
|
|
|
|
return;
|
|
|
|
Sys_Print (stdout, fmt, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Sys_ErrPrintf (const char *fmt, va_list args)
|
|
|
|
{
|
|
|
|
Sys_Print (stderr, fmt, args);
|
2001-03-30 23:24:57 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2001-07-05 04:59:43 +00:00
|
|
|
Sys_Printf (const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start (args, fmt);
|
2002-02-20 19:22:52 +00:00
|
|
|
sys_std_printf_function (fmt, args);
|
2001-07-05 06:31:05 +00:00
|
|
|
va_end (args);
|
2001-07-05 04:59:43 +00:00
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2010-11-23 05:09:30 +00:00
|
|
|
Sys_MaskPrintf (int mask, const char *fmt, ...)
|
2001-09-21 04:22:46 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
2010-11-23 05:09:30 +00:00
|
|
|
if (!developer || !(developer->int_val & mask))
|
2001-09-21 04:22:46 +00:00
|
|
|
return;
|
|
|
|
va_start (args, fmt);
|
2002-02-20 19:22:52 +00:00
|
|
|
sys_std_printf_function (fmt, args);
|
2001-09-21 04:22:46 +00:00
|
|
|
va_end (args);
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE double
|
2001-03-30 23:24:57 +00:00
|
|
|
Sys_DoubleTime (void)
|
|
|
|
{
|
2001-04-01 03:30:17 +00:00
|
|
|
static qboolean first = true;
|
2001-03-30 23:24:57 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
static DWORD starttime;
|
|
|
|
DWORD now;
|
|
|
|
|
|
|
|
now = timeGetTime ();
|
|
|
|
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
starttime = now;
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (now < starttime) // wrapped?
|
|
|
|
return (now / 1000.0) + (LONG_MAX - starttime / 1000.0);
|
|
|
|
|
|
|
|
if (now - starttime == 0)
|
|
|
|
return 0.0;
|
|
|
|
|
|
|
|
return (now - starttime) / 1000.0;
|
|
|
|
#else
|
|
|
|
struct timeval tp;
|
|
|
|
struct timezone tzp;
|
2001-04-01 03:30:17 +00:00
|
|
|
double now;
|
|
|
|
static double start_time;
|
2001-03-30 23:24:57 +00:00
|
|
|
|
|
|
|
gettimeofday (&tp, &tzp);
|
2002-06-03 23:29:34 +00:00
|
|
|
|
2003-08-11 22:39:07 +00:00
|
|
|
now = tp.tv_sec + tp.tv_usec / 1e6;
|
2001-03-30 23:24:57 +00:00
|
|
|
|
2001-04-01 03:30:17 +00:00
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
start_time = now;
|
2001-03-30 23:24:57 +00:00
|
|
|
}
|
|
|
|
|
2001-04-01 03:30:17 +00:00
|
|
|
return now - start_time;
|
2001-03-30 23:24:57 +00:00
|
|
|
#endif
|
|
|
|
}
|
2001-07-05 03:28:40 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2003-11-20 07:00:07 +00:00
|
|
|
Sys_TimeOfDay (date_t *date)
|
|
|
|
{
|
|
|
|
struct tm *newtime;
|
|
|
|
time_t long_time;
|
|
|
|
|
|
|
|
time (&long_time);
|
|
|
|
newtime = localtime (&long_time);
|
|
|
|
|
|
|
|
date->day = newtime->tm_mday;
|
|
|
|
date->mon = newtime->tm_mon;
|
|
|
|
date->year = newtime->tm_year + 1900;
|
|
|
|
date->hour = newtime->tm_hour;
|
|
|
|
date->min = newtime->tm_min;
|
|
|
|
date->sec = newtime->tm_sec;
|
|
|
|
strftime (date->str, 128, "%a %b %d, %H:%M %Y", newtime);
|
|
|
|
}
|
|
|
|
|
2007-03-24 12:28:47 +00:00
|
|
|
VISIBLE void
|
2007-04-04 07:48:14 +00:00
|
|
|
Sys_MakeCodeWriteable (uintptr_t startaddr, size_t length)
|
2001-07-05 03:28:40 +00:00
|
|
|
{
|
2001-07-05 18:47:19 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
DWORD flOldProtect;
|
|
|
|
|
|
|
|
if (!VirtualProtect
|
2001-12-02 17:29:14 +00:00
|
|
|
((LPVOID) startaddr, length, PAGE_READWRITE, &flOldProtect))
|
2002-05-21 21:03:46 +00:00
|
|
|
Sys_Error ("Protection change failed");
|
2001-07-05 18:47:19 +00:00
|
|
|
#else
|
|
|
|
# ifdef HAVE_MPROTECT
|
2001-07-05 03:28:40 +00:00
|
|
|
int r;
|
2003-07-17 21:01:25 +00:00
|
|
|
unsigned long endaddr = startaddr + length;
|
2003-07-21 20:51:03 +00:00
|
|
|
# ifdef HAVE__SC_PAGESIZE
|
2003-07-18 12:18:05 +00:00
|
|
|
long psize = sysconf (_SC_PAGESIZE);
|
2001-07-05 03:28:40 +00:00
|
|
|
|
2003-07-18 12:18:05 +00:00
|
|
|
startaddr &= ~(psize - 1);
|
|
|
|
endaddr = (endaddr + psize - 1) & ~(psize -1);
|
|
|
|
# else
|
|
|
|
# ifdef HAVE_GETPAGESIZE
|
2003-07-17 21:01:25 +00:00
|
|
|
int psize = getpagesize ();
|
2001-07-05 03:28:40 +00:00
|
|
|
|
2003-07-17 21:01:25 +00:00
|
|
|
startaddr &= ~(psize - 1);
|
|
|
|
endaddr = (endaddr + psize - 1) & ~(psize - 1);
|
2003-07-18 12:18:05 +00:00
|
|
|
# endif
|
2003-07-17 21:01:25 +00:00
|
|
|
# endif
|
2003-07-21 22:24:28 +00:00
|
|
|
// systems with mprotect but not getpagesize (or similar) probably don't
|
|
|
|
// need to page align the arguments to mprotect (eg, QNX)
|
2003-07-17 21:45:01 +00:00
|
|
|
r = mprotect ((char *) startaddr, endaddr - startaddr,
|
|
|
|
PROT_EXEC | PROT_READ | PROT_WRITE);
|
2001-07-05 03:28:40 +00:00
|
|
|
|
|
|
|
if (r < 0)
|
2002-05-21 21:03:46 +00:00
|
|
|
Sys_Error ("Protection change failed");
|
2001-07-05 03:28:40 +00:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
}
|
2001-08-29 17:45:53 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2001-08-29 17:45:53 +00:00
|
|
|
Sys_Init_Cvars (void)
|
|
|
|
{
|
|
|
|
sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL,
|
|
|
|
"Set to disable std out");
|
|
|
|
sys_extrasleep = Cvar_Get ("sys_extrasleep", "0", CVAR_NONE, NULL,
|
|
|
|
"Set to cause whatever amount delay in "
|
|
|
|
"microseconds you want. Mostly "
|
|
|
|
"useful to generate simulated bad "
|
|
|
|
"connections.");
|
2003-01-31 04:51:35 +00:00
|
|
|
sys_dead_sleep = Cvar_Get ("sys_dead_sleep", "0", CVAR_NONE, NULL,
|
2001-08-29 17:45:53 +00:00
|
|
|
"When set, the server gets NO cpu if no "
|
|
|
|
"clients are connected and there's no other "
|
|
|
|
"activity. *MIGHT* cause problems with some "
|
|
|
|
"mods.");
|
|
|
|
sys_sleep = Cvar_Get ("sys_sleep", "8", CVAR_NONE, NULL, "Sleep how long "
|
|
|
|
"in seconds between checking for connections. "
|
|
|
|
"Minimum is 0, maximum is 13");
|
|
|
|
}
|
2001-09-24 21:00:23 +00:00
|
|
|
|
2002-02-27 06:55:21 +00:00
|
|
|
void
|
|
|
|
Sys_Shutdown (void)
|
2001-09-24 21:00:23 +00:00
|
|
|
{
|
2007-03-21 09:33:46 +00:00
|
|
|
shutdown_list_t *t;
|
2001-09-24 21:00:23 +00:00
|
|
|
|
2007-03-21 09:33:46 +00:00
|
|
|
while (shutdown_list) {
|
|
|
|
shutdown_list->func ();
|
|
|
|
t = shutdown_list;
|
|
|
|
shutdown_list = shutdown_list->next;
|
2005-05-05 22:50:09 +00:00
|
|
|
free (t);
|
2001-09-24 21:00:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2001-09-24 21:00:23 +00:00
|
|
|
Sys_Quit (void)
|
|
|
|
{
|
2002-02-27 06:55:21 +00:00
|
|
|
Sys_Shutdown ();
|
2001-09-24 21:00:23 +00:00
|
|
|
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2002-08-07 15:31:56 +00:00
|
|
|
#if defined (HAVE_VA_COPY)
|
|
|
|
# define VA_COPY(a,b) va_copy (a, b)
|
|
|
|
#elif defined (HAVE__VA_COPY)
|
|
|
|
# define VA_COPY(a,b) __va_copy (a, b)
|
|
|
|
#else
|
2003-07-21 19:26:53 +00:00
|
|
|
# define VA_COPY(a,b) memcpy (a, b, sizeof (a))
|
2002-08-07 15:31:56 +00:00
|
|
|
#endif
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2001-09-24 21:00:23 +00:00
|
|
|
Sys_Error (const char *error, ...)
|
|
|
|
{
|
2002-08-07 15:31:56 +00:00
|
|
|
va_list args;
|
|
|
|
#ifdef VA_LIST_IS_ARRAY
|
|
|
|
va_list tmp_args;
|
|
|
|
#endif
|
2001-09-24 21:00:23 +00:00
|
|
|
|
2002-08-07 15:31:56 +00:00
|
|
|
va_start (args, error);
|
2005-10-23 22:00:45 +00:00
|
|
|
#ifdef VA_LIST_IS_ARRAY
|
|
|
|
VA_COPY (tmp_args, args);
|
|
|
|
#endif
|
2002-08-07 15:31:56 +00:00
|
|
|
sys_err_printf_function (error, args);
|
|
|
|
va_end (args);
|
2001-09-24 21:00:23 +00:00
|
|
|
|
2002-02-27 06:55:21 +00:00
|
|
|
Sys_Shutdown ();
|
2001-09-24 21:00:23 +00:00
|
|
|
|
2002-11-14 22:17:25 +00:00
|
|
|
if (sys_err_printf_function != Sys_ErrPrintf) {
|
|
|
|
// print the message again using the default error printer to increase
|
|
|
|
// the chances of the error being seen.
|
2002-08-07 15:31:56 +00:00
|
|
|
#ifdef VA_LIST_IS_ARRAY
|
2002-11-14 22:17:25 +00:00
|
|
|
VA_COPY (args, tmp_args);
|
2002-08-07 15:31:56 +00:00
|
|
|
#endif
|
2002-11-14 22:17:25 +00:00
|
|
|
Sys_ErrPrintf (error, args);
|
|
|
|
}
|
2002-08-07 15:31:56 +00:00
|
|
|
|
2001-09-24 21:00:23 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2001-09-24 21:00:23 +00:00
|
|
|
Sys_RegisterShutdown (void (*func) (void))
|
|
|
|
{
|
|
|
|
shutdown_list_t *p;
|
|
|
|
if (!func)
|
|
|
|
return;
|
|
|
|
p = malloc (sizeof (*p));
|
|
|
|
if (!p)
|
|
|
|
Sys_Error ("Sys_RegisterShutdown: insufficient memory");
|
|
|
|
p->func = func;
|
|
|
|
p->next = shutdown_list;
|
|
|
|
shutdown_list = p;
|
|
|
|
}
|
2001-11-27 04:50:41 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int
|
2001-11-27 04:50:41 +00:00
|
|
|
Sys_TimeID (void) //FIXME I need a new name, one that doesn't make me feel 3 feet thick
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
#ifdef _WIN32
|
|
|
|
val = ((int) (timeGetTime () * 1000) * time (NULL)) & 0xffff;
|
|
|
|
#else
|
|
|
|
val = ((int) (getpid () + getuid () * 1000) * time (NULL)) & 0xffff;
|
|
|
|
#endif
|
|
|
|
return val;
|
|
|
|
}
|
2002-02-19 20:47:45 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2002-02-19 20:47:45 +00:00
|
|
|
Sys_PageIn (void *ptr, int size)
|
|
|
|
{
|
2004-01-20 03:47:27 +00:00
|
|
|
//may or may not be useful in linux #ifdef _WIN32
|
2002-02-19 20:47:45 +00:00
|
|
|
byte *x;
|
|
|
|
int m, n;
|
|
|
|
|
|
|
|
// touch all the memory to make sure it's there. The 16-page skip is to
|
|
|
|
// keep Win 95 from thinking we're trying to page ourselves in (we are
|
|
|
|
// doing that, of course, but there's no reason we shouldn't)
|
|
|
|
x = (byte *) ptr;
|
|
|
|
|
|
|
|
for (n = 0; n < 4; n++) {
|
|
|
|
for (m = 0; m < (size - 16 * 0x1000); m += 4) {
|
|
|
|
sys_checksum += *(int *) &x[m];
|
|
|
|
sys_checksum += *(int *) &x[m + 16 * 0x1000];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//#endif
|
|
|
|
}
|
2002-05-31 22:50:43 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2002-05-31 22:50:43 +00:00
|
|
|
Sys_DebugLog (const char *file, const char *fmt, ...)
|
|
|
|
{
|
2002-08-07 15:31:56 +00:00
|
|
|
va_list args;
|
2002-08-27 22:13:34 +00:00
|
|
|
static dstring_t *data;
|
2002-05-31 22:50:43 +00:00
|
|
|
int fd;
|
2003-03-13 05:41:55 +00:00
|
|
|
|
2002-08-27 22:13:34 +00:00
|
|
|
if (!data)
|
|
|
|
data = dstring_newstr ();
|
|
|
|
|
2002-08-07 15:31:56 +00:00
|
|
|
va_start (args, fmt);
|
|
|
|
dvsprintf (data, fmt, args);
|
|
|
|
va_end (args);
|
2007-01-06 21:31:03 +00:00
|
|
|
if ((fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0644)) >= 0) {
|
|
|
|
if (write (fd, data->str, data->size - 1) != (ssize_t) (data->size - 1))
|
|
|
|
Sys_Printf ("Error writing %s: %s\n", file, strerror(errno));
|
|
|
|
close (fd);
|
|
|
|
}
|
2002-05-31 22:50:43 +00:00
|
|
|
}
|
2002-06-01 03:00:13 +00:00
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE int
|
2005-01-26 01:19:36 +00:00
|
|
|
Sys_CheckInput (int idle, int net_socket)
|
2002-06-01 03:00:13 +00:00
|
|
|
{
|
2002-06-03 19:11:48 +00:00
|
|
|
fd_set fdset;
|
2003-01-16 16:11:28 +00:00
|
|
|
int res;
|
2002-06-03 19:11:48 +00:00
|
|
|
struct timeval _timeout;
|
|
|
|
struct timeval *timeout = 0;
|
2002-06-01 03:00:13 +00:00
|
|
|
|
2002-06-03 19:11:48 +00:00
|
|
|
#ifdef _WIN32
|
2002-06-04 16:17:10 +00:00
|
|
|
int sleep_msec;
|
2002-06-03 19:11:48 +00:00
|
|
|
// Now we want to give some processing time to other applications,
|
|
|
|
// such as qw_client, running on this machine.
|
|
|
|
sleep_msec = sys_sleep->int_val;
|
|
|
|
if (sleep_msec > 0) {
|
|
|
|
if (sleep_msec > 13)
|
|
|
|
sleep_msec = 13;
|
|
|
|
Sleep (sleep_msec);
|
|
|
|
}
|
2002-06-01 03:00:13 +00:00
|
|
|
|
2002-06-03 19:11:48 +00:00
|
|
|
_timeout.tv_sec = 0;
|
2005-05-02 04:09:15 +00:00
|
|
|
_timeout.tv_usec = net_socket < 0 ? 0 : 20;
|
2002-06-03 19:11:48 +00:00
|
|
|
#else
|
|
|
|
_timeout.tv_sec = 0;
|
2005-05-02 04:09:15 +00:00
|
|
|
_timeout.tv_usec = net_socket < 0 ? 0 : 2000;
|
2002-06-03 19:11:48 +00:00
|
|
|
#endif
|
|
|
|
// select on the net socket and stdin
|
|
|
|
// the only reason we have a timeout at all is so that if the last
|
|
|
|
// connected client times out, the message would not otherwise
|
|
|
|
// be printed until the next event.
|
|
|
|
FD_ZERO (&fdset);
|
2004-03-26 02:52:47 +00:00
|
|
|
#ifndef _WIN32
|
2002-06-03 19:11:48 +00:00
|
|
|
if (do_stdin)
|
|
|
|
FD_SET (0, &fdset);
|
2004-03-26 02:52:47 +00:00
|
|
|
#endif
|
2003-04-16 04:07:55 +00:00
|
|
|
if (net_socket >= 0)
|
2005-01-26 01:19:36 +00:00
|
|
|
FD_SET (((unsigned) net_socket), &fdset); // cast needed for windows
|
2002-08-03 01:29:26 +00:00
|
|
|
|
2002-06-03 19:11:48 +00:00
|
|
|
if (!idle || !sys_dead_sleep->int_val)
|
|
|
|
timeout = &_timeout;
|
|
|
|
|
2003-04-16 04:07:55 +00:00
|
|
|
res = select (max (net_socket, 0) + 1, &fdset, NULL, NULL, timeout);
|
2003-01-16 16:11:28 +00:00
|
|
|
if (res == 0 || res == -1)
|
2002-06-03 19:11:48 +00:00
|
|
|
return 0;
|
2004-03-26 02:52:47 +00:00
|
|
|
#ifndef _WIN32
|
2002-06-03 19:11:48 +00:00
|
|
|
stdin_ready = FD_ISSET (0, &fdset);
|
2004-03-26 02:52:47 +00:00
|
|
|
#endif
|
2002-06-03 19:11:48 +00:00
|
|
|
return 1;
|
2002-06-01 03:00:13 +00:00
|
|
|
}
|
|
|
|
|
2002-06-03 19:11:48 +00:00
|
|
|
/*
|
|
|
|
Sys_ConsoleInput
|
2002-06-01 03:00:13 +00:00
|
|
|
|
2002-06-03 19:11:48 +00:00
|
|
|
Checks for a complete line of text typed in at the console, then forwards
|
|
|
|
it to the host command processor
|
|
|
|
*/
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE const char *
|
2002-06-03 19:11:48 +00:00
|
|
|
Sys_ConsoleInput (void)
|
2002-06-01 03:00:13 +00:00
|
|
|
{
|
2002-06-03 19:11:48 +00:00
|
|
|
static char text[256];
|
2004-01-22 03:43:09 +00:00
|
|
|
static int len = 0;
|
2002-06-03 19:11:48 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
int c;
|
|
|
|
|
|
|
|
// read a line out
|
2004-01-22 03:43:09 +00:00
|
|
|
while (_kbhit ()) {
|
2002-06-03 19:11:48 +00:00
|
|
|
c = _getch ();
|
|
|
|
putch (c);
|
|
|
|
if (c == '\r') {
|
|
|
|
text[len] = 0;
|
|
|
|
putch ('\n');
|
|
|
|
len = 0;
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
if (c == 8) {
|
|
|
|
if (len) {
|
|
|
|
putch (' ');
|
|
|
|
putch (c);
|
|
|
|
len--;
|
|
|
|
text[len] = 0;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
text[len] = c;
|
|
|
|
len++;
|
2010-11-21 04:55:03 +00:00
|
|
|
if (len < sizeof (text))
|
|
|
|
text[len] = 0;
|
|
|
|
else {
|
|
|
|
// buffer is full
|
2002-06-03 19:11:48 +00:00
|
|
|
len = 0;
|
2010-11-21 04:55:03 +00:00
|
|
|
text[sizeof (text) - 1] = 0;
|
|
|
|
return text;
|
|
|
|
}
|
2002-06-03 19:11:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
#else
|
|
|
|
if (!stdin_ready || !do_stdin)
|
|
|
|
return NULL; // the select didn't say it was ready
|
|
|
|
stdin_ready = false;
|
|
|
|
|
|
|
|
len = read (0, text, sizeof (text));
|
|
|
|
if (len == 0) {
|
|
|
|
// end of file
|
|
|
|
do_stdin = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (len < 1)
|
|
|
|
return NULL;
|
|
|
|
text[len - 1] = 0; // rip off the \n and terminate
|
|
|
|
|
|
|
|
return text;
|
2002-06-01 03:00:13 +00:00
|
|
|
#endif
|
2002-06-03 19:11:48 +00:00
|
|
|
}
|
2002-08-20 23:04:57 +00:00
|
|
|
|
|
|
|
static jmp_buf aiee_abort;
|
|
|
|
|
|
|
|
typedef struct sh_stack_s {
|
|
|
|
struct sh_stack_s *next;
|
2002-11-13 19:26:44 +00:00
|
|
|
int (*signal_hook)(int,void*);
|
2002-08-20 23:04:57 +00:00
|
|
|
void *data;
|
|
|
|
} sh_stack_t;
|
|
|
|
|
|
|
|
static sh_stack_t *sh_stack;
|
|
|
|
static sh_stack_t *free_sh;
|
2002-11-13 19:26:44 +00:00
|
|
|
static int (*signal_hook)(int,void*);
|
2002-08-20 23:04:57 +00:00
|
|
|
static void *signal_hook_data;
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2002-11-13 19:26:44 +00:00
|
|
|
Sys_PushSignalHook (int (*hook)(int, void *), void *data)
|
2002-08-20 23:04:57 +00:00
|
|
|
{
|
|
|
|
sh_stack_t *s;
|
|
|
|
|
|
|
|
if (free_sh) {
|
|
|
|
s = free_sh;
|
|
|
|
} else {
|
|
|
|
s = malloc (sizeof (sh_stack_t));
|
|
|
|
s->next = 0;
|
|
|
|
}
|
|
|
|
s->signal_hook = signal_hook;
|
|
|
|
s->data = signal_hook_data;
|
|
|
|
signal_hook = hook;
|
|
|
|
signal_hook_data = data;
|
|
|
|
|
|
|
|
free_sh = s->next;
|
|
|
|
s->next = sh_stack;
|
|
|
|
sh_stack = s;
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2002-08-20 23:04:57 +00:00
|
|
|
Sys_PopSignalHook (void)
|
|
|
|
{
|
|
|
|
if (sh_stack) {
|
|
|
|
sh_stack_t *s;
|
|
|
|
|
|
|
|
signal_hook = sh_stack->signal_hook;
|
|
|
|
signal_hook_data = sh_stack->data;
|
|
|
|
|
|
|
|
s = sh_stack->next;
|
|
|
|
sh_stack->next = free_sh;
|
|
|
|
free_sh = sh_stack;
|
|
|
|
sh_stack = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
aiee (int sig)
|
|
|
|
{
|
|
|
|
printf ("AIEE, signal %d in shutdown code, giving up\n", sig);
|
|
|
|
longjmp (aiee_abort, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
signal_handler (int sig)
|
|
|
|
{
|
2002-11-14 15:37:09 +00:00
|
|
|
int volatile recover = 0; // volatile for longjump
|
2002-11-13 19:26:44 +00:00
|
|
|
|
2002-08-20 23:04:57 +00:00
|
|
|
printf ("Received signal %d, exiting...\n", sig);
|
|
|
|
|
|
|
|
switch (sig) {
|
|
|
|
case SIGINT:
|
|
|
|
case SIGTERM:
|
2002-08-21 01:51:27 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
case SIGHUP:
|
2002-08-20 23:04:57 +00:00
|
|
|
signal (SIGHUP, SIG_DFL);
|
2002-08-21 01:51:27 +00:00
|
|
|
#endif
|
2002-08-20 23:04:57 +00:00
|
|
|
signal (SIGINT, SIG_DFL);
|
|
|
|
signal (SIGTERM, SIG_DFL);
|
|
|
|
Sys_Quit ();
|
|
|
|
default:
|
2002-08-21 01:51:27 +00:00
|
|
|
#ifndef _WIN32
|
2002-08-20 23:04:57 +00:00
|
|
|
signal (SIGQUIT, aiee);
|
|
|
|
signal (SIGTRAP, aiee);
|
|
|
|
signal (SIGIOT, aiee);
|
|
|
|
signal (SIGBUS, aiee);
|
2002-08-21 01:51:27 +00:00
|
|
|
#endif
|
|
|
|
signal (SIGILL, aiee);
|
2002-08-20 23:04:57 +00:00
|
|
|
signal (SIGSEGV, aiee);
|
2002-11-13 19:26:44 +00:00
|
|
|
signal (SIGFPE, aiee);
|
2002-08-20 23:04:57 +00:00
|
|
|
|
|
|
|
if (!setjmp (aiee_abort)) {
|
|
|
|
if (signal_hook)
|
2002-11-13 19:26:44 +00:00
|
|
|
recover = signal_hook (sig, signal_hook_data);
|
2002-08-20 23:04:57 +00:00
|
|
|
Sys_Shutdown ();
|
|
|
|
}
|
|
|
|
|
2002-11-13 19:26:44 +00:00
|
|
|
if (recover) {
|
|
|
|
#ifndef _WIN32
|
|
|
|
signal (SIGQUIT, signal_handler);
|
|
|
|
signal (SIGTRAP, signal_handler);
|
|
|
|
signal (SIGIOT, signal_handler);
|
|
|
|
signal (SIGBUS, signal_handler);
|
|
|
|
#endif
|
|
|
|
signal (SIGILL, signal_handler);
|
|
|
|
signal (SIGSEGV, signal_handler);
|
|
|
|
signal (SIGFPE, signal_handler);
|
|
|
|
} else {
|
2002-08-21 01:51:27 +00:00
|
|
|
#ifndef _WIN32
|
2002-11-13 19:26:44 +00:00
|
|
|
signal (SIGQUIT, SIG_DFL);
|
|
|
|
signal (SIGTRAP, SIG_DFL);
|
|
|
|
signal (SIGIOT, SIG_DFL);
|
|
|
|
signal (SIGBUS, SIG_DFL);
|
2002-08-21 01:51:27 +00:00
|
|
|
#endif
|
2002-11-13 19:26:44 +00:00
|
|
|
signal (SIGILL, SIG_DFL);
|
|
|
|
signal (SIGSEGV, SIG_DFL);
|
|
|
|
signal (SIGFPE, SIG_DFL);
|
|
|
|
}
|
2002-08-20 23:04:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE void
|
2002-08-20 23:04:57 +00:00
|
|
|
Sys_Init (void)
|
|
|
|
{
|
|
|
|
// catch signals
|
2002-08-21 01:51:27 +00:00
|
|
|
#ifndef _WIN32
|
2002-08-20 23:04:57 +00:00
|
|
|
signal (SIGHUP, signal_handler);
|
|
|
|
signal (SIGQUIT, signal_handler);
|
|
|
|
signal (SIGTRAP, signal_handler);
|
|
|
|
signal (SIGIOT, signal_handler);
|
|
|
|
signal (SIGBUS, signal_handler);
|
2002-08-21 01:51:27 +00:00
|
|
|
#endif
|
|
|
|
signal (SIGINT, signal_handler);
|
|
|
|
signal (SIGILL, signal_handler);
|
2002-08-20 23:04:57 +00:00
|
|
|
signal (SIGSEGV, signal_handler);
|
|
|
|
signal (SIGTERM, signal_handler);
|
2002-11-13 19:26:44 +00:00
|
|
|
signal (SIGFPE, signal_handler);
|
2002-08-20 23:04:57 +00:00
|
|
|
}
|
2010-08-24 23:21:07 +00:00
|
|
|
|
|
|
|
VISIBLE int
|
|
|
|
Sys_CreatePath (const char *path)
|
|
|
|
{
|
|
|
|
char *ofs;
|
|
|
|
char *e_path = alloca (strlen (path) + 1);
|
|
|
|
|
|
|
|
strcpy (e_path, path);
|
|
|
|
for (ofs = e_path + 1; *ofs; ofs++) {
|
|
|
|
if (*ofs == '/') { // create the directory
|
|
|
|
*ofs = 0;
|
|
|
|
if (Sys_mkdir (e_path) == -1)
|
|
|
|
return -1;
|
|
|
|
*ofs = '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-24 07:01:01 +00:00
|
|
|
|
|
|
|
char *
|
|
|
|
Sys_ExpandSquiggle (const char *path)
|
|
|
|
{
|
|
|
|
char *home;
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
struct passwd *pwd_ent;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (strncmp (path, "~/", 2) != 0) {
|
|
|
|
return strdup (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
// LordHavoc: first check HOME to duplicate previous version behavior
|
|
|
|
// (also handy if someone wants it elsewhere than their windows directory)
|
|
|
|
home = getenv ("HOME");
|
|
|
|
if (!home || !home[0])
|
|
|
|
home = getenv ("WINDIR");
|
|
|
|
#else
|
|
|
|
if ((pwd_ent = getpwuid (getuid ()))) {
|
|
|
|
home = pwd_ent->pw_dir;
|
|
|
|
} else
|
|
|
|
home = getenv ("HOME");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (home)
|
|
|
|
return nva ("%s%s", home, path + 1); // skip leading ~
|
|
|
|
|
|
|
|
return strdup (path);
|
|
|
|
}
|