Skip to content

Commit 526616e

Browse files
committed
cleanup CRTL code
1 parent 36d3aa5 commit 526616e

File tree

8 files changed

+23
-13
lines changed

8 files changed

+23
-13
lines changed

bld/clib/environ/c/_findenv.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ static int __F_NAME(findenv,wfindenv)( const CHAR_TYPE *name, int delete_var )
8989
lib_free( *envp );
9090
}
9191
#endif
92+
/* shift string array entries */
9293
for( tmp_envp = envp; *tmp_envp != NULL; tmp_envp++ ) {
9394
*tmp_envp = *(tmp_envp + 1);
9495
}
9596
#ifndef __WIDECHAR__
97+
/* shift flag array entries */
9698
envm = (char *)tmp_envp;
9799
while( len-- > 0 ) {
98100
*envm++ = *_RWD_env_mask++;
@@ -116,7 +118,8 @@ static int __F_NAME(findenv,wfindenv)( const CHAR_TYPE *name, int delete_var )
116118
}
117119
}
118120
}
119-
return( __F_NAME(_RWD_environ,_RWD_wenviron) - envp ); /* not found */
121+
/* not found */
122+
return( __F_NAME(_RWD_environ,_RWD_wenviron) - envp );
120123
}
121124

122125
int __F_NAME(__findenvadd,__wfindenvadd)( const CHAR_TYPE *env_string )

bld/clib/environ/c/_setenv.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int __F_NAME(addenv,waddenv)( int index, const CHAR_TYPE *name, const CHA
6767
envp = __F_NAME(_RWD_environ,_RWD_wenviron);
6868
len = __F_NAME(strlen,wcslen)( name );
6969
old_val = _RWD_env_mask[index] ? envp[index] : NULL;
70-
env_str = lib_realloc( (void *)old_val, ( len + __F_NAME(strlen,wcslen)( newvalue ) + 2 ) * sizeof( CHAR_TYPE ) );
70+
env_str = lib_realloc( old_val, ( len + 1 + __F_NAME(strlen,wcslen)( newvalue ) + 1 ) * sizeof( CHAR_TYPE ) );
7171
if( env_str == NULL )
7272
return( -1 );
7373
memcpy( env_str, name, len * sizeof( CHAR_TYPE ) );

bld/clib/environ/c/environ.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*
33
* Open Watcom Project
44
*
5+
* Copyright (c) 2002-2021 The Open Watcom Contributors. All Rights Reserved.
56
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
67
*
78
* ========================================================================
@@ -35,9 +36,10 @@
3536
#include "rtinit.h"
3637
#include "_environ.h"
3738

38-
_WCRTDATA char ** _WCDATA environ; /* pointer to environment table */
39-
_WCRTDATA wchar_t ** _WCDATA _wenviron; /* pointer to wide char environment */
40-
char * _WCNEAR __env_mask; /* ptr to char array of flags */
39+
40+
_WCRTDATA char ** _WCDATA environ; /* pointer to environment table */
41+
_WCRTDATA wchar_t ** _WCDATA _wenviron; /* pointer to wide char environment */
42+
char * _WCNEAR __env_mask; /* ptr to char array of flags */
4143

4244
AXI( __setenvp, INIT_PRIORITY_LIBRARY )
4345

bld/clib/environ/c/setenvp.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,12 @@ void __setenvp( void )
104104
while( *argep != NULL )
105105
argep++;
106106
count = argep - _Envptr;
107-
argep = lib_malloc( ENVARR_SIZE( count ) );
108-
memcpy( argep, _Envptr, ( count + 1 ) * sizeof( char * ) );
109-
_RWD_environ = argep;
110-
_RWD_env_mask = (char *)&argep[count + 1];
111-
memset( _RWD_env_mask, 0, count );
107+
_RWD_environ = lib_malloc( ENVARR_SIZE( count ) );
108+
if( _RWD_environ != NULL ) {
109+
_RWD_env_mask = (char *)&_RWD_environ[count + 1];
110+
memcpy( _RWD_environ, _Envptr, ( count + 1 ) * sizeof( char * ) );
111+
memset( _RWD_env_mask, 0, count );
112+
}
112113
#else
113114
#if defined(__WINDOWS_386__) || defined(__DOS_386__)
114115
char _WCFAR *startp;

bld/clib/intel/c/p5prof.c

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <stdio.h>
3737
#include <stdlib.h>
3838
#include <stddef.h>
39+
#include <limits.h>
3940
#include "rtinit.h"
4041
#include "p5prof.h"
4142
#include "pathgrp2.h"

bld/clib/intel/c/p5prof2.c

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <string.h>
3737
#include <stdio.h>
3838
#include <stddef.h>
39+
#include <limits.h>
3940
#include <unistd.h>
4041
#include <sys/stat.h>
4142
#ifdef __NT__

bld/clib/intel/c/profilog.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Open Watcom Project
44
*
5-
* Copyright (c) 2002-2020 The Open Watcom Contributors. All Rights Reserved.
5+
* Copyright (c) 2002-2021 The Open Watcom Contributors. All Rights Reserved.
66
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
77
*
88
* ========================================================================
@@ -34,6 +34,7 @@
3434
#include "widechar.h"
3535
#include <stdlib.h>
3636
#include <stdio.h>
37+
#include <limits.h>
3738
#include <unistd.h>
3839
#include "rtinit.h"
3940
#include "p5prof.h"

bld/clib/startup/c/cmainqnx.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Open Watcom Project
44
*
5-
* Copyright (c) 2002-2019 The Open Watcom Contributors. All Rights Reserved.
5+
* Copyright (c) 2002-2021 The Open Watcom Contributors. All Rights Reserved.
66
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
77
*
88
* ========================================================================
@@ -52,6 +52,7 @@
5252
#include "rtdata.h"
5353
#include "fltsupp.h"
5454
#include "slibqnx.h"
55+
#include "_environ.h"
5556

5657

5758
#if defined( _M_I86 )
@@ -77,10 +78,10 @@ char **_argv; /* argument vector */
7778

7879
pid_t _my_pid; /* some sort of POSIX dodad */
7980
struct _proc_spawn *__cmd; /* address of spawn msg */
80-
char *__near __env_mask;
8181
int (__far * (__far *__f))(); /* Shared library jump table */
8282
extern void __user_init( void );
8383
#define __user_init() ((int(__far *)(void)) __f[1])()
84+
8485
#endif
8586

8687
static void _WCI86FAR __null_FPE_rtn( int fpe_type )

0 commit comments

Comments
 (0)