This commit is contained in:
Yamagi Burmeister 2012-06-08 13:01:56 +02:00
parent 26b15dbe07
commit 87e62a3724
6 changed files with 3713 additions and 3526 deletions

View file

@ -24,7 +24,6 @@
* =======================================================================
*/
/* For mremap() - must be before sys/mman.h include! */
#if defined(__linux__) && !defined(_GNU_SOURCE)
#define _GNU_SOURCE
@ -41,7 +40,6 @@
#define MAP_ANONYMOUS MAP_ANON
#endif
byte *membase;
int maxhunksize;
int curhunksize;
@ -63,7 +61,7 @@ Hunk_Begin ( int maxsize )
*((int *)membase) = curhunksize;
return ( membase + sizeof ( int ) );
return membase + sizeof(int);
}
void *
@ -81,7 +79,7 @@ Hunk_Alloc ( int size )
buf = membase + sizeof(int) + curhunksize;
curhunksize += size;
return ( buf );
return buf;
}
int
@ -108,7 +106,6 @@ Hunk_End ( void )
unmap_len = old_size - new_size;
n = munmap(unmap_base, unmap_len) + membase;
}
#endif
#if defined(__linux__)
@ -122,7 +119,7 @@ Hunk_End ( void )
*((int *)membase) = curhunksize + sizeof(int);
return ( curhunksize );
return curhunksize;
}
void
@ -140,3 +137,4 @@ Hunk_Free ( void *base )
}
}
}

View file

@ -132,3 +132,4 @@ main ( int argc, char **argv )
return 0;
}

View file

@ -91,7 +91,8 @@ NetadrToSockadr ( netadr_t *a, struct sockaddr_storage *s )
if (inet_pton(AF_INET6, QUAKE2MCAST, &s6->sin6_addr.s6_addr) != 1)
{
Com_Printf("NET_NetadrToSockadr: inet_pton: %s\n", strerror(errno));
Com_Printf("NET_NetadrToSockadr: inet_pton: %s\n",
strerror(errno));
return;
}
@ -102,12 +103,13 @@ NetadrToSockadr ( netadr_t *a, struct sockaddr_storage *s )
#endif
/* scope_id is important for
link-local destination.*/
* link-local destination.*/
s6->sin6_scope_id = a->scope_id;
break;
case NA_IP6:
if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)a->ip))
{
#ifdef __FreeBSD__
@ -131,7 +133,7 @@ NetadrToSockadr ( netadr_t *a, struct sockaddr_storage *s )
#endif
/* scope_id is important for
link-local destination. */
* link-local destination. */
s6->sin6_scope_id = a->scope_id;
}
@ -317,7 +319,9 @@ NET_BaseAdrToString(netadr_t a)
#else
socklen_t const salen = sizeof(ss);
#endif
if (getnameinfo((struct sockaddr*)&ss, salen, s, sizeof(s), NULL, 0, NI_NUMERICHOST))
if (getnameinfo((struct sockaddr *)&ss, salen, s, sizeof(s), NULL,
0, NI_NUMERICHOST))
{
Com_sprintf(s, sizeof(s), "<invalid>");
}
@ -325,7 +329,8 @@ NET_BaseAdrToString(netadr_t a)
else
{
if ((a.type == NA_MULTICAST6) ||
IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)&ss)-> sin6_addr))
IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)&ss)->
sin6_addr))
{
/* If the address is multicast (link) or a
link-local, need to carry the scope. The string
@ -406,7 +411,8 @@ NET_StringToSockaddr ( char *s, struct sockaddr_storage *sadr )
if ((err = getaddrinfo(addrs, ports, &hints, &resultp)))
{
/* Error */
Com_Printf("NET_StringToSockaddr: string %s:\n%s\n", s, gai_strerror(err));
Com_Printf("NET_StringToSockaddr: string %s:\n%s\n", s,
gai_strerror(err));
return 0;
}
@ -459,7 +465,7 @@ NET_StringToAdr ( char *s, netadr_t *a )
qboolean
NET_IsLocalAddress(netadr_t adr)
{
return ( NET_CompareAdr( adr, net_local_adr ) );
return NET_CompareAdr(adr, net_local_adr);
}
qboolean
@ -477,7 +483,7 @@ NET_GetLoopPacket ( netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message )
if (loop->get >= loop->send)
{
return ( false );
return false;
}
i = loop->get & (MAX_LOOPBACK - 1);
@ -486,7 +492,7 @@ NET_GetLoopPacket ( netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message )
memcpy(net_message->data, loop->msgs[i].data, loop->msgs[i].datalen);
net_message->cursize = loop->msgs[i].datalen;
*net_from = net_local_adr;
return ( true );
return true;
}
void
@ -668,13 +674,15 @@ NET_SendPacket ( netsrc_t sock, int length, void *data, netadr_t to )
error = getnameinfo((struct sockaddr *)s6, s6->sin6_len, tmp,
sizeof(tmp), NULL, 0, NI_NUMERICHOST);
#else
error = getnameinfo((struct sockaddr *)s6, sizeof(struct sockaddr_in6),
error = getnameinfo((struct sockaddr *)s6,
sizeof(struct sockaddr_in6),
tmp, sizeof(tmp), NULL, 0, NI_NUMERICHOST);
#endif
if (error)
{
Com_Printf("NET_SendPacket: getnameinfo: %s\n", gai_strerror(error));
Com_Printf("NET_SendPacket: getnameinfo: %s\n",
gai_strerror(error));
return;
}
@ -691,7 +699,8 @@ NET_SendPacket ( netsrc_t sock, int length, void *data, netadr_t to )
if (error)
{
Com_Printf("NET_SendPacket: getaddrinfo: %s\n", gai_strerror(error));
Com_Printf("NET_SendPacket: getaddrinfo: %s\n",
gai_strerror(error));
return;
}
@ -707,7 +716,12 @@ NET_SendPacket ( netsrc_t sock, int length, void *data, netadr_t to )
}
}
ret = sendto(net_socket, data, length, 0, (struct sockaddr *)&addr, addr_size);
ret = sendto(net_socket,
data,
length,
0,
(struct sockaddr *)&addr,
addr_size);
if (ret == -1)
{
@ -836,7 +850,8 @@ NET_Socket ( char *net_interface, int port, netsrc_t type, int family )
for (ai = res; ai != NULL; ai = ai->ai_next)
{
if ((newsocket = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) == -1)
if ((newsocket =
socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) == -1)
{
Com_Printf("NET_Socket: socket: %s\n", strerror(errno));
continue;
@ -852,7 +867,8 @@ NET_Socket ( char *net_interface, int port, netsrc_t type, int family )
if (family == AF_INET)
{
/* make it broadcast capable */
if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&i, sizeof(i)) == -1)
if (setsockopt(newsocket, SOL_SOCKET, SO_BROADCAST, (char *)&i,
sizeof(i)) == -1)
{
Com_Printf("ERROR: NET_Socket: setsockopt SO_BROADCAST:%s\n",
NET_ErrorString());
@ -861,7 +877,8 @@ NET_Socket ( char *net_interface, int port, netsrc_t type, int family )
}
/* make it reusable */
if (setsockopt(newsocket, SOL_SOCKET, SO_REUSEADDR, (char *)&i, sizeof(i)) == -1)
if (setsockopt(newsocket, SOL_SOCKET, SO_REUSEADDR, (char *)&i,
sizeof(i)) == -1)
{
Com_Printf("ERROR: NET_Socket: setsockopt SO_REUSEADDR:%s\n",
NET_ErrorString());
@ -895,37 +912,47 @@ NET_Socket ( char *net_interface, int port, netsrc_t type, int family )
break;
case AF_INET6:
/* Multicast outgoing interface is specified for
client and server (+set multicast <ifname>) */
mcast = Cvar_Get("multicast", "NULL", CVAR_NOSET);
multicast_interface = (strcmp(mcast->string, "NULL") ? mcast->string : NULL);
multicast_interface =
(strcmp(mcast->string, "NULL") ? mcast->string : NULL);
if (multicast_interface != NULL)
{
/* multicast_interface is a global variable.
Also used in NET_SendPacket() */
if ((mreq.ipv6mr_interface = if_nametoindex(multicast_interface)) == 0)
if ((mreq.ipv6mr_interface =
if_nametoindex(multicast_interface)) == 0)
{
Com_Printf("NET_Socket: invalid interface: %s\n", multicast_interface);
Com_Printf("NET_Socket: invalid interface: %s\n",
multicast_interface);
}
if (setsockopt(newsocket, IPPROTO_IPV6, IPV6_MULTICAST_IF,
&mreq.ipv6mr_interface, sizeof(mreq.ipv6mr_interface)) < 0)
&mreq.ipv6mr_interface,
sizeof(mreq.ipv6mr_interface)) < 0)
{
Com_Printf("NET_Socket: IPV6_MULTICAST_IF: %s\n", strerror(errno));
Com_Printf("NET_Socket: IPV6_MULTICAST_IF: %s\n",
strerror(errno));
}
/* Join multicast group ONLY if server */
if (type == NS_SERVER)
{
if (inet_pton(AF_INET6, QUAKE2MCAST, &mreq.ipv6mr_multiaddr.s6_addr) != 1)
if (inet_pton(AF_INET6, QUAKE2MCAST,
&mreq.ipv6mr_multiaddr.s6_addr) != 1)
{
Com_Printf("NET_Socket: inet_pton: %s\n", strerror(errno));
Com_Printf("NET_Socket: inet_pton: %s\n",
strerror(errno));
}
if (setsockopt(newsocket, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) < 0)
if (setsockopt(newsocket, IPPROTO_IPV6, IPV6_JOIN_GROUP,
&mreq, sizeof(mreq)) < 0)
{
Com_Printf("NET_Socket: IPV6_JOIN_GROUP: %s\n", strerror(errno));
Com_Printf("NET_Socket: IPV6_JOIN_GROUP: %s\n",
strerror(errno));
}
}
}
@ -948,7 +975,7 @@ NET_ErrorString ( void )
int code;
code = errno;
return ( strerror( code ) );
return strerror(code);
}
/*
@ -962,7 +989,8 @@ NET_Sleep ( int msec )
extern cvar_t *dedicated;
extern qboolean stdin_active;
if ((!ip_sockets[NS_SERVER] && !ip6_sockets[NS_SERVER]) || (dedicated && !dedicated->value))
if ((!ip_sockets[NS_SERVER] &&
!ip6_sockets[NS_SERVER]) || (dedicated && !dedicated->value))
{
return; /* we're not a server, just run full speed */
}
@ -978,5 +1006,7 @@ NET_Sleep ( int msec )
FD_SET(ip6_sockets[NS_SERVER], &fdset); /* IPv6 network socket */
timeout.tv_sec = msec / 1000;
timeout.tv_usec = (msec % 1000) * 1000;
select(MAX(ip_sockets[NS_SERVER], ip6_sockets[NS_SERVER]) + 1, &fdset, NULL, NULL, &timeout);
select(MAX(ip_sockets[NS_SERVER],
ip6_sockets[NS_SERVER]) + 1, &fdset, NULL, NULL, &timeout);
}

File diff suppressed because it is too large Load diff

View file

@ -71,27 +71,27 @@ CompareAttributes ( char *path, char *name, unsigned musthave, unsigned canthave
/* . and .. never match */
if ((strcmp(name, ".") == 0) || (strcmp(name, "..") == 0))
{
return ( false );
return false;
}
return ( true );
return true;
if (stat(fn, &st) == -1)
{
return ( false ); /* shouldn't happen */
return false; /* shouldn't happen */
}
if ((st.st_mode & S_IFDIR) && (canthave & SFF_SUBDIR))
{
return ( false );
return false;
}
if ((musthave & SFF_SUBDIR) && !(st.st_mode & S_IFDIR))
{
return ( false );
return false;
}
return ( true );
return true;
}
void
@ -111,12 +111,12 @@ Sys_Milliseconds ( void )
if (!secbase)
{
secbase = tp.tv_sec;
return ( tp.tv_usec / 1000 );
return tp.tv_usec / 1000;
}
curtime = (tp.tv_sec - secbase) * 1000 + tp.tv_usec / 1000;
return ( curtime );
return curtime;
}
void
@ -135,7 +135,7 @@ Sys_GetCurrentDirectory ( void )
Sys_Error("Couldn't get current working directory");
}
return ( dir );
return dir;
}
char *
@ -168,7 +168,7 @@ Sys_FindFirst ( char *path, unsigned musthave, unsigned canhave )
if ((fdir = opendir(findbase)) == NULL)
{
return ( NULL );
return NULL;
}
while ((d = readdir(fdir)) != NULL)
@ -178,12 +178,12 @@ Sys_FindFirst ( char *path, unsigned musthave, unsigned canhave )
if (CompareAttributes(findbase, d->d_name, musthave, canhave))
{
sprintf(findpath, "%s/%s", findbase, d->d_name);
return ( findpath );
return findpath;
}
}
}
return ( NULL );
return NULL;
}
char *
@ -193,7 +193,7 @@ Sys_FindNext ( unsigned musthave, unsigned canhave )
if (fdir == NULL)
{
return ( NULL );
return NULL;
}
while ((d = readdir(fdir)) != NULL)
@ -203,12 +203,12 @@ Sys_FindNext ( unsigned musthave, unsigned canhave )
if (CompareAttributes(findbase, d->d_name, musthave, canhave))
{
sprintf(findpath, "%s/%s", findbase, d->d_name);
return ( findpath );
return findpath;
}
}
}
return ( NULL );
return NULL;
}
void
@ -329,10 +329,10 @@ Sys_FileTime ( char *path )
if (stat(path, &buf) == -1)
{
return ( -1 );
return -1;
}
return ( buf.st_mtime );
return buf.st_mtime;
}
void
@ -351,12 +351,12 @@ Sys_ConsoleInput ( void )
if (!dedicated || !dedicated->value)
{
return ( NULL );
return NULL;
}
if (!stdin_active)
{
return ( NULL );
return NULL;
}
FD_ZERO(&fdset);
@ -366,7 +366,7 @@ Sys_ConsoleInput ( void )
if ((select(1, &fdset, NULL, NULL, &timeout) == -1) || !FD_ISSET(0, &fdset))
{
return ( NULL );
return NULL;
}
len = read(0, text, sizeof(text));
@ -374,17 +374,17 @@ Sys_ConsoleInput ( void )
if (len == 0) /* eof! */
{
stdin_active = false;
return ( NULL );
return NULL;
}
if (len < 1)
{
return ( NULL );
return NULL;
}
text[len - 1] = 0; /* rip off the /n and terminate */
return ( text );
return text;
}
void
@ -431,7 +431,7 @@ Sys_GetGameAPI ( void *parms )
if (!path)
{
return ( NULL ); /* couldn't find one anywhere */
return NULL; /* couldn't find one anywhere */
}
snprintf(name, MAX_OSPATH, "%s/%s", path, gamename);
@ -471,7 +471,7 @@ Sys_GetGameAPI ( void *parms )
Com_Printf("%s\n", str_p);
return ( NULL );
return NULL;
}
}
@ -480,24 +480,23 @@ Sys_GetGameAPI ( void *parms )
if (!GetGameAPI)
{
Sys_UnloadGame();
return ( NULL );
return NULL;
}
return ( GetGameAPI( parms ) );
return GetGameAPI(parms);
}
void
Sys_SendKeyEvents(void)
{
#ifndef DEDICATED_ONLY
if (IN_Update_fp)
{
IN_Update_fp();
}
#endif
/* grab frame time */
sys_frame_time = Sys_Milliseconds();
}

View file

@ -60,6 +60,7 @@ qboolean reflib_active = 0;
/* INPUT */
void Do_Key_Event(int key, qboolean down);
void (*IN_Update_fp)(void);
void (*IN_KeyboardInit_fp)(Key_Event_fp_t fp);
void (*IN_Close_fp)(void);
@ -160,13 +161,13 @@ VID_GetModeInfo ( int *width, int *height, int mode )
{
if ((mode < 0) || (mode >= VID_NUM_MODES))
{
return ( false );
return false;
}
*width = vid_modes[mode].width;
*height = vid_modes[mode].height;
return ( true );
return true;
}
void
@ -242,13 +243,13 @@ VID_LoadRefresh ( char *name )
if (stat(fn, &st) == -1)
{
Com_Printf("LoadLibrary(\"%s\") failed: %s\n", name, strerror(errno));
return ( false );
return false;
}
if ((reflib_library = dlopen(fn, RTLD_LAZY)) == 0)
{
Com_Printf("LoadLibrary(\"%s\") failed: %s\n", name, dlerror());
return ( false );
return false;
}
Com_Printf("LoadLibrary(\"%s\")\n", fn);
@ -308,7 +309,7 @@ VID_LoadRefresh ( char *name )
{
re.Shutdown();
VID_FreeReflib();
return ( false );
return false;
}
/* Init IN */
@ -324,7 +325,7 @@ VID_LoadRefresh ( char *name )
Com_Printf("------------------------------------\n\n");
reflib_active = true;
return ( true );
return true;
}
/*
@ -362,7 +363,6 @@ VID_CheckChanges ( void )
}
}
void
VID_Init(void)
{
@ -422,11 +422,11 @@ VID_CheckRefExists ( const char *ref )
if (stat(fn, &st) == 0)
{
return ( true );
return true;
}
else
{
return ( false );
return false;
}
}
@ -463,3 +463,4 @@ Do_Key_Event ( int key, qboolean down )
{
Key_Event(key, down, Sys_Milliseconds());
}