Skip to content

Commit 6163584

Browse files
committed
Ticket #4661: show full file name in the file error message box.
* (path_trunc): improve: constify and rename the 2nd argument, add possibility to return non-truncated path by passing -1 as truncation width, update Doxygen comment. Signed-off-by: Andrew Borodin <[email protected]>
1 parent 6b8b45f commit 6163584

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/util.c

+13-5
Original file line numberDiff line numberDiff line change
@@ -301,19 +301,27 @@ fake_name_quote (const char *s, gboolean quote_percent)
301301

302302
/* --------------------------------------------------------------------------------------------- */
303303
/**
304-
* path_trunc() is the same as str_trunc() but
305-
* it deletes possible password from path for security
304+
* path_trunc() is the same as str_trunc() but it deletes possible password from path for security
306305
* reasons.
306+
*
307+
* @param path file path to trancate
308+
* @param trunc_width width (in characters) of truncation result. If -1, full path will be kept.
309+
*
310+
* @returns pointer to trancated path. It points to the internal static buffer, do not call
311+
g_free() to free it.
307312
*/
308313

309314
const char *
310-
path_trunc (const char *path, size_t trunc_len)
315+
path_trunc (const char *path, const size_t trunc_width)
311316
{
312317
vfs_path_t *vpath;
313-
const char *ret;
314318

315319
vpath = vfs_path_from_str_flags (path, VPF_STRIP_PASSWORD);
316-
ret = str_trunc (vfs_path_as_str (vpath), trunc_len);
320+
321+
const char *p = vfs_path_as_str (vpath);
322+
const size_t width = trunc_width == (size_t) (-1) ? (size_t) str_term_width1 (p) : trunc_width;
323+
const char *ret = str_trunc (p, width);
324+
317325
vfs_path_free (vpath, TRUE);
318326

319327
return ret;

lib/util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ char *fake_name_quote (const char *c, gboolean quote_percent);
168168
/* path_trunc() is the same as str_trunc() but
169169
* it deletes possible password from path for security
170170
* reasons. */
171-
const char *path_trunc (const char *path, size_t trunc_len);
171+
const char *path_trunc (const char *path, const size_t trunc_width);
172172

173173
/* return a static string representing size, appending "K" or "M" for
174174
* big sizes.

0 commit comments

Comments
 (0)