summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/core.c1
-rw-r--r--src/common/db.c6
-rw-r--r--src/common/grfio.c68
-rw-r--r--src/common/grfio.h4
-rw-r--r--src/common/malloc.c23
-rw-r--r--src/common/malloc.h20
-rw-r--r--src/common/mmo.h32
-rw-r--r--src/common/showmsg.c5
-rw-r--r--src/common/socket.c64
-rw-r--r--src/common/socket.h3
-rw-r--r--src/common/strlib.c22
-rw-r--r--src/common/strlib.h6
-rw-r--r--src/common/timer.c10
-rw-r--r--src/common/utils.c9
-rw-r--r--src/common/utils.h6
15 files changed, 168 insertions, 111 deletions
diff --git a/src/common/core.c b/src/common/core.c
index 493aab850..a8c922fc3 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -9,6 +9,7 @@
#include <signal.h>
#include <string.h>
+#include "../common/mmo.h"
#include "core.h"
#include "socket.h"
#include "timer.h"
diff --git a/src/common/db.c b/src/common/db.c
index bc4e8451b..d76b7a44c 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -424,7 +424,7 @@ void* db_erase(struct dbt *table,void* key)
#ifdef MALLOC_DBN
free_dbn(p);
#else
- free(p);
+ aFree(p);
#endif
return data;
}
@@ -497,11 +497,11 @@ void db_final(struct dbt *table,int (*func)(void*,void*,va_list),...)
#ifdef MALLOC_DBN
free_dbn(p);
#else
- free(p);
+ aFree(p);
#endif
p=pn;
}
}
- free(table);
+ aFree(table);
va_end(ap);
}
diff --git a/src/common/grfio.c b/src/common/grfio.c
index 440c3b2a3..6afd1d668 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -25,8 +25,6 @@
#include <ctype.h>
#include <sys/stat.h>
-#include <zlib.h>
-
#include "utils.h"
#include "grfio.h"
#include "mmo.h"
@@ -284,7 +282,7 @@ static void decode_des_etc(BYTE *buf,int len,int type,int cycle)
* Grf data decode sub : zip
*------------------------------------------
*/
-int decode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen)
+int decode_zip(char *dest, unsigned long* destLen, const char* source, unsigned long sourceLen)
{
z_stream stream;
int err;
@@ -301,21 +299,21 @@ int decode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char*
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
- err = inflateInit(&stream);
+ err = zlib_inflateInit(&stream);
if (err != Z_OK) return err;
- err = inflate(&stream, Z_FINISH);
+ err = zlib_inflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
- inflateEnd(&stream);
+ zlib_inflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err;
}
*destLen = stream.total_out;
- err = inflateEnd(&stream);
+ err = zlib_inflateEnd(&stream);
return err;
}
-int encode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen) {
+int encode_zip(char *dest, unsigned long* destLen, const char* source, unsigned long sourceLen) {
z_stream stream;
int err;
@@ -513,14 +511,14 @@ int grfio_size(char *fname)
char lfname[256],*rname,*p;
FILELIST lentry;
struct stat st;
-
+
if(strcmp(data_dir, "") != 0 && (rname=grfio_resnametable(fname,lfname))!=NULL) {
//printf("%s\t",fname);
//sprintf(rname,"%s",grfio_resnametable(fname,lfname));
//printf("%s\n",rname);
sprintf(lfname,"%s%s",data_dir,rname);
//printf("%s\n",lfname);
- }
+ }
for(p=&lfname[0];*p!=0;p++) if (*p=='\\') *p = '/'; // * At the time of Unix
@@ -557,7 +555,7 @@ void* grfio_reads(char *fname, int *size)
strncpy(lfname,fname,255);
// i hope this is the correct way =p [celest]
- if ((rname=grfio_resnametable(fname,lfname))!=NULL) {
+ if ((rname=grfio_resnametable(fname,lfname))!=NULL) {
char tbuf[255];
//sprintf(rname,"%s",grfio_resnametable(fname,lfname));
sprintf(tbuf,"%s%s",data_dir,rname);
@@ -576,7 +574,7 @@ void* grfio_reads(char *fname, int *size)
lentry.declen = ftell(in);
}
fseek(in,0,0); // SEEK_SET
- buf2 = (unsigned char *) aCalloc(lentry.declen+1024, 1);
+ buf2 = (unsigned char *) aCallocA(lentry.declen+1024, 1);
if (buf2==NULL) {
printf("file read memory allocate error : declen\n");
goto errret;
@@ -592,13 +590,13 @@ void* grfio_reads(char *fname, int *size)
} else {
printf("%s not found (grfio_reads)\n", fname);
//goto errret;
- free(buf2);
+ aFree(buf2);
return NULL;
}
}
}
if (entry!=NULL && entry->gentry>0) { // Archive[GRF] File Read
- buf = (unsigned char *) aCalloc(entry->srclen_aligned+1024, 1);
+ buf = (unsigned char *) aCallocA(entry->srclen_aligned+1024, 1);
if (buf==NULL) {
printf("file read memory allocate error : srclen_aligned\n");
goto errret;
@@ -608,13 +606,13 @@ void* grfio_reads(char *fname, int *size)
if(in==NULL) {
printf("%s not found (grfio_reads)\n",gfname);
//goto errret;
- free(buf);
+ aFree(buf);
return NULL;
}
fseek(in,entry->srcpos,0);
fread(buf,1,entry->srclen_aligned,in);
fclose(in);
- buf2 = (unsigned char *) aCalloc(entry->declen+1024, 1);
+ buf2 = (unsigned char *) aCallocA(entry->declen+1024, 1);
if (buf2==NULL) {
printf("file decode memory allocate error\n");
goto errret;
@@ -633,14 +631,14 @@ void* grfio_reads(char *fname, int *size)
} else {
memcpy(buf2,buf,entry->declen);
}
- free(buf);
+ aFree(buf);
}
if (size!=NULL && entry!=NULL)
*size = entry->declen;
return buf2;
errret:
- if (buf!=NULL) free(buf);
- if (buf2!=NULL) free(buf2);
+ if (buf!=NULL) aFree(buf);
+ if (buf2!=NULL) aFree(buf2);
if (in!=NULL) fclose(in);
return NULL;
}
@@ -704,7 +702,7 @@ static int grfio_entryread(char *gfname,int gentry)
if (grf_version==0x01) { //****** Grf version 01xx ******
list_size = grf_size-ftell(fp);
- grf_filelist = (unsigned char *) aCalloc(list_size, 1);
+ grf_filelist = (unsigned char *) aCallocA(list_size, 1);
if(grf_filelist==NULL){
fclose(fp);
printf("out of memory : grf_filelist\n");
@@ -727,7 +725,7 @@ static int grfio_entryread(char *gfname,int gentry)
fname = decode_filename(grf_filelist+ofs+6,grf_filelist[ofs]-6);
if(strlen((const char *) fname)>sizeof(aentry.fn)-1){
printf("file name too long : %s\n",fname);
- free(grf_filelist);
+ aFree(grf_filelist);
exit(1);
}
srclen=0;
@@ -762,7 +760,7 @@ static int grfio_entryread(char *gfname,int gentry)
}
ofs = ofs2 + 17;
}
- free(grf_filelist);
+ aFree(grf_filelist);
} else if (grf_version==0x02) { //****** Grf version 02xx ******
unsigned char eheader[8];
@@ -779,15 +777,15 @@ static int grfio_entryread(char *gfname,int gentry)
return 4;
}
- rBuf = (unsigned char *) aCalloc( rSize , 1); // Get a Read Size
+ rBuf = (unsigned char *) aCallocA( rSize , 1); // Get a Read Size
if (rBuf==NULL) {
fclose(fp);
printf("out of memory : grf compress entry table buffer\n");
return 3;
}
- grf_filelist = (unsigned char *) aCalloc( eSize , 1); // Get a Extend Size
+ grf_filelist = (unsigned char *) aCallocA( eSize , 1); // Get a Extend Size
if (grf_filelist==NULL) {
- free(rBuf);
+ aFree(rBuf);
fclose(fp);
printf("out of memory : grf extract entry table buffer\n");
return 3;
@@ -796,7 +794,7 @@ static int grfio_entryread(char *gfname,int gentry)
fclose(fp);
decode_zip(grf_filelist,&eSize,rBuf,rSize); // Decode function
list_size = eSize;
- free(rBuf);
+ aFree(rBuf);
entrys = getlong(grf_header+0x26) - 7;
@@ -808,7 +806,7 @@ static int grfio_entryread(char *gfname,int gentry)
fname = grf_filelist+ofs;
if (strlen((const char *) fname)>sizeof(aentry.fn)-1) {
printf("grf : file name too long : %s\n",fname);
- free(grf_filelist);
+ aFree(grf_filelist);
exit(1);
}
ofs2 = ofs+strlen(grf_filelist+ofs)+1;
@@ -839,7 +837,7 @@ static int grfio_entryread(char *gfname,int gentry)
}
ofs = ofs2 + 17;
}
- free(grf_filelist);
+ aFree(grf_filelist);
} else { //****** Grf Other version ******
fclose(fp);
@@ -859,11 +857,11 @@ static int grfio_entryread(char *gfname,int gentry)
static void grfio_resourcecheck()
{
int size;
- unsigned char *buf,*ptr;
+ char *buf,*ptr;
char w1[256],w2[256],src[256],dst[256];
FILELIST *entry;
- buf=grfio_reads("data\\resnametable.txt",&size);
+ buf = (char*)grfio_reads("data\\resnametable.txt",&size);
buf[size] = 0;
for(ptr=buf;ptr-buf<size;) {
@@ -889,7 +887,7 @@ static void grfio_resourcecheck()
if (!ptr) break;
ptr++;
}
- free(buf);
+ aFree(buf);
filelist_adjust(); // Unnecessary area release of filelist
}
@@ -927,7 +925,7 @@ int grfio_add(char *fname)
}
}
len = strlen( fname );
- buf = aCalloc(len+1, 1);
+ buf = (char*)aCallocA(len+1, 1);
if (buf==NULL) {
printf("out of memory : gentry\n");
exit(1);
@@ -953,17 +951,17 @@ void grfio_final(void)
{
int lop;
- if (filelist!=NULL) free(filelist);
+ if (filelist!=NULL) aFree(filelist);
filelist = NULL;
filelist_entrys = filelist_maxentry = 0;
if (gentry_table!=NULL) {
for(lop=0;lop<gentry_entrys;lop++) {
if (gentry_table[lop]!=NULL) {
- free(gentry_table[lop]);
+ aFree(gentry_table[lop]);
}
}
- free(gentry_table);
+ aFree(gentry_table);
}
gentry_table = NULL;
gentry_entrys = gentry_maxentry = 0;
diff --git a/src/common/grfio.h b/src/common/grfio.h
index 3fa257e2f..f39e9af1b 100644
--- a/src/common/grfio.h
+++ b/src/common/grfio.h
@@ -8,8 +8,8 @@ void* grfio_read(char*); // GRFIO data file read
void* grfio_reads(char*,int*); // GRFIO data file read & size get
int grfio_size(char*); // GRFIO data file size get
-int decode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen);
-int encode_zip(unsigned char *dest, unsigned long* destLen, const unsigned char* source, unsigned long sourceLen);
+int decode_zip(char *dest, unsigned long* destLen, const char* source, unsigned long sourceLen);
+int encode_zip(char *dest, unsigned long* destLen, const char* source, unsigned long sourceLen);
// Accessor to GRF filenames
char *grfio_setdatafile(const char *str);
diff --git a/src/common/malloc.c b/src/common/malloc.c
index ed5fb2e44..a00399a0e 100644
--- a/src/common/malloc.c
+++ b/src/common/malloc.c
@@ -1,9 +1,10 @@
-#if !defined(DMALLOC) && !defined(GCOLLECT) && !defined(BCHECK)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "malloc.h"
+#if !defined(DMALLOC) && !defined(GCOLLECT) && !defined(BCHECK)
+
void* aMalloc_( size_t size, const char *file, int line, const char *func )
{
void *ret;
@@ -45,9 +46,27 @@ void* aRealloc_( void *p, size_t size, const char *file, int line, const char *f
return ret;
}
+#endif
+
+
+#if defined(GCOLLECT)
+
+void * _bcallocA(size_t size, size_t cnt) {
+ void *ret = aMallocA(size * cnt);
+ memset(ret, 0, size * cnt);
+ return ret;
+}
+
void * _bcalloc(size_t size, size_t cnt) {
- void *ret = malloc(size * cnt);
+ void *ret = aMalloc(size * cnt);
memset(ret, 0, size * cnt);
return ret;
}
#endif
+
+char * _bstrdup(const char *chr) {
+ int len = strlen(chr);
+ char *ret = aMalloc(len + 1);
+ strcpy(ret, chr);
+ return ret;
+}
diff --git a/src/common/malloc.h b/src/common/malloc.h
index 860f8dd7b..b37c3b799 100644
--- a/src/common/malloc.h
+++ b/src/common/malloc.h
@@ -9,23 +9,39 @@
#define aMalloc(size) \
dmalloc_malloc(__FILE__, __LINE__, (size), DMALLOC_FUNC_MALLOC, 0, 0)
+#define aMallocA(size) \
+ dmalloc_malloc(__FILE__, __LINE__, (size), DMALLOC_FUNC_MALLOC, 0, 0)
+#define aCallocA(count,size) \
+ dmalloc_malloc(__FILE__, __LINE__, (count)*(size), DMALLOC_FUNC_CALLOC, 0, 0)
#define aCalloc(count,size) \
dmalloc_malloc(__FILE__, __LINE__, (count)*(size), DMALLOC_FUNC_CALLOC, 0, 0)
#define aRealloc(ptr,size) \
dmalloc_realloc(__FILE__, __LINE__, (ptr), (size), DMALLOC_FUNC_REALLOC, 0)
+#define aFree(ptr) free(ptr)
+#define aStrdup(ptr) strdup(ptr)
#elif defined(GCOLLECT)
#include "gc.h"
#define aMalloc(n) GC_MALLOC(n)
+#define aMallocA(n) GC_MALLOC_ATOMIC(n)
+#define aCallocA(m,n) _bcallocA(m,n)
#define aCalloc(m,n) _bcalloc(m,n)
#define aRealloc(p,n) GC_REALLOC(p,n)
+#define aFree(n) GC_FREE(n)
+#define aStrdup(n) _bstrdup(n)
extern void * _bcalloc(size_t, size_t);
+extern void * _bcallocA(size_t, size_t);
+extern char * _bstrdup(const char *);
#elif defined(BCHECK)
#define aMalloc(n) malloc(n)
+#define aMallocA(n) malloc(n)
#define aCalloc(m,n) calloc(m,n)
+#define aCallocA(m,n) calloc(m,n)
#define aRealloc(p,n) realloc(p,n)
+#define aFree(n) free(n)
+#define aStrdup(n) strdup(n)
#else
#if __STDC_VERSION__ < 199901L
@@ -43,8 +59,12 @@ void* aCalloc_( size_t num, size_t size, const char *file, int line, const char
void* aRealloc_( void *p, size_t size, const char *file, int line, const char *func );
#define aMalloc(n) aMalloc_(n,ALC_MARK)
+#define aMallocA(n) aMalloc_(n,ALC_MARK)
#define aCalloc(m,n) aCalloc_(m,n,ALC_MARK)
+#define aCallocA(m,n) aCalloc_(m,n,ALC_MARK)
#define aRealloc(p,n) aRealloc_(p,n,ALC_MARK)
+#define aFree(ptr) free(ptr)
+#define aStrdup(ptr) strdup(ptr)
#endif
diff --git a/src/common/mmo.h b/src/common/mmo.h
index 41598509e..a8722e53e 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -326,19 +326,25 @@ enum {
GD_DEVELOPMENT=10014,
};
-#ifndef _WIN32
-#ifndef strcmpi
-#define strcmpi strcasecmp
-#endif
-#ifndef stricmp
-#define stricmp strcasecmp
-#endif
-#ifndef strncmpi
-#define strncmpi strncasecmp
-#endif
-#ifndef strnicmp
-#define strnicmp strncasecmp
-#endif
+#ifndef __WIN32
+ #ifndef strcmpi
+ #define strcmpi strcasecmp
+ #endif
+ #ifndef stricmp
+ #define stricmp strcasecmp
+ #endif
+ #ifndef strncmpi
+ #define strncmpi strncasecmp
+ #endif
+ #ifndef strnicmp
+ #define strnicmp strncasecmp
+ #endif
+#else
+ #define snprintf _snprintf
+ #define vsnprintf _vsnprintf
+ #ifndef strncmpi
+ #define strncmpi strnicmp
+ #endif
#endif
#endif // _MMO_H_
diff --git a/src/common/showmsg.c b/src/common/showmsg.c
index 857a819bb..ddaae3a52 100644
--- a/src/common/showmsg.c
+++ b/src/common/showmsg.c
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include "showmsg.h"
+#include "malloc.h"
char tmp_output[1024] = {"\0"};
@@ -47,7 +48,7 @@ int _ShowMessage(const char *string, enum msg_type flag){ // by MC Cameri
return 1;
}
if (!(flag == MSG_DEBUG && !SHOW_DEBUG_MSG)) {
- output = (char*)malloc(sizeof(char)*(strlen(prefix)+strlen(string)+2)); // prefix+string+two chars(space and \0)
+ output = (char*)aMalloc(sizeof(char)*(strlen(prefix)+strlen(string)+2)); // prefix+string+two chars(space and \0)
if (output == NULL) {
return 1;
// exit(1); // Kill server? Deadly
@@ -58,7 +59,7 @@ int _ShowMessage(const char *string, enum msg_type flag){ // by MC Cameri
strcat(output,string);
printf(output);
fflush(stdout);
- free(output);
+ aFree(output);
}
/*
if ((core_config.debug_output_level > -1) && (flag >= core_config.debug_output_level)) {
diff --git a/src/common/socket.c b/src/common/socket.c
index 764d4d821..72e7e3f22 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -3,11 +3,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
+#include <errno.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
+#include <io.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
@@ -16,7 +18,6 @@
#include <sys/time.h>
#include <unistd.h>
#include <sys/ioctl.h>
-#include <errno.h>
#ifndef SIOCGIFCONF
#include <sys/sockio.h> // SIOCGIFCONF on Solaris, maybe others? [Shinomori]
@@ -151,11 +152,11 @@ static int send_from_fifo(int fd)
return 0;
}
-void flush_fifos()
+void flush_fifos()
{
int i;
for(i=0;i<fd_max;i++)
- if(session[i] != NULL &&
+ if(session[i] != NULL &&
session[i]->func_send == send_from_fifo)
send_from_fifo(i);
}
@@ -177,20 +178,22 @@ static int connect_client(int listen_fd)
int fd;
struct sockaddr_in client_address;
int len;
+#ifndef _WIN32
int result;
+#endif
//printf("connect_client : %d\n",listen_fd);
len=sizeof(client_address);
- fd=accept(listen_fd,(struct sockaddr*)&client_address,&len);
+ fd = accept(listen_fd,(struct sockaddr*)&client_address,(socklen_t*)&len);
if(fd_max<=fd) fd_max=fd+1;
setsocketopts(fd);
if(fd==-1)
perror("accept");
- else
+ else
FD_SET(fd,&readfds);
#ifdef _WIN32
@@ -203,8 +206,8 @@ static int connect_client(int listen_fd)
#endif
CREATE(session[fd], struct socket_data, 1);
- CREATE(session[fd]->rdata, unsigned char, rfifo_size);
- CREATE(session[fd]->wdata, unsigned char, wfifo_size);
+ CREATE_A(session[fd]->rdata, unsigned char, rfifo_size);
+ CREATE_A(session[fd]->wdata, unsigned char, wfifo_size);
session[fd]->max_rdata = rfifo_size;
session[fd]->max_wdata = wfifo_size;
@@ -240,7 +243,7 @@ int make_listen_port(int port)
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = htonl( INADDR_ANY );
- server_address.sin_port = htons(port);
+ server_address.sin_port = htons((unsigned short)port);
result = bind(fd, (struct sockaddr*)&server_address, sizeof(server_address));
if( result == -1 ) {
@@ -271,12 +274,13 @@ int make_listen_port(int port)
int console_recieve(int i) {
int n;
char *buf;
-
- CREATE(buf, char , 64);
-
+
+ CREATE_A(buf, char , 64);
+
memset(buf,0,sizeof(64));
n = read(0, buf , 64);
+
if ( n < 0 )
printf("Console input read error\n");
else
@@ -298,21 +302,21 @@ static int null_console_parse(char *buf)
// Console Input [Wizputer]
int start_console(void) {
FD_SET(0,&readfds);
-
+
CREATE(session[0], struct socket_data, 1);
if(session[0]==NULL){
printf("out of memory : start_console\n");
exit(1);
}
-
+
memset(session[0],0,sizeof(*session[0]));
-
+
session[0]->func_recv = console_recieve;
session[0]->func_console = default_console_parse;
-
+
return 0;
-}
-
+}
+
int make_connection(long ip,int port)
{
struct sockaddr_in server_address;
@@ -320,14 +324,14 @@ int make_connection(long ip,int port)
int result;
fd = socket( AF_INET, SOCK_STREAM, 0 );
- if(fd_max<=fd)
+ if(fd_max<=fd)
fd_max=fd+1;
setsocketopts(fd);
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = ip;
- server_address.sin_port = htons(port);
+ server_address.sin_port = htons((unsigned short)port);
#ifdef _WIN32
{
@@ -343,8 +347,8 @@ int make_connection(long ip,int port)
FD_SET(fd,&readfds);
CREATE(session[fd], struct socket_data, 1);
- CREATE(session[fd]->rdata, unsigned char, rfifo_size);
- CREATE(session[fd]->wdata, unsigned char, wfifo_size);
+ CREATE_A(session[fd]->rdata, unsigned char, rfifo_size);
+ CREATE_A(session[fd]->wdata, unsigned char, wfifo_size);
session[fd]->max_rdata = rfifo_size;
session[fd]->max_wdata = wfifo_size;
@@ -363,12 +367,12 @@ int delete_session(int fd)
FD_CLR(fd,&readfds);
if(session[fd]){
if(session[fd]->rdata)
- free(session[fd]->rdata);
+ aFree(session[fd]->rdata);
if(session[fd]->wdata)
- free(session[fd]->wdata);
+ aFree(session[fd]->wdata);
if(session[fd]->session_data)
- free(session[fd]->session_data);
- free(session[fd]);
+ aFree(session[fd]->session_data);
+ aFree(session[fd]);
}
session[fd]=NULL;
//printf("delete_session:%d\n",fd);
@@ -401,7 +405,7 @@ int WFIFOSET(int fd,int len)
}
s->wdata_size=(s->wdata_size+(len)+2048 < s->max_wdata) ?
s->wdata_size+len : (printf("socket: %d wdata lost !!\n",fd),s->wdata_size);
- if (s->wdata_size > (TCP_FRAME_LEN))
+ if (s->wdata_size > (TCP_FRAME_LEN))
send_from_fifo(fd);
return 0;
}
@@ -456,7 +460,7 @@ int do_parsepacket(void)
for(i=0;i<fd_max;i++){
if(!session[i])
continue;
- if ((session[i]->rdata_tick != 0) && ((tick_ - session[i]->rdata_tick) > stall_time_))
+ if ((session[i]->rdata_tick != 0) && ((tick_ - session[i]->rdata_tick) > stall_time_))
session[i]->eof = 1;
if(session[i]->rdata_size==0 && session[i]->eof==0)
continue;
@@ -500,7 +504,7 @@ int Net_Init(void)
unsigned int i;
char fullhost[255];
struct hostent* hent;
-
+
/* Start up the windows networking */
WSADATA wsaData;
@@ -512,7 +516,7 @@ int Net_Init(void)
if(gethostname(fullhost, sizeof(fullhost)) == SOCKET_ERROR) {
printf("Ugg.. no hostname defined!\n");
return 0;
- }
+ }
// XXX This should look up the local IP addresses in the registry
// instead of calling gethostbyname. However, the way IP addresses
@@ -545,7 +549,7 @@ int Net_Init(void)
return 0;
}
- for(pos = 0; pos < ic.ifc_len;)
+ for(pos = 0; pos < ic.ifc_len;)
{
struct ifreq * ir = (struct ifreq *) (ic.ifc_buf + pos);
diff --git a/src/common/socket.h b/src/common/socket.h
index 172712d26..68b204862 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -5,8 +5,9 @@
#include <stdio.h>
-#ifdef _WIN32
+#ifdef __WIN32
#include <winsock.h>
+#define close(fd) closesocket(fd)
#else
#include <sys/types.h>
#include <sys/socket.h>
diff --git a/src/common/strlib.c b/src/common/strlib.c
index 9114c3d03..ca6e38761 100644
--- a/src/common/strlib.c
+++ b/src/common/strlib.c
@@ -8,15 +8,15 @@
//-----------------------------------------------
// string lib.
-unsigned char* jstrescape (unsigned char* pt) {
+char* jstrescape (char* pt) {
//copy from here
unsigned char * ptr;
int i =0, j=0;
-
+
//copy string to temporary
- CREATE(ptr, char, J_MAX_MALLOC_SIZE);
+ CREATE_A(ptr, char, J_MAX_MALLOC_SIZE);
strcpy (ptr,pt);
-
+
while (ptr[i] != '\0') {
switch (ptr[i]) {
case '\'':
@@ -32,14 +32,14 @@ unsigned char* jstrescape (unsigned char* pt) {
}
}
pt[j++] = '\0';
- free (ptr);
- return (unsigned char*) &pt[0];
+ aFree (ptr);
+ return &pt[0];
}
-unsigned char* jstrescapecpy (unsigned char* pt,unsigned char* spt) {
+char* jstrescapecpy (char* pt,char* spt) {
//copy from here
int i =0, j=0;
-
+
while (spt[i] != '\0') {
switch (spt[i]) {
case '\'':
@@ -55,12 +55,12 @@ unsigned char* jstrescapecpy (unsigned char* pt,unsigned char* spt) {
}
}
pt[j++] = '\0';
- return (unsigned char*) &pt[0];
+ return &pt[0];
}
-int jmemescapecpy (unsigned char* pt,unsigned char* spt, int size) {
+int jmemescapecpy (char* pt,char* spt, int size) {
//copy from here
int i =0, j=0;
-
+
while (i < size) {
switch (spt[i]) {
case '\'':
diff --git a/src/common/strlib.h b/src/common/strlib.h
index 6b6169083..54c52cf94 100644
--- a/src/common/strlib.h
+++ b/src/common/strlib.h
@@ -4,7 +4,7 @@
// String function library.
// code by Jioh L. Jung (ziozzang@4wish.net)
// This code is under license "BSD"
-unsigned char* jstrescape (unsigned char* pt);
-unsigned char* jstrescapecpy (unsigned char* pt,unsigned char* spt);
-int jmemescapecpy (unsigned char* pt,unsigned char* spt, int size);
+char* jstrescape (char* pt);
+char* jstrescapecpy (char* pt,char* spt);
+int jmemescapecpy (char* pt,char* spt, int size);
#endif
diff --git a/src/common/timer.c b/src/common/timer.c
index 4c602b51e..8b52811b8 100644
--- a/src/common/timer.c
+++ b/src/common/timer.c
@@ -262,7 +262,7 @@ int add_timer(unsigned int tick,int (*func)(int,unsigned int,int,int),int id,int
int j;
if (timer_data_max == 0) {
timer_data_max = 256;
- CREATE(timer_data, struct TimerData, timer_data_max);
+ CREATE_A(timer_data, struct TimerData, timer_data_max);
//timer_data[0] = NULL;
} else {
timer_data_max += 256;
@@ -403,13 +403,13 @@ void timer_final(void)
for(tfl = tfl_root; tfl; tfl = tfl_next)
{
tfl_next = tfl->next;
- free(tfl);
+ aFree(tfl);
tfl = NULL;
}
if(timer_heap)
- free(timer_heap);
+ aFree(timer_heap);
if(free_timer_list)
- free(free_timer_list);
+ aFree(free_timer_list);
if(timer_data)
- free(timer_data);
+ aFree(timer_data);
}
diff --git a/src/common/utils.c b/src/common/utils.c
index 9a7722478..732b1d366 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -4,6 +4,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include "malloc.h"
+#include "mmo.h"
void dump(unsigned char *buffer, int num)
{
@@ -112,7 +113,7 @@ void str_lower(char *name)
// Allocate a StringBuf [MouseJstr]
struct StringBuf * StringBuf_Malloc()
{
- struct StringBuf * ret = (struct StringBuf *) malloc(sizeof(struct StringBuf));
+ struct StringBuf * ret = (struct StringBuf *) aMallocA(sizeof(struct StringBuf));
StringBuf_Init(ret);
return ret;
}
@@ -120,7 +121,7 @@ struct StringBuf * StringBuf_Malloc()
// Initialize a previously allocated StringBuf [MouseJstr]
void StringBuf_Init(struct StringBuf * sbuf) {
sbuf->max_ = 1024;
- sbuf->ptr_ = sbuf->buf_ = (char *) malloc(sbuf->max_ + 1);
+ sbuf->ptr_ = sbuf->buf_ = (char *) aMallocA(sbuf->max_ + 1);
}
// printf into a StringBuf, moving the pointer [MouseJstr]
@@ -169,7 +170,7 @@ int StringBuf_Append(struct StringBuf *buf1,const struct StringBuf *buf2)
// Destroy a StringBuf [MouseJstr]
void StringBuf_Destroy(struct StringBuf *sbuf)
{
- free(sbuf->buf_);
+ aFree(sbuf->buf_);
sbuf->ptr_ = sbuf->buf_ = 0;
}
@@ -177,7 +178,7 @@ void StringBuf_Destroy(struct StringBuf *sbuf)
void StringBuf_Free(struct StringBuf *sbuf)
{
StringBuf_Destroy(sbuf);
- free(sbuf);
+ aFree(sbuf);
}
// Return the built string from the StringBuf [MouseJstr]
diff --git a/src/common/utils.h b/src/common/utils.h
index 0ac880a50..63c3f21ec 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -30,6 +30,12 @@
if (!((result) = (type *) aCalloc ((number), sizeof(type)))) \
{ perror("SYSERR: malloc failure"); abort(); } } while(0)
+#define CREATE_A(result, type, number) do {\
+ if ((number) * sizeof(type) <= 0) \
+ printf("SYSERR: Zero bytes or less requested at %s:%d.\n", __FILE__, __LINE__); \
+ if (!((result) = (type *) aCallocA ((number), sizeof(type)))) \
+ { perror("SYSERR: malloc failure"); abort(); } } while(0)
+
#define RECREATE(result,type,number) do {\
if (!((result) = (type *) aRealloc ((result), sizeof(type) * (number))))\
{ printf("SYSERR: realloc failure"); abort(); } } while(0)