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 /win32 | |
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.
Diffstat (limited to 'win32')
-rw-r--r-- | win32/mingw.c | 34 |
1 files changed, 18 insertions, 16 deletions
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 | } |