rid warnings from modern MSVC

This commit is contained in:
Doug MacEachern 2007-06-27 01:10:12 +00:00
parent e710e27948
commit 3e064dfeb7
8 changed files with 36 additions and 23 deletions

View File

@ -1323,7 +1323,7 @@ JNIEXPORT jlongArray SIGAR_JNI(ptql_SigarProcessQuery_find)
JNIEXPORT jboolean SIGAR_JNI(util_Getline_isatty) JNIEXPORT jboolean SIGAR_JNI(util_Getline_isatty)
(JNIEnv *env, jclass cls) (JNIEnv *env, jclass cls)
{ {
return isatty(fileno(stdin)) ? JNI_TRUE : JNI_FALSE; return sigar_isatty(sigar_fileno(stdin)) ? JNI_TRUE : JNI_FALSE;
} }
JNIEXPORT jstring SIGAR_JNI(util_Getline_getline) JNIEXPORT jstring SIGAR_JNI(util_Getline_getline)

View File

@ -115,7 +115,7 @@ JNIEXPORT jlong SIGAR_JNI(win32_RegistryKey_RegOpenKey)
/* required under IBM/WebSphere 4.0 for certain keys */ /* required under IBM/WebSphere 4.0 for certain keys */
if (lpSubkey[len] != '\0') { if (lpSubkey[len] != '\0') {
copy = wcsdup(lpSubkey); copy = _wcsdup(lpSubkey);
copy[len] = '\0'; copy[len] = '\0';
} }
else { else {
@ -143,7 +143,7 @@ JNIEXPORT jint SIGAR_JNI(win32_RegistryKey_RegQueryIntValue)
LONG lErr; LONG lErr;
/* required under IBM/WebSphere 4.0 for certain keys */ /* required under IBM/WebSphere 4.0 for certain keys */
if (lpValueName[len] != '\0') { if (lpValueName[len] != '\0') {
copy = wcsdup(lpValueName); copy = _wcsdup(lpValueName);
copy[len] = '\0'; copy[len] = '\0';
} }
else { else {
@ -206,7 +206,7 @@ JNIEXPORT jstring SIGAR_JNI(win32_RegistryKey_RegQueryStringValue)
LONG lErr; LONG lErr;
/* required under IBM/WebSphere 4.0 for certain keys */ /* required under IBM/WebSphere 4.0 for certain keys */
if (lpValueName[len] != '\0') { if (lpValueName[len] != '\0') {
copy = wcsdup(lpValueName); copy = _wcsdup(lpValueName);
copy[len] = '\0'; copy[len] = '\0';
} }
else { else {

View File

@ -86,8 +86,11 @@
#define sigar_strdup(s) \ #define sigar_strdup(s) \
dmalloc_strdup(__FILE__, __LINE__, s, 0); dmalloc_strdup(__FILE__, __LINE__, s, 0);
#else #else
#define sigar_strdup(s) \ # ifdef WIN32
strdup(s) # define sigar_strdup(s) _strdup(s)
# else
# define sigar_strdup(s) strdup(s)
# endif
#endif #endif
#define SIGAR_ZERO(s) \ #define SIGAR_ZERO(s) \

View File

@ -44,6 +44,16 @@
#define sigar_isupper(c) \ #define sigar_isupper(c) \
(isupper(((unsigned char)(c)))) (isupper(((unsigned char)(c))))
#ifdef WIN32
#define sigar_fileno _fileno
#define sigar_isatty _isatty
#define sigar_write _write
#else
#define sigar_fileno fileno
#define sigar_isatty isatty
#define sigar_write write
#endif
#ifndef PROC_FS_ROOT #ifndef PROC_FS_ROOT
#define PROC_FS_ROOT "/proc/" #define PROC_FS_ROOT "/proc/"
#endif #endif

View File

@ -131,7 +131,7 @@ int sigar_parse_proc_args(sigar_t *sigar, WCHAR *buf,
for (i=0; i<num; i++) { for (i=0; i<num; i++) {
SIGAR_W2A(args[i], arg, SIGAR_CMDLINE_MAX); SIGAR_W2A(args[i], arg, SIGAR_CMDLINE_MAX);
SIGAR_PROC_ARGS_GROW(procargs); SIGAR_PROC_ARGS_GROW(procargs);
procargs->data[procargs->number++] = strdup(arg); procargs->data[procargs->number++] = sigar_strdup(arg);
} }
GlobalFree(args); GlobalFree(args);

View File

@ -2410,7 +2410,7 @@ sigar_net_interface_list_get(sigar_t *sigar,
} }
if (iflist) { if (iflist) {
iflist->data[iflist->number++] = strdup(name); iflist->data[iflist->number++] = sigar_strdup(name);
} }
key = netif_hash(name); key = netif_hash(name);

View File

@ -660,13 +660,13 @@ gl_putc(int c)
CharToOemBuff((char const *)&c,&ch,1); CharToOemBuff((char const *)&c,&ch,1);
#endif #endif
write(1, &ch, 1); sigar_write(1, &ch, 1);
} }
#if defined(unix) || defined(MSDOS) || defined(WIN32) || defined(R__MWERKS) #if defined(unix) || defined(MSDOS) || defined(WIN32) || defined(R__MWERKS)
#ifdef TIOCSETP /* BSD in RAW mode, map NL to NL,CR */ #ifdef TIOCSETP /* BSD in RAW mode, map NL to NL,CR */
if (ch == '\n') { if (ch == '\n') {
ch = '\r'; ch = '\r';
write(1, &ch, 1); sigar_write(1, &ch, 1);
} }
#endif #endif
#endif #endif
@ -684,11 +684,11 @@ gl_puts(char *buf)
{ {
char *OemBuf = (char *)malloc(2*len); char *OemBuf = (char *)malloc(2*len);
CharToOemBuff(buf,OemBuf,len); CharToOemBuff(buf,OemBuf,len);
write(1, OemBuf, len); sigar_write(1, OemBuf, len);
free(OemBuf); free(OemBuf);
} }
#else #else
write(1, buf, len); sigar_write(1, buf, len);
#endif #endif
} }
@ -702,11 +702,11 @@ gl_error(char *buf)
{ {
char *OemBuf = (char *)malloc(2*len); char *OemBuf = (char *)malloc(2*len);
CharToOemBuff(buf,OemBuf,len); CharToOemBuff(buf,OemBuf,len);
write(2, OemBuf, len); sigar_write(2, OemBuf, len);
free(OemBuf); free(OemBuf);
} }
#else #else
write(2, buf, len); sigar_write(2, buf, len);
#endif #endif
exit(1); exit(1);
} }
@ -718,7 +718,7 @@ gl_init()
if (gl_init_done < 0) { /* -1 only on startup */ if (gl_init_done < 0) { /* -1 only on startup */
hist_init(); hist_init();
} }
if (isatty(0) == 0 || isatty(1) == 0) if (sigar_isatty(0) == 0 || sigar_isatty(1) == 0)
gl_notty = 1; gl_notty = 1;
gl_char_init(); gl_char_init();
gl_init_done = 1; gl_init_done = 1;
@ -756,7 +756,7 @@ SIGAR_DECLARE(void)
sigar_getline_windowchanged() sigar_getline_windowchanged()
{ {
#ifdef TIOCGWINSZ #ifdef TIOCGWINSZ
if (isatty(0)) { if (sigar_isatty(0)) {
static char lenv[32], cenv[32]; static char lenv[32], cenv[32];
struct winsize wins; struct winsize wins;
ioctl(0, TIOCGWINSZ, &wins); ioctl(0, TIOCGWINSZ, &wins);

View File

@ -531,7 +531,7 @@ static int ptql_branch_list_destroy(ptql_branch_list_t *branches)
static int ptql_branch_init_any(ptql_parse_branch_t *parsed, static int ptql_branch_init_any(ptql_parse_branch_t *parsed,
ptql_branch_t *branch) ptql_branch_t *branch)
{ {
branch->data.str = strdup(parsed->attr); branch->data.str = sigar_strdup(parsed->attr);
branch->data_size = strlen(parsed->attr); branch->data_size = strlen(parsed->attr);
return SIGAR_OK; return SIGAR_OK;
} }
@ -654,14 +654,14 @@ static int ptql_branch_init_pid(ptql_parse_branch_t *parsed,
} }
else if (strEQ(parsed->attr, "PidFile")) { else if (strEQ(parsed->attr, "PidFile")) {
branch->flags = PTQL_PID_FILE; branch->flags = PTQL_PID_FILE;
branch->data.str = strdup(parsed->value); branch->data.str = sigar_strdup(parsed->value);
branch->data_size = strlen(parsed->value); branch->data_size = strlen(parsed->value);
return SIGAR_OK; return SIGAR_OK;
} }
else if (strEQ(parsed->attr, "Service")) { else if (strEQ(parsed->attr, "Service")) {
branch->flags = PTQL_PID_SERVICE; branch->flags = PTQL_PID_SERVICE;
#ifdef WIN32 #ifdef WIN32
branch->data.str = strdup(parsed->value); branch->data.str = sigar_strdup(parsed->value);
branch->data_size = strlen(parsed->value); branch->data_size = strlen(parsed->value);
#endif #endif
return SIGAR_OK; return SIGAR_OK;
@ -1148,7 +1148,7 @@ static int ptql_branch_add(ptql_parse_branch_t *parsed,
} }
else { else {
if ((ptr = getenv(parsed->value+1))) { if ((ptr = getenv(parsed->value+1))) {
branch->value.str = strdup(ptr); branch->value.str = sigar_strdup(ptr);
} }
else { else {
branch->value.str = NULL; branch->value.str = NULL;
@ -1212,7 +1212,7 @@ static int ptql_branch_add(ptql_parse_branch_t *parsed,
case PTQL_VALUE_TYPE_ANY: case PTQL_VALUE_TYPE_ANY:
branch->match.str = ptql_op_str[branch->op_name]; branch->match.str = ptql_op_str[branch->op_name];
if (!is_set) { if (!is_set) {
branch->value.str = strdup(parsed->value); branch->value.str = sigar_strdup(parsed->value);
} }
break; break;
} }
@ -1233,14 +1233,14 @@ static int ptql_branch_compare(const void *b1, const void *b2)
SIGAR_DECLARE(int) sigar_ptql_query_create(sigar_ptql_query_t **queryp, SIGAR_DECLARE(int) sigar_ptql_query_create(sigar_ptql_query_t **queryp,
char *ptql) char *ptql)
{ {
char *ptr, *ptql_copy = strdup(ptql); char *ptr, *ptql_copy = sigar_strdup(ptql);
int status = SIGAR_OK; int status = SIGAR_OK;
int has_ref = 0; int has_ref = 0;
sigar_ptql_query_t *query = sigar_ptql_query_t *query =
*queryp = malloc(sizeof(*query)); *queryp = malloc(sizeof(*query));
#ifdef PTQL_DEBUG #ifdef PTQL_DEBUG
query->ptql = strdup(ptql); query->ptql = sigar_strdup(ptql);
#endif #endif
ptql = ptql_copy; ptql = ptql_copy;