The MinGW.org Windows System Libraries
Revisão | 467402e1dab9396c4f21b894dfb2c7374a483542 (tree) |
---|---|
Hora | 2021-01-27 04:58:39 |
Autor | Keith Marshall <keith@user...> |
Commiter | Keith Marshall |
Avoid proliferation of static snprintf() implementations.
@@ -1,3 +1,18 @@ | ||
1 | +2021-01-26 Keith Marshall <keith@users.osdn.me> | |
2 | + | |
3 | + Avoid proliferation of static snprintf() implementations. | |
4 | + | |
5 | + * mingwex/dlfcn.c (dlfcn_store_error_message): Do NOT use... | |
6 | + (vsnprintf): ...this static inline function; prefer to call... | |
7 | + (__mingw_vsnprintf): ...this extern implementation, directly. | |
8 | + | |
9 | + * mingwex/dlfcn.c (dlfcn_strerror) | |
10 | + * mingwex/setenv.c (__mingw_setenv) | |
11 | + * mingwex/strerror_r.c (strerror_r): Do NOT use... | |
12 | + (snprintf): ...this; it expands to create static clones of... | |
13 | + (__mingw_snprintf): ...this extern implementation; prefer to call it | |
14 | + directly, to avoid code redundancy. | |
15 | + | |
1 | 16 | 2020-08-07 Keith Marshall <keith@users.osdn.me> |
2 | 17 | |
3 | 18 | Initialize MSVCRT.DLL's _pgmptr reference. |
@@ -6,8 +6,8 @@ | ||
6 | 6 | * |
7 | 7 | * $Id$ |
8 | 8 | * |
9 | - * Written by Keith Marshall <keithmarshall@users.sourceforge.net> | |
10 | - * Copyright (C) 2014, MinGW.org Project | |
9 | + * Written by Keith Marshall <keith@users.osdn.me> | |
10 | + * Copyright (C) 2014, 2021, MinGW.org Project | |
11 | 11 | * |
12 | 12 | * |
13 | 13 | * Permission is hereby granted, free of charge, to any person obtaining a |
@@ -91,12 +91,12 @@ static void dlfcn_store_error_message( const char *fmt, ... ) | ||
91 | 91 | int msglen; |
92 | 92 | va_list argv; |
93 | 93 | va_start( argv, fmt ); |
94 | - msglen = 1 + vsnprintf( NULL, 0, fmt, argv ); | |
94 | + msglen = 1 + __mingw_vsnprintf( NULL, 0, fmt, argv ); | |
95 | 95 | if( (dlfcn_error_pending = realloc( dlfcn_error_message, msglen )) != NULL ) |
96 | 96 | /* |
97 | 97 | * Store message, only if a buffer was successfully allocated. |
98 | 98 | */ |
99 | - vsnprintf( dlfcn_error_pending, msglen, fmt, argv ); | |
99 | + __mingw_vsnprintf( dlfcn_error_pending, msglen, fmt, argv ); | |
100 | 100 | dlfcn_error_message = dlfcn_error_pending; |
101 | 101 | va_end( argv ); |
102 | 102 | } |
@@ -132,8 +132,8 @@ static char *dlfcn_strerror( int errcode ) | ||
132 | 132 | * formatted reference to the unknown error code. |
133 | 133 | */ |
134 | 134 | char *fmt = "Unknown error %d"; |
135 | - char tmp[1 + snprintf( NULL, 0, fmt, errcode )]; | |
136 | - snprintf( tmp, sizeof( tmp ), fmt, errcode ); | |
135 | + char tmp[1 + __mingw_snprintf( NULL, 0, fmt, errcode )]; | |
136 | + __mingw_snprintf( tmp, sizeof( tmp ), fmt, errcode ); | |
137 | 137 | text = strdup( tmp ); |
138 | 138 | } |
139 | 139 | /* However we derived it, the error description is now available |
@@ -7,8 +7,8 @@ | ||
7 | 7 | * |
8 | 8 | * $Id$ |
9 | 9 | * |
10 | - * Written by Keith Marshall <keithmarshall@users.sourceforge.net> | |
11 | - * Copyright (C) 2016, MinGW.org Project | |
10 | + * Written by Keith Marshall <keith@users.osdn.me> | |
11 | + * Copyright (C) 2016, 2021, MinGW.org Project | |
12 | 12 | * |
13 | 13 | * |
14 | 14 | * Permission is hereby granted, free of charge, to any person obtaining a |
@@ -64,8 +64,8 @@ int __mingw_setenv( const char *var, const char *value, int overwrite ) | ||
64 | 64 | */ |
65 | 65 | const char *fmt = "%s=%s"; |
66 | 66 | const char *val = value ? value : ""; |
67 | - char buf[1 + snprintf( NULL, 0, fmt, var, val )]; | |
68 | - snprintf( buf, sizeof( buf ), fmt, var, val ); | |
67 | + char buf[1 + __mingw_snprintf( NULL, 0, fmt, var, val )]; | |
68 | + __mingw_snprintf( buf, sizeof( buf ), fmt, var, val ); | |
69 | 69 | |
70 | 70 | /* "buf" is now formatted as "var=value", in the form |
71 | 71 | * required by putenv(), but it exists only within our |
@@ -5,8 +5,8 @@ | ||
5 | 5 | * |
6 | 6 | * $Id$ |
7 | 7 | * |
8 | - * Written by Keith Marshall <keithmarshall@users.sourceforge.net> | |
9 | - * Copyright (C) 2016, 2017, MinGW.org Project | |
8 | + * Written by Keith Marshall <keith@users.osdn.me> | |
9 | + * Copyright (C) 2016, 2017, 2021, MinGW.org Project | |
10 | 10 | * |
11 | 11 | * |
12 | 12 | * Permission is hereby granted, free of charge, to any person obtaining a |
@@ -68,13 +68,13 @@ int strerror_r( int errnum, char *buf, size_t len ) | ||
68 | 68 | * range INT_MAX < errnum <= UINT_MAX, while sys_nerr is expected |
69 | 69 | * to be less than INT_MAX. |
70 | 70 | */ |
71 | - snprintf( buf, len, "Unknown error: %d", errnum ); | |
71 | + __mingw_snprintf( buf, len, "Unknown error: %d", errnum ); | |
72 | 72 | return errno = EINVAL; |
73 | 73 | } |
74 | 74 | /* errnum appears to be valid; copy the associated message, while |
75 | 75 | * checking that its entire text is copied... |
76 | 76 | */ |
77 | - if( snprintf( buf, len, "%s", strerror( errnum )) >= len ) | |
77 | + if( __mingw_snprintf( buf, len, "%s", strerror( errnum )) >= len ) | |
78 | 78 | /* |
79 | 79 | * ...otherwise, set errno on truncation. |
80 | 80 | */ |