Return true if two paths refer to the same on-disk file. Used to avoid * copying the running binary onto itself during install (cbm_copy_file would * truncate it, since it opens the destination "wb" before reading the source). */
| 1018 | * copying the running binary onto itself during install (cbm_copy_file would |
| 1019 | * truncate it, since it opens the destination "wb" before reading the source). */ |
| 1020 | static bool cbm_same_file(const char *a, const char *b) { |
| 1021 | struct stat sa; |
| 1022 | struct stat sb; |
| 1023 | if (stat(a, &sa) != 0 || stat(b, &sb) != 0) { |
| 1024 | return false; |
| 1025 | } |
| 1026 | #ifdef _WIN32 |
| 1027 | /* st_ino is unreliable on Windows; compare normalized path strings. */ |
| 1028 | char na[CLI_BUF_1K]; |
| 1029 | char nb[CLI_BUF_1K]; |
| 1030 | snprintf(na, sizeof(na), "%s", a); |
| 1031 | snprintf(nb, sizeof(nb), "%s", b); |
| 1032 | cbm_normalize_path_sep(na); |
| 1033 | cbm_normalize_path_sep(nb); |
| 1034 | return strcmp(na, nb) == 0; |
| 1035 | #else |
| 1036 | return sa.st_dev == sb.st_dev && sa.st_ino == sb.st_ino; |
| 1037 | #endif |
| 1038 | } |
| 1039 | |
| 1040 | typedef struct { |
| 1041 | char fingerprint[CBM_DAEMON_BUILD_FINGERPRINT_SIZE]; |
no test coverage detected