| 804 | } |
| 805 | |
| 806 | static bool windows_log_path_open(const char *log_path, windows_log_path_t *path) { |
| 807 | size_t length = 0; |
| 808 | if (!path || !bounded_length(log_path, sizeof(path->storage), &length) || length == 0 || |
| 809 | length + 5 >= sizeof(path->storage)) { |
| 810 | return false; |
| 811 | } |
| 812 | memset(path, 0, sizeof(*path)); |
| 813 | memcpy(path->storage, log_path, length + 1); |
| 814 | char *forward = strrchr(path->storage, '/'); |
| 815 | char *backward = strrchr(path->storage, '\\'); |
| 816 | char *slash = forward; |
| 817 | if (!slash || (backward && backward > slash)) { |
| 818 | slash = backward; |
| 819 | } |
| 820 | if (!slash || slash == path->storage || slash[1] == '\0') { |
| 821 | return false; |
| 822 | } |
| 823 | path->base = slash + 1; |
| 824 | *slash = '\0'; |
| 825 | size_t base_length = strlen(path->base); |
| 826 | int lock_written = snprintf(path->lock_base, sizeof(path->lock_base), "%s.lock", path->base); |
| 827 | if (base_length == 0 || base_length > 248 || lock_written <= 0 || |
| 828 | (size_t)lock_written >= sizeof(path->lock_base)) { |
| 829 | return false; |
| 830 | } |
| 831 | |
| 832 | path->wide = cbm_path_to_wide(log_path); |
| 833 | if (!path->wide) { |
| 834 | return false; |
| 835 | } |
| 836 | size_t wide_length = wcslen(path->wide); |
| 837 | path->rotated = malloc((wide_length + 3) * sizeof(*path->rotated)); |
| 838 | path->lock = malloc((wide_length + 6) * sizeof(*path->lock)); |
| 839 | if (!path->rotated || !path->lock) { |
| 840 | windows_log_path_close(path); |
| 841 | return false; |
| 842 | } |
| 843 | memcpy(path->rotated, path->wide, wide_length * sizeof(*path->rotated)); |
| 844 | memcpy(path->rotated + wide_length, L".1", 3 * sizeof(*path->rotated)); |
| 845 | memcpy(path->lock, path->wide, wide_length * sizeof(*path->lock)); |
| 846 | memcpy(path->lock + wide_length, L".lock", 6 * sizeof(*path->lock)); |
| 847 | return true; |
| 848 | } |
| 849 | |
| 850 | static bool windows_private_file_prepare(const char *directory, const char *base) { |
| 851 | /* cbm_daemon_ipc_private_log_open supplies the same explicit protected |
no test coverage detected