diff options
author | Ron Yorston <rmy@pobox.com> | 2021-07-28 12:48:21 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-07-28 12:48:21 +0100 |
commit | 83b78af8033e10e959e7b56c74b1c3c5ee2f8fc5 (patch) | |
tree | dbbb2b8f04260d7874a255f7b1a213055be5c62c | |
parent | 5776a5f8d5bfe83b72dc3d9788e92a2a11b22cd2 (diff) | |
download | busybox-w32-83b78af8033e10e959e7b56c74b1c3c5ee2f8fc5.tar.gz busybox-w32-83b78af8033e10e959e7b56c74b1c3c5ee2f8fc5.tar.bz2 busybox-w32-83b78af8033e10e959e7b56c74b1c3c5ee2f8fc5.zip |
win32: code shrink using is_prefixed_with()
Use is_prefixed_with() rather than strncmp() in a few places,
and the case-insensitive analogues.
Saves 96 bytes in 64-bit build, 192 bytes in 32-bit.
-rw-r--r-- | networking/httpd.c | 5 | ||||
-rw-r--r-- | shell/ash.c | 8 | ||||
-rw-r--r-- | win32/mingw.c | 34 |
3 files changed, 27 insertions, 20 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index fcc49853a..fcd1627b1 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -557,7 +557,12 @@ enum { | |||
557 | } while (0) | 557 | } while (0) |
558 | 558 | ||
559 | 559 | ||
560 | #if !ENABLE_PLATFORM_MINGW32 | ||
560 | #define STRNCASECMP(a, str) strncasecmp((a), (str), sizeof(str)-1) | 561 | #define STRNCASECMP(a, str) strncasecmp((a), (str), sizeof(str)-1) |
562 | #else | ||
563 | /* Not exactly equivalent to strncasecmp(), but OK for its use here */ | ||
564 | #define STRNCASECMP(a, str) (!is_prefixed_with_case((a), (str))) | ||
565 | #endif | ||
561 | 566 | ||
562 | /* Prototypes */ | 567 | /* Prototypes */ |
563 | enum { | 568 | enum { |
diff --git a/shell/ash.c b/shell/ash.c index 3e02a4e1f..08e34d6e7 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -15269,8 +15269,8 @@ init(void) | |||
15269 | * because it appears first. | 15269 | * because it appears first. |
15270 | */ | 15270 | */ |
15271 | for (envp = environ; envp && *envp; envp++) { | 15271 | for (envp = environ; envp && *envp; envp++) { |
15272 | if (strncasecmp(*envp, "PATH=", 5) == 0 && | 15272 | if (is_prefixed_with_case(*envp, "PATH=") && |
15273 | strncmp(*envp, "PATH=", 5) != 0) { | 15273 | !is_prefixed_with(*envp, "PATH=")) { |
15274 | break; | 15274 | break; |
15275 | } | 15275 | } |
15276 | } | 15276 | } |
@@ -15295,8 +15295,8 @@ init(void) | |||
15295 | /* Convert backslashes to forward slashes in value but | 15295 | /* Convert backslashes to forward slashes in value but |
15296 | * not if we're on Windows XP or for variables known to | 15296 | * not if we're on Windows XP or for variables known to |
15297 | * cause problems */ | 15297 | * cause problems */ |
15298 | if ( !winxp && strncmp(*envp, "SYSTEMROOT=", 11) != 0 && | 15298 | if (!winxp && !is_prefixed_with(*envp, "SYSTEMROOT=") && |
15299 | strncmp(*envp, "COMSPEC=", 8) != 0 ) { | 15299 | !is_prefixed_with(*envp, "COMSPEC=")) { |
15300 | bs_to_slash(end+1); | 15300 | bs_to_slash(end+1); |
15301 | } | 15301 | } |
15302 | 15302 | ||
diff --git a/win32/mingw.c b/win32/mingw.c index 1e3cce17a..943202f41 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -171,7 +171,7 @@ static int rand_fd = -1; | |||
171 | */ | 171 | */ |
172 | int get_dev_type(const char *filename) | 172 | int get_dev_type(const char *filename) |
173 | { | 173 | { |
174 | if (filename && !strncmp(filename, "/dev/", 5)) | 174 | if (filename && is_prefixed_with(filename, "/dev/")) |
175 | return index_in_strings("null\0zero\0urandom\0", filename+5); | 175 | return index_in_strings("null\0zero\0urandom\0", filename+5); |
176 | 176 | ||
177 | return NOT_DEVICE; | 177 | return NOT_DEVICE; |
@@ -414,7 +414,8 @@ mode_t mingw_umask(mode_t new_mode) | |||
414 | */ | 414 | */ |
415 | static int has_exec_format(const char *name) | 415 | static int has_exec_format(const char *name) |
416 | { | 416 | { |
417 | int n; | 417 | int n, sig; |
418 | unsigned int offset; | ||
418 | unsigned char buf[1024]; | 419 | unsigned char buf[1024]; |
419 | 420 | ||
420 | /* special case: skip DLLs, there are thousands of them! */ | 421 | /* special case: skip DLLs, there are thousands of them! */ |
@@ -435,19 +436,20 @@ static int has_exec_format(const char *name) | |||
435 | * the magic from the file command. | 436 | * the magic from the file command. |
436 | */ | 437 | */ |
437 | if (buf[0] == 'M' && buf[1] == 'Z') { | 438 | if (buf[0] == 'M' && buf[1] == 'Z') { |
438 | unsigned int offset = (buf[0x19] << 8) | buf[0x18]; | 439 | offset = (buf[0x19] << 8) + buf[0x18]; |
439 | if (offset > 0x3f) { | 440 | if (offset > 0x3f) { |
440 | offset = (buf[0x3f] << 24) | (buf[0x3e] << 16) | | 441 | offset = (buf[0x3f] << 24) + (buf[0x3e] << 16) + |
441 | (buf[0x3d] << 8) | buf[0x3c]; | 442 | (buf[0x3d] << 8) + buf[0x3c]; |
442 | if (offset + 100 < n) { | 443 | if (offset < sizeof(buf)-100) { |
443 | unsigned char *ptr = buf + offset; | 444 | if (memcmp(buf+offset, "PE\0\0", 4) == 0) { |
444 | if (memcmp(ptr, "PE\0\0", 4) == 0) { | 445 | sig = (buf[offset+25] << 8) + buf[offset+24]; |
445 | unsigned int sig = (ptr[25] << 8) | ptr[24]; | ||
446 | if (sig == 0x10b || sig == 0x20b) { | 446 | if (sig == 0x10b || sig == 0x20b) { |
447 | sig = (ptr[23] << 8) | ptr[22]; | 447 | sig = (buf[offset+23] << 8) + buf[offset+22]; |
448 | if ((sig & 0x2000) != 0) // DLL | 448 | if ((sig & 0x2000) != 0) { |
449 | /* DLL */ | ||
449 | return 0; | 450 | return 0; |
450 | sig = ptr[92]; | 451 | } |
452 | sig = buf[offset+92]; | ||
451 | return (sig == 1 || sig == 2 || sig == 3 || sig == 7); | 453 | return (sig == 1 || sig == 2 || sig == 3 || sig == 7); |
452 | } | 454 | } |
453 | } | 455 | } |
@@ -1230,13 +1232,13 @@ static char *normalize_ntpathA(char *buf) | |||
1230 | /* fix absolute path prefixes */ | 1232 | /* fix absolute path prefixes */ |
1231 | if (buf[0] == '\\') { | 1233 | if (buf[0] == '\\') { |
1232 | /* strip NT namespace prefixes */ | 1234 | /* strip NT namespace prefixes */ |
1233 | if (!strncmp(buf, "\\??\\", 4) || | 1235 | if (is_prefixed_with(buf, "\\??\\") || |
1234 | !strncmp(buf, "\\\\?\\", 4)) | 1236 | is_prefixed_with(buf, "\\\\?\\")) |
1235 | buf += 4; | 1237 | buf += 4; |
1236 | else if (!strncasecmp(buf, "\\DosDevices\\", 12)) | 1238 | else if (is_prefixed_with_case(buf, "\\DosDevices\\")) |
1237 | buf += 12; | 1239 | buf += 12; |
1238 | /* replace remaining '...UNC\' with '\\' */ | 1240 | /* replace remaining '...UNC\' with '\\' */ |
1239 | if (!strncasecmp(buf, "UNC\\", 4)) { | 1241 | if (is_prefixed_with_case(buf, "UNC\\")) { |
1240 | buf += 2; | 1242 | buf += 2; |
1241 | *buf = '\\'; | 1243 | *buf = '\\'; |
1242 | } | 1244 | } |