Remove non-standard arithmetic on void *, and get offsetof() from <stddef.h> instead

of rolling our own.

Fixes building on Irix.


git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@110 13b04d17-f746-0410-82c6-800466cd88b0
This commit is contained in:
Kevin Easton
2011-02-02 12:34:13 +00:00
parent b43ecbaa85
commit 3aa7f7765f
2 changed files with 14 additions and 16 deletions

View File

@@ -22,6 +22,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h>
/* /*
* Everybody needs these POSIX headers... * Everybody needs these POSIX headers...

View File

@@ -15,10 +15,6 @@ CVS_REVISION(struct_c)
#define MAIN_SOURCE #define MAIN_SOURCE
#include "modval.h" #include "modval.h"
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
extern char *after_expando(char *, int, int *); extern char *after_expando(char *, int, int *);
/* the types of IrcVariables (repeated in vars.h) */ /* the types of IrcVariables (repeated in vars.h) */
@@ -422,40 +418,40 @@ int setup_structure(char *name, char *which, Window **win, DCC_int **dcc, Channe
static inline int get_offset_int(void *tmp, int offset) static inline int get_offset_int(void *tmp, int offset)
{ {
int val = *(int *)((void *)tmp + offset); int val = *(int *)((char *)tmp + offset);
return val; return val;
} }
static inline char *get_offset_str(void *tmp, int offset) static inline char *get_offset_str(void *tmp, int offset)
{ {
char *s = *(char **) ((void *)tmp + offset); char *s = *(char **)((char *)tmp + offset);
return s; return s;
} }
static inline char *get_offset_char(void *tmp, int offset) static inline char *get_offset_char(void *tmp, int offset)
{ {
char *s = (char *) ((void *)tmp + offset); char *s = (char *)((char *)tmp + offset);
return s; return s;
} }
static inline void set_offset_int(void *tmp, int offset, int val) static inline void set_offset_int(void *tmp, int offset, int val)
{ {
int *ptr = (int *)((void *)tmp + offset); int *ptr = (int *)((char *)tmp + offset);
*ptr = val; *ptr = val;
} }
static inline void set_offset_str(void *tmp, int offset, char *val) static inline void set_offset_str(void *tmp, int offset, const char *val)
{ {
char **ptr = (char **) ((void *)tmp + offset); char **ptr = (char **)((char *)tmp + offset);
if (val && *val) if (val && *val)
malloc_strcpy(ptr, val); malloc_strcpy(ptr, val);
else else
new_free(ptr); new_free(ptr);
} }
static inline void set_offset_char(void *tmp, int offset, char *val) static inline void set_offset_char(void *tmp, int offset, const char *val)
{ {
char *ptr = (char *) ((void *)tmp + offset); char *ptr = (char *)((char *)tmp + offset);
if (val && *val) if (val && *val)
strcpy(ptr, val); strcpy(ptr, val);
else else
@@ -576,11 +572,12 @@ int code = -1;
break; break;
case SERVER_LOOKUP: case SERVER_LOOKUP:
tmp = server_struct; tmp = server_struct;
if (serv != -1 && serv < server_list_size()) if (serv >= 0 && serv < server_list_size())
{ {
user = (void *)(get_server_list()); Server *slist = get_server_list();
user += (sizeof(Server) * serv);
ch = ((Server *)user)->chan_list; user = &slist[serv];
ch = slist[serv].chan_list;
} }
default: default:
break; break;