1 /* 2 Various non-library utilities 3 4 Copyright (C) 2003-2025 5 Free Software Foundation, Inc. 6 7 Written by: 8 Adam Byrtek, 2003 9 Slava Zanko <slavazanko@gmail.com>, 2013 10 11 This file is part of the Midnight Commander. 12 13 The Midnight Commander is free software: you can redistribute it 14 and/or modify it under the terms of the GNU General Public License as 15 published by the Free Software Foundation, either version 3 of the License, 16 or (at your option) any later version. 17 18 The Midnight Commander is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 GNU General Public License for more details. 22 23 You should have received a copy of the GNU General Public License 24 along with this program. If not, see <https://www.gnu.org/licenses/>. 25 */ 26 27 #include <config.h> 28 29 #include <errno.h> 30 31 #include "lib/global.h" 32 #include "lib/util.h" 33 #include "lib/widget.h" 34 35 #include "src/filemanager/file.h" 36 #include "src/filemanager/filegui.h" 37 38 #include "util.h" 39 40 /*** global variables ****************************************************************************/ 41 42 /*** file scope macro definitions ****************************************************************/ 43 44 /*** file scope type declarations ****************************************************************/ 45 46 /*** file scope variables ************************************************************************/ 47 48 /* --------------------------------------------------------------------------------------------- */ 49 /*** file scope functions ************************************************************************/ 50 /* --------------------------------------------------------------------------------------------- */ 51 52 /* --------------------------------------------------------------------------------------------- */ 53 /*** public functions ****************************************************************************/ 54 /* --------------------------------------------------------------------------------------------- */ 55 56 gboolean 57 check_for_default (const vfs_path_t *default_file_vpath, const vfs_path_t *file_vpath) /**/ 58 { 59 if (!exist_file (vfs_path_as_str (file_vpath))) 60 { 61 file_op_context_t *ctx; 62 63 if (!exist_file (vfs_path_as_str (default_file_vpath))) 64 return FALSE; 65 66 ctx = file_op_context_new (OP_COPY); 67 file_progress_ui_create (ctx, 0, FALSE); 68 copy_file_file (ctx, vfs_path_as_str (default_file_vpath), vfs_path_as_str (file_vpath)); 69 file_op_context_destroy (ctx); 70 } 71 72 return TRUE; 73 } 74 75 /* --------------------------------------------------------------------------------------------- */ 76 /** 77 * Report error with one file using errno. Unlike file_error(), this function contains only one 78 * button "OK" and returns nothing. 79 * 80 * @param format printf()-like format for message 81 * @param file file name. Can be NULL. 82 */ 83 84 void 85 file_error_message (const char *format, const char *filename) /*
*/ 86 { 87 const char *error_string = unix_error_string (errno); 88 89 if (filename == NULL || *filename == '\0') 90 message (D_ERROR, MSG_ERROR, "%s\n%s", format, error_string); 91 else 92 { 93 char *full_format; 94 95 full_format = g_strconcat (format, "\n", error_string, (char *) NULL); 96 // delete password and try to show a full path 97 message (D_ERROR, MSG_ERROR, full_format, path_trunc (filename, -1)); 98 g_free (full_format); 99 } 100 } 101 102 /* --------------------------------------------------------------------------------------------- */