1
1

* changes to make the util code safe to build with a C++ compiler

This commit was SVN r3194.
Этот коммит содержится в:
Brian Barrett 2004-10-18 15:38:19 +00:00
родитель d600401f77
Коммит 1b1702ce00
11 изменённых файлов: 36 добавлений и 28 удалений

Просмотреть файл

@ -20,7 +20,7 @@ int ompi_argv_append(int *argc, char ***argv, const char *arg)
/* Create new argv. */ /* Create new argv. */
if (NULL == *argv) { if (NULL == *argv) {
*argv = malloc(2 * sizeof(char *)); *argv = (char**) malloc(2 * sizeof(char *));
if (NULL == *argv) if (NULL == *argv)
return OMPI_ERROR; return OMPI_ERROR;
*argc = 0; *argc = 0;
@ -31,14 +31,14 @@ int ompi_argv_append(int *argc, char ***argv, const char *arg)
/* Extend existing argv. */ /* Extend existing argv. */
else { else {
*argv = realloc(*argv, (*argc + 2) * sizeof(char *)); *argv = (char**) realloc(*argv, (*argc + 2) * sizeof(char *));
if (NULL == *argv) if (NULL == *argv)
return OMPI_ERROR; return OMPI_ERROR;
} }
/* Set the newest element to point to a copy of the arg string */ /* Set the newest element to point to a copy of the arg string */
(*argv)[*argc] = malloc(strlen(arg) + 1); (*argv)[*argc] = (char*) malloc(strlen(arg) + 1);
if (NULL == (*argv)[*argc]) if (NULL == (*argv)[*argc])
return OMPI_ERROR; return OMPI_ERROR;
@ -105,7 +105,7 @@ char **ompi_argv_split(const char *src_string, int delimiter)
/* long argument, malloc buffer, copy and add */ /* long argument, malloc buffer, copy and add */
else if (arglen > (ARGSIZE - 1)) { else if (arglen > (ARGSIZE - 1)) {
argtemp = malloc(arglen + 1); argtemp = (char*) malloc(arglen + 1);
if (NULL == argtemp) if (NULL == argtemp)
return NULL; return NULL;
@ -178,7 +178,7 @@ char *ompi_argv_join(char **argv, int delimiter)
/* Allocate the string. */ /* Allocate the string. */
if (NULL == (str = malloc(str_len))) if (NULL == (str = (char*) malloc(str_len)))
return NULL; return NULL;
/* Loop filling in the string. */ /* Loop filling in the string. */
@ -326,8 +326,8 @@ int ompi_argv_insert(char ***target, int start, char **source)
/* Alloc out new space */ /* Alloc out new space */
*target = realloc(*target, *target = (char**) realloc(*target,
sizeof(char *) * (target_count + source_count + 1)); sizeof(char *) * (target_count + source_count + 1));
/* Move suffix items down to the end */ /* Move suffix items down to the end */

Просмотреть файл

@ -352,7 +352,8 @@ return (OMPI_SUCCESS);
*/ */
int ompi_pack(ompi_buffer_t buffer, void * src, size_t n, ompi_pack_type_t type) int ompi_pack(ompi_buffer_t buffer, void * src, size_t n, ompi_pack_type_t type)
{ {
int i, rc; int rc;
size_t i;
void *dest; void *dest;
ompi_buffer_internal_t* bptr; ompi_buffer_internal_t* bptr;
size_t op_size=0; size_t op_size=0;
@ -439,7 +440,7 @@ return (OMPI_SUCCESS);
} }
break; break;
case OMPI_STRING: case OMPI_STRING:
strncpy(dest, src, n); strncpy((char*) dest, (char*) src, n);
*((char *) dest + n - 1) = '\0'; *((char *) dest + n - 1) = '\0';
break; break;
case OMPI_NAME: case OMPI_NAME:
@ -478,9 +479,10 @@ return (OMPI_SUCCESS);
* @retval OMPI_SUCCESS * @retval OMPI_SUCCESS
* @retval OMPI_ERROR * @retval OMPI_ERROR
*/ */
int ompi_unpack(ompi_buffer_t buffer, void * dest, size_t n, ompi_pack_type_t type) int
ompi_unpack(ompi_buffer_t buffer, void * dest, size_t n, ompi_pack_type_t type)
{ {
int i; size_t i;
void *src; void *src;
ompi_buffer_internal_t* bptr; ompi_buffer_internal_t* bptr;
size_t op_size=0; size_t op_size=0;
@ -555,7 +557,7 @@ return (OMPI_SUCCESS);
} }
break; break;
case OMPI_STRING: case OMPI_STRING:
strncpy(dest, src, n); strncpy((char*) dest, (char*) src, n);
*((char *) dest + n - 1) = '\0'; *((char *) dest + n - 1) = '\0';
break; break;
case OMPI_NAME: case OMPI_NAME:

Просмотреть файл

@ -423,7 +423,7 @@ char *ompi_cmd_line_get_usage_msg(ompi_cmd_line_t *cmd)
if (NULL != line) { if (NULL != line) {
free(line); free(line);
} }
line = malloc(len * 2); line = (char*) malloc(len * 2);
if (NULL == line) { if (NULL == line) {
ompi_mutex_unlock(&cmd->lcl_mutex); ompi_mutex_unlock(&cmd->lcl_mutex);
return NULL; return NULL;

Просмотреть файл

@ -135,7 +135,7 @@ static int ompi_ifinit(void)
} }
memcpy(&intf.if_mask, &ifr->ifr_addr, sizeof(intf.if_mask)); memcpy(&intf.if_mask, &ifr->ifr_addr, sizeof(intf.if_mask));
intf_ptr = malloc(sizeof(ompi_if_t)); intf_ptr = (ompi_if_t*) malloc(sizeof(ompi_if_t));
if(intf_ptr == 0) { if(intf_ptr == 0) {
ompi_output(0, "ompi_ifinit: unable to allocated %d bytes\n", sizeof(ompi_if_t)); ompi_output(0, "ompi_ifinit: unable to allocated %d bytes\n", sizeof(ompi_if_t));
return OMPI_ERR_OUT_OF_RESOURCE; return OMPI_ERR_OUT_OF_RESOURCE;

Просмотреть файл

@ -17,7 +17,7 @@ ompi_ltostr(long num)
char *buf = NULL; char *buf = NULL;
int ret = 0; int ret = 0;
buf = malloc(sizeof(char) * buflen); buf = (char*) malloc(sizeof(char) * buflen);
if (NULL == buf) return NULL; if (NULL == buf) return NULL;
ret = snprintf(buf, buflen, "%ld", num); ret = snprintf(buf, buflen, "%ld", num);
@ -38,7 +38,7 @@ ompi_dtostr(double num)
char *buf = NULL; char *buf = NULL;
int ret = 0; int ret = 0;
buf = malloc(sizeof(char) * buflen); buf = (char*) malloc(sizeof(char) * buflen);
if (NULL == buf) return NULL; if (NULL == buf) return NULL;
ret = snprintf(buf, buflen, "%f", num); ret = snprintf(buf, buflen, "%f", num);

Просмотреть файл

@ -401,7 +401,7 @@ static int open_file(int i)
dir = ompi_process_info.proc_session_dir; dir = ompi_process_info.proc_session_dir;
if (NULL != dir) { if (NULL != dir) {
filename = malloc(MAXPATHLEN); filename = (char*) malloc(MAXPATHLEN);
if (NULL == filename) { if (NULL == filename) {
return OMPI_ERR_OUT_OF_RESOURCE; return OMPI_ERR_OUT_OF_RESOURCE;
} }
@ -519,7 +519,7 @@ static void output(int output_id, char *format, va_list arglist)
if (NULL != temp_str) { if (NULL != temp_str) {
free(temp_str); free(temp_str);
} }
temp_str = malloc(total_len * 2); temp_str = (char*) malloc(total_len * 2);
temp_str_len = total_len * 2; temp_str_len = total_len * 2;
} }
if (NULL != ldi->ldi_prefix) { if (NULL != ldi->ldi_prefix) {

Просмотреть файл

@ -82,7 +82,7 @@ ompi_path_findv(char *fname, char **pathv, int mode, char **envv)
if (!delimit) { if (!delimit) {
fullpath = path_access(fname, env, mode); fullpath = path_access(fname, env, mode);
} else { } else {
pfix = malloc(strlen(env) + strlen(delimit) + 1); pfix = (char*) malloc(strlen(env) + strlen(delimit) + 1);
if (NULL == pfix){ if (NULL == pfix){
return(0); return(0);
} }
@ -224,7 +224,7 @@ path_access(char *fname, char *path, int mode)
/* /*
* Allocate space for the full pathname. * Allocate space for the full pathname.
*/ */
fullpath = malloc(strlen(path) + strlen(fname) + 2); fullpath = (char*) malloc(strlen(path) + strlen(fname) + 2);
if (NULL == fullpath){ if (NULL == fullpath){
return(0); return(0);
} }

Просмотреть файл

@ -27,7 +27,7 @@ static int guess_strlen(const char *fmt, va_list ap)
char *sarg; char *sarg;
double darg; double darg;
float farg; float farg;
int i; size_t i;
int iarg; int iarg;
int len; int len;
long larg; long larg;
@ -192,7 +192,7 @@ int ompi_vasprintf(char **ptr, const char *fmt, va_list ap)
length = vsprintf(*ptr, fmt, ap); length = vsprintf(*ptr, fmt, ap);
/* realloc */ /* realloc */
*ptr = realloc(*ptr, (size_t) length + 1); *ptr = (char*) realloc(*ptr, (size_t) length + 1);
if (NULL == *ptr) { if (NULL == *ptr) {
errno = ENOMEM; errno = ENOMEM;
return -1; return -1;

Просмотреть файл

@ -240,7 +240,7 @@ static int output(bool want_error_header, ompi_pointer_array_t *lines,
len = want_error_header ? 2 * strlen(star_line) : 0; len = want_error_header ? 2 * strlen(star_line) : 0;
for (i = 0; i < ompi_pointer_array_get_size(lines); ++i) { for (i = 0; i < ompi_pointer_array_get_size(lines); ++i) {
tmp = ompi_pointer_array_get_item(lines, i); tmp = (char*) ompi_pointer_array_get_item(lines, i);
if (NULL == tmp) { if (NULL == tmp) {
break; break;
} }
@ -249,7 +249,7 @@ static int output(bool want_error_header, ompi_pointer_array_t *lines,
/* Malloc it out */ /* Malloc it out */
concat = malloc(len + 1); concat = (char*) malloc(len + 1);
if (NULL == concat) { if (NULL == concat) {
fprintf(stderr, star_line); fprintf(stderr, star_line);
fprintf(stderr, "Sorry! You were supposed to get help about:\n %s\nfrom the file:\n %s\n", topic, base); fprintf(stderr, "Sorry! You were supposed to get help about:\n %s\nfrom the file:\n %s\n", topic, base);
@ -265,7 +265,7 @@ static int output(bool want_error_header, ompi_pointer_array_t *lines,
strcat(concat, star_line); strcat(concat, star_line);
} }
for (i = 0; i < ompi_pointer_array_get_size(lines); ++i) { for (i = 0; i < ompi_pointer_array_get_size(lines); ++i) {
tmp = ompi_pointer_array_get_item(lines, i); tmp = (char*) ompi_pointer_array_get_item(lines, i);
if (NULL == tmp) { if (NULL == tmp) {
break; break;
} }
@ -301,7 +301,7 @@ static int destroy_message(ompi_pointer_array_t *lines)
char *tmp; char *tmp;
for (i = 0; i < ompi_pointer_array_get_size(lines); ++i) { for (i = 0; i < ompi_pointer_array_get_size(lines); ++i) {
tmp = ompi_pointer_array_get_item(lines, i); tmp = (char*) ompi_pointer_array_get_item(lines, i);
if (NULL == tmp) { if (NULL == tmp) {
break; break;
} }

Просмотреть файл

@ -16,7 +16,13 @@ int ompi_show_help_finish_parsing(void);
/* /*
* local functions * local functions
*/ */
static int ompi_show_help_yywrap(void); #ifdef __cplusplus
extern "C" {
#endif
static int ompi_show_help_yywrap(void);
#ifdef __cplusplus
}
#endif
/* /*
* global variables * global variables

Просмотреть файл

@ -31,7 +31,7 @@
char * char *
ompi_strncpy(char *dest, const char *src, size_t len) ompi_strncpy(char *dest, const char *src, size_t len)
{ {
int i; size_t i;
int pad = 0; int pad = 0;
char *new_dest = dest; char *new_dest = dest;