updated: [54d6ec8] replaced buggy concat_dir_and_file() by mhl_str_dir_plus_file()
Enrico Weigelt, metux IT service
weigelt at metux.de
Sat Jan 31 17:17:03 UTC 2009
The following commit has been merged in the mc-4.6 branch:
commit 54d6ec88dcb9648d77ae84d063fdaedb76233b39
Author: Enrico Weigelt, metux IT service <weigelt at metux.de>
Date: Sat Jan 31 16:51:58 2009 +0100
replaced buggy concat_dir_and_file() by mhl_str_dir_plus_file()
diff --git a/ChangeLog b/ChangeLog
index 982d31b..9afbd3d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2009-01-31 Enrico Weigelt, metux ITS <weigelt at metux.de>
+
+ * replaced buggy concat_dir_and_file() by mhl_str_dir_plus_file() (in mhl/string.h)
2009-01-30 Enrico Weigelt, metux ITS <weigelt at metux.de>
diff --git a/edit/edit.c b/edit/edit.c
index 8f2bca7..bec84d7 100644
--- a/edit/edit.c
+++ b/edit/edit.c
@@ -30,9 +30,10 @@
#include <ctype.h>
#include <errno.h>
#include <sys/stat.h>
-
#include <stdlib.h>
+#include <mhl/string.h>
+
#include "../src/global.h"
#include "edit.h"
@@ -2665,7 +2666,7 @@ user_menu (WEdit * edit)
int nomark;
struct stat status;
long start_mark, end_mark;
- char *block_file = concat_dir_and_file (home_dir, BLOCK_FILE);
+ char *block_file = mhl_str_dir_plus_file (home_dir, BLOCK_FILE);
int rc = 0;
nomark = eval_marks (edit, &start_mark, &end_mark);
diff --git a/edit/editcmd.c b/edit/editcmd.c
index de8cf79..5b5c7e7 100644
--- a/edit/editcmd.c
+++ b/edit/editcmd.c
@@ -28,7 +28,6 @@
#include <assert.h>
#include <ctype.h>
-
#include <stdio.h>
#include <stdarg.h>
#include <sys/types.h>
@@ -36,9 +35,10 @@
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
-
#include <stdlib.h>
+#include <mhl/string.h>
+
#include "../src/global.h"
#include "../src/history.h"
@@ -235,7 +235,7 @@ edit_save_file (WEdit *edit, const char *filename)
return 0;
if (*filename != PATH_SEP && edit->dir) {
- savename = concat_dir_and_file (edit->dir, filename);
+ savename = mhl_str_dir_plus_file (edit->dir, filename);
filename = catstrs (savename, (char *) NULL);
g_free (savename);
}
@@ -301,7 +301,7 @@ edit_save_file (WEdit *edit, const char *filename)
savedir[slashpos - filename + 1] = '\0';
} else
savedir = g_strdup (".");
- saveprefix = concat_dir_and_file (savedir, "cooledit");
+ saveprefix = mhl_str_dir_plus_file (savedir, "cooledit");
g_free (savedir);
fd = mc_mkstemps (&savename, saveprefix, NULL);
g_free (saveprefix);
diff --git a/edit/editwidget.c b/edit/editwidget.c
index 2b248a0..8ae8cf0 100644
--- a/edit/editwidget.c
+++ b/edit/editwidget.c
@@ -33,9 +33,10 @@
#include <ctype.h>
#include <errno.h>
#include <sys/stat.h>
-
#include <stdlib.h>
+#include <mhl/string.h>
+
#include "../src/global.h"
#include "edit.h"
@@ -174,7 +175,7 @@ edit_file (const char *_file, int line)
WButtonBar *edit_bar;
if (!made_directory) {
- char *dir = concat_dir_and_file (home_dir, EDIT_DIR);
+ char *dir = mhl_str_dir_plus_file (home_dir, EDIT_DIR);
made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
g_free (dir);
}
diff --git a/edit/syntax.c b/edit/syntax.c
index 23e8b6c..2cfe976 100644
--- a/edit/syntax.c
+++ b/edit/syntax.c
@@ -30,9 +30,10 @@
#include <ctype.h>
#include <errno.h>
#include <sys/stat.h>
-
#include <stdlib.h>
+#include <mhl/string.h>
+
#include "../src/global.h"
#include "edit.h"
@@ -1026,7 +1027,7 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
f = fopen (syntax_file, "r");
if (!f){
- lib_file = concat_dir_and_file (mc_home, "syntax" PATH_SEP_STR "Syntax");
+ lib_file = mhl_str_dir_plus_file (mc_home, "syntax" PATH_SEP_STR "Syntax");
f = fopen (lib_file, "r");
g_free (lib_file);
if (!f)
@@ -1188,7 +1189,7 @@ edit_load_syntax (WEdit *edit, char ***pnames, const char *type)
if (!*edit->filename && !type)
return;
}
- f = concat_dir_and_file (home_dir, SYNTAX_FILE);
+ f = mhl_str_dir_plus_file (home_dir, SYNTAX_FILE);
r = edit_read_syntax_file (edit, pnames, f, edit ? edit->filename : 0,
get_first_editor_line (edit), type);
if (r == -1) {
diff --git a/edit/usermap.c b/edit/usermap.c
index af0f023..ebb6880 100644
--- a/edit/usermap.c
+++ b/edit/usermap.c
@@ -26,11 +26,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <mhl/string.h>
+
#include "../src/global.h"
#include "edit.h"
@@ -596,7 +597,7 @@ edit_load_user_map(WEdit *edit)
if (edit_key_emulation != EDIT_KEY_EMULATION_USER)
return TRUE;
- file = concat_dir_and_file(home_dir, MC_USERMAP);
+ file = mhl_str_dir_plus_file(home_dir, MC_USERMAP);
if (stat(file, &s) < 0) {
char *msg = g_strdup_printf(_("%s not found!"), file);
diff --git a/mhl/string.h b/mhl/string.h
index c50228d..6f2bdb3 100644
--- a/mhl/string.h
+++ b/mhl/string.h
@@ -121,4 +121,37 @@ static inline char* mhl_str_reverse(char* ptr)
return ptr;
}
+static inline char* mhl_str_dir_plus_file(const char* dirname, const char* filename)
+{
+ /* make sure we have valid strings */
+ if (!dirname)
+ dirname="";
+
+ if (!filename)
+ filename="";
+
+ /* skip leading slashes on filename */
+ while (*filename == '/')
+ filename++;
+
+ /* skip trailing slashes on dirname */
+ int dnlen = strlen(dirname);
+ while (dnlen && (dirname[dnlen-1]=='/'))
+ dnlen--;
+
+ int fnlen = strlen(filename);
+ char* buffer = mhl_mem_alloc_z(dnlen+fnlen+2); /* enough space for dirname, /, filename, zero */
+ char* ptr = buffer;
+
+ memcpy(ptr, dirname, dnlen);
+ ptr+=dnlen;
+ *ptr = '/';
+ ptr++;
+ memcpy(ptr, filename, fnlen);
+ ptr+=fnlen;
+ *ptr = 0;
+
+ return buffer;
+}
+
#endif /* __MHL_STRING_H */
diff --git a/src/charsets.c b/src/charsets.c
index 5666c23..da94853 100644
--- a/src/charsets.c
+++ b/src/charsets.c
@@ -48,7 +48,7 @@ load_codepages_list (void)
extern int display_codepage;
char *default_codepage = NULL;
- fname = concat_dir_and_file (mc_home, CHARSETS_INDEX);
+ fname = mhl_str_dir_plus_file (mc_home, CHARSETS_INDEX);
if (!(f = fopen (fname, "r"))) {
fprintf (stderr, _("Warning: file %s not found\n"), fname);
g_free (fname);
diff --git a/src/cmd.c b/src/cmd.c
index 7892bd3..f82165c 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -34,6 +34,8 @@
#endif
#include <unistd.h>
+#include <mhl/string.h>
+
#include "global.h"
#include "cmd.h" /* Our definitions */
#include "fileopctx.h" /* file_op_context_new() */
@@ -362,7 +364,7 @@ mkdir_cmd (void)
if (dir[0] == '/' || dir[0] == '~')
absdir = g_strdup (dir);
else
- absdir = concat_dir_and_file (current_panel->cwd, dir);
+ absdir = mhl_str_dir_plus_file (current_panel->cwd, dir);
save_cwds_stat ();
if (my_mkdir (absdir, 0777) == 0) {
@@ -568,10 +570,10 @@ void ext_cmd (void)
_(" Which extension file you want to edit? "), 0, 2,
_("&User"), _("&System Wide"));
}
- extdir = concat_dir_and_file (mc_home, MC_LIB_EXT);
+ extdir = mhl_str_dir_plus_file (mc_home, MC_LIB_EXT);
if (dir == 0){
- buffer = concat_dir_and_file (home_dir, MC_USER_EXT);
+ buffer = mhl_str_dir_plus_file (home_dir, MC_USER_EXT);
check_for_default (extdir, buffer);
do_edit (buffer);
g_free (buffer);
@@ -598,7 +600,7 @@ menu_edit_cmd (int where)
_("&Local"), _("&User"), _("&System Wide")
);
- menufile = concat_dir_and_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
+ menufile = mhl_str_dir_plus_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
switch (dir) {
case 0:
@@ -607,12 +609,12 @@ menu_edit_cmd (int where)
break;
case 1:
- buffer = concat_dir_and_file (home_dir, where ? CEDIT_HOME_MENU : MC_HOME_MENU);
+ buffer = mhl_str_dir_plus_file (home_dir, where ? CEDIT_HOME_MENU : MC_HOME_MENU);
check_for_default (menufile, buffer);
break;
case 2:
- buffer = concat_dir_and_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
+ buffer = mhl_str_dir_plus_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
break;
default:
@@ -671,10 +673,10 @@ edit_syntax_cmd (void)
_(" Which syntax file you want to edit? "), 0, 2,
_("&User"), _("&System Wide"));
}
- extdir = concat_dir_and_file (mc_home, "syntax" PATH_SEP_STR "Syntax");
+ extdir = mhl_str_dir_plus_file (mc_home, "syntax" PATH_SEP_STR "Syntax");
if (dir == 0) {
- buffer = concat_dir_and_file (home_dir, SYNTAX_FILE);
+ buffer = mhl_str_dir_plus_file (home_dir, SYNTAX_FILE);
check_for_default (extdir, buffer);
do_edit (buffer);
g_free (buffer);
@@ -805,8 +807,8 @@ compare_dir (WPanel *panel, WPanel *other, enum CompareMode mode)
}
/* Thorough compare on, do byte-by-byte comparison */
- src_name = concat_dir_and_file (panel->cwd, source->fname);
- dst_name = concat_dir_and_file (other->cwd, target->fname);
+ src_name = mhl_str_dir_plus_file (panel->cwd, source->fname);
+ dst_name = mhl_str_dir_plus_file (other->cwd, target->fname);
if (compare_files (src_name, dst_name, source->st.st_size))
do_file_mark (panel, i, 1);
g_free (src_name);
@@ -920,10 +922,10 @@ do_link (int symbolic_link, const char *fname)
char *d;
/* suggest the full path for symlink */
- s = concat_dir_and_file (current_panel->cwd, fname);
+ s = mhl_str_dir_plus_file (current_panel->cwd, fname);
if (get_other_type () == view_listing) {
- d = concat_dir_and_file (other_panel->cwd, fname);
+ d = mhl_str_dir_plus_file (other_panel->cwd, fname);
} else {
d = g_strdup (fname);
}
diff --git a/src/command.c b/src/command.c
index b204b8d..ec11dcf 100644
--- a/src/command.c
+++ b/src/command.c
@@ -27,6 +27,8 @@
#include <errno.h>
#include <string.h>
+#include <mhl/string.h>
+
#include "global.h" /* home_dir */
#include "tty.h"
#include "widget.h" /* WInput */
@@ -124,7 +126,7 @@ examine_cd (char *path)
c = *s;
*s = 0;
if (*p) {
- r = concat_dir_and_file (p, q);
+ r = mhl_str_dir_plus_file (p, q);
result = do_cd (r, cd_parse_command);
g_free (r);
}
@@ -176,7 +178,7 @@ void do_cd_command (char *cmd)
} else {
char *old = current_panel->cwd;
char *new;
- new = concat_dir_and_file (old, cmd+3);
+ new = mhl_str_dir_plus_file (old, cmd+3);
sync_tree (new);
g_free (new);
}
diff --git a/src/complete.c b/src/complete.c
index 1742b85..2d13c57 100644
--- a/src/complete.c
+++ b/src/complete.c
@@ -26,11 +26,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <mhl/string.h>
+
#include "global.h"
#include "tty.h"
#include "win.h"
@@ -474,7 +475,7 @@ command_completion_function (char *text, int state)
if (cur_path >= path_end)
break;
expanded = tilde_expand (*cur_path ? cur_path : ".");
- cur_word = concat_dir_and_file (expanded, text);
+ cur_word = mhl_str_dir_plus_file (expanded, text);
g_free (expanded);
canonicalize_pathname (cur_word);
cur_path = strchr (cur_path, 0) + 1;
@@ -740,7 +741,7 @@ try_complete (char *text, int *start, int *end, int flags)
c = *s;
*s = 0;
if (*cdpath){
- r = concat_dir_and_file (cdpath, word);
+ r = mhl_str_dir_plus_file (cdpath, word);
ignore_filenames = 1;
matches = completion_matches (r, filename_completion_function);
ignore_filenames = 0;
diff --git a/src/cons.handler.c b/src/cons.handler.c
index b08c266..1fe35b0 100644
--- a/src/cons.handler.c
+++ b/src/cons.handler.c
@@ -28,6 +28,8 @@
#endif
#include <unistd.h>
+#include <mhl/string.h>
+
#include "global.h"
#include "tty.h"
#include "cons.saver.h"
@@ -143,7 +145,7 @@ handle_console_linux (unsigned char action)
open ("/dev/null", O_WRONLY);
if (tty_name) {
/* Exec the console save/restore handler */
- mc_conssaver = concat_dir_and_file (SAVERDIR, "cons.saver");
+ mc_conssaver = mhl_str_dir_plus_file (SAVERDIR, "cons.saver");
execl (mc_conssaver, "cons.saver", tty_name, (char *) NULL);
}
/* Console is not a tty or execl() failed */
diff --git a/src/cons.saver.c b/src/cons.saver.c
index ccd0647..7086cd6 100644
--- a/src/cons.saver.c
+++ b/src/cons.saver.c
@@ -53,6 +53,8 @@
#endif
#include <unistd.h>
+#include <mhl/string.h>
+
#define LINUX_CONS_SAVER_C
#include "cons.saver.h"
diff --git a/src/ext.c b/src/ext.c
index a4468bd..a0bee25 100644
--- a/src/ext.c
+++ b/src/ext.c
@@ -25,9 +25,10 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
-
#include <unistd.h>
+#include <mhl/string.h>
+
#include "global.h"
#include "tty.h"
#include "user.h"
@@ -440,11 +441,11 @@ regex_command (const char *filename, const char *action, int *move_dir)
int mc_user_ext = 1;
int home_error = 0;
- extension_file = concat_dir_and_file (home_dir, MC_USER_EXT);
+ extension_file = mhl_str_dir_plus_file (home_dir, MC_USER_EXT);
if (!exist_file (extension_file)) {
g_free (extension_file);
check_stock_mc_ext:
- extension_file = concat_dir_and_file (mc_home, MC_LIB_EXT);
+ extension_file = mhl_str_dir_plus_file (mc_home, MC_LIB_EXT);
mc_user_ext = 0;
}
data = load_file (extension_file);
diff --git a/src/file.c b/src/file.c
index b8d54e7..de91806 100644
--- a/src/file.c
+++ b/src/file.c
@@ -913,7 +913,7 @@ copy_dir_dir (FileOpContext *ctx, const char *s, const char *d, int toplevel,
}
/* Dive into subdir if exists */
if (toplevel && ctx->dive_into_subdirs) {
- dest_dir = concat_dir_and_file (d, x_basename (s));
+ dest_dir = mhl_str_dir_plus_file (d, x_basename (s));
} else {
dest_dir = g_strdup (d);
goto dont_mkdir;
@@ -959,11 +959,11 @@ copy_dir_dir (FileOpContext *ctx, const char *s, const char *d, int toplevel,
continue;
/* get the filename and add it to the src directory */
- path = concat_dir_and_file (s, next->d_name);
+ path = mhl_str_dir_plus_file (s, next->d_name);
(*ctx->stat_func) (path, &buf);
if (S_ISDIR (buf.st_mode)) {
- mdpath = concat_dir_and_file (dest_dir, next->d_name);
+ mdpath = mhl_str_dir_plus_file (dest_dir, next->d_name);
/*
* From here, we just intend to recursively copy subdirs, not
* the double functionality of copying different when the target
@@ -974,7 +974,7 @@ copy_dir_dir (FileOpContext *ctx, const char *s, const char *d, int toplevel,
parent_dirs, progress_count, progress_bytes);
g_free (mdpath);
} else {
- dest_file = concat_dir_and_file (dest_dir, x_basename (path));
+ dest_file = mhl_str_dir_plus_file (dest_dir, x_basename (path));
return_status = copy_file_file (ctx, path, dest_file, 1,
progress_count, progress_bytes, 0);
g_free (dest_file);
@@ -1164,7 +1164,7 @@ move_dir_dir (FileOpContext *ctx, const char *s, const char *d,
destdir = g_strdup (d);
move_over = 1;
} else
- destdir = concat_dir_and_file (d, x_basename (s));
+ destdir = mhl_str_dir_plus_file (d, x_basename (s));
if (sbuf.st_dev == dbuf.st_dev && sbuf.st_ino == dbuf.st_ino) {
int msize = COLS - 36;
@@ -1321,7 +1321,7 @@ recursive_erase (FileOpContext *ctx, const char *s, off_t *progress_count,
continue;
if (!strcmp (next->d_name, ".."))
continue;
- path = concat_dir_and_file (s, next->d_name);
+ path = mhl_str_dir_plus_file (s, next->d_name);
if (mc_lstat (path, &buf)) {
g_free (path);
mc_closedir (reading);
@@ -1512,7 +1512,7 @@ compute_dir_size (const char *dirname, off_t *ret_marked, double *ret_total)
if (strcmp (dirent->d_name, "..") == 0)
continue;
- fullname = concat_dir_and_file (dirname, dirent->d_name);
+ fullname = mhl_str_dir_plus_file (dirname, dirent->d_name);
res = mc_lstat (fullname, &s);
@@ -1569,7 +1569,7 @@ panel_compute_totals (WPanel *panel, off_t *ret_marked, double *ret_total)
double subdir_bytes = 0;
dir_name =
- concat_dir_and_file (panel->cwd, panel->dir.list[i].fname);
+ mhl_str_dir_plus_file (panel->cwd, panel->dir.list[i].fname);
compute_dir_size (dir_name, &subdir_count, &subdir_bytes);
*ret_marked += subdir_count;
@@ -1877,7 +1877,7 @@ panel_operate (void *source_panel, FileOperation operation,
/* The source and src_stat variables have been initialized before */
#ifdef WITH_FULL_PATHS
- source_with_path = concat_dir_and_file (panel->cwd, source);
+ source_with_path = mhl_str_dir_plus_file (panel->cwd, source);
#endif /* WITH_FULL_PATHS */
if (operation == OP_DELETE) {
@@ -1892,7 +1892,7 @@ panel_operate (void *source_panel, FileOperation operation,
if (temp == NULL) {
value = transform_error;
} else {
- char *temp2 = concat_dir_and_file (dest, temp);
+ char *temp2 = mhl_str_dir_plus_file (dest, temp);
g_free (dest);
dest = temp2;
temp = NULL;
@@ -1970,7 +1970,7 @@ panel_operate (void *source_panel, FileOperation operation,
#ifdef WITH_FULL_PATHS
g_free (source_with_path);
- source_with_path = concat_dir_and_file (panel->cwd, source);
+ source_with_path = mhl_str_dir_plus_file (panel->cwd, source);
#endif /* WITH_FULL_PATHS */
if (operation == OP_DELETE) {
@@ -1986,7 +1986,7 @@ panel_operate (void *source_panel, FileOperation operation,
if (temp == NULL)
value = transform_error;
else {
- char *temp2 = concat_dir_and_file (dest, temp);
+ char *temp2 = mhl_str_dir_plus_file (dest, temp);
switch (operation) {
case OP_COPY:
diff --git a/src/filenot.c b/src/filenot.c
index f614ce1..01e0d78 100644
--- a/src/filenot.c
+++ b/src/filenot.c
@@ -27,6 +27,8 @@
#include <errno.h>
#include <string.h>
+#include <mhl/string.h>
+
#include "global.h"
static char *
@@ -37,7 +39,7 @@ get_absolute_name (const char *file)
if (file[0] == PATH_SEP)
return g_strdup (file);
mc_get_current_wd (dir, MC_MAXPATHLEN);
- return concat_dir_and_file (dir, file);
+ return mhl_str_dir_plus_file (dir, file);
}
static int
@@ -60,7 +62,7 @@ my_mkdir_rec (char *s, mode_t mode)
return -1;
}
- p = concat_dir_and_file (s, "..");
+ p = mhl_str_dir_plus_file (s, "..");
q = vfs_canon (p);
g_free (p);
diff --git a/src/find.c b/src/find.c
index baf1504..95103f1 100644
--- a/src/find.c
+++ b/src/find.c
@@ -25,9 +25,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
#include <sys/stat.h>
+#include <mhl/string.h>
+
#include "global.h"
#include "tty.h"
#include "win.h"
@@ -354,7 +355,7 @@ push_directory (const char *dir)
dir_stack *new;
new = g_new (dir_stack, 1);
- new->name = concat_dir_and_file (dir, "");
+ new->name = mhl_str_dir_plus_file (dir, NULL);
new->prev = dir_stack_base;
dir_stack_base = new;
}
@@ -516,7 +517,7 @@ search_content (Dlg_head *h, const char *directory, const char *filename)
int file_fd;
int ret_val = 0;
- fname = concat_dir_and_file (directory, filename);
+ fname = mhl_str_dir_plus_file (directory, filename);
if (mc_stat (fname, &s) != 0 || !S_ISREG (s.st_mode)){
g_free (fname);
@@ -692,7 +693,7 @@ do_search (struct Dlg_head *h)
}
if (subdirs_left && find_recursively && directory) { /* Can directory be NULL ? */
- char *tmp_name = concat_dir_and_file (directory, dp->d_name);
+ char *tmp_name = mhl_str_dir_plus_file (directory, dp->d_name);
if (!mc_lstat (tmp_name, &tmp_stat)
&& S_ISDIR (tmp_stat.st_mode)) {
push_directory (tmp_name);
@@ -752,8 +753,8 @@ make_fullname (const char *dirname, const char *filename)
if (strcmp(dirname, ".") == 0 || strcmp(dirname, "."PATH_SEP_STR) == 0)
return g_strdup (filename);
if (strncmp(dirname, "."PATH_SEP_STR, 2) == 0)
- return concat_dir_and_file (dirname + 2, filename);
- return concat_dir_and_file (dirname, filename);
+ return mhl_str_dir_plus_file (dirname + 2, filename);
+ return mhl_str_dir_plus_file (dirname, filename);
}
static void
diff --git a/src/hotlist.c b/src/hotlist.c
index 90678fe..737c9c1 100644
--- a/src/hotlist.c
+++ b/src/hotlist.c
@@ -32,11 +32,12 @@
#include <ctype.h>
#include <stdio.h>
#include <string.h>
-
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <mhl/string.h>
+
#include "global.h"
#include "tty.h" /* COLS */
#include "color.h" /* dialog_colors */
@@ -1447,7 +1448,7 @@ load_hotlist (void)
}
if (!hotlist_file_name)
- hotlist_file_name = concat_dir_and_file (home_dir, HOTLIST_FILENAME);
+ hotlist_file_name = mhl_str_dir_plus_file (home_dir, HOTLIST_FILENAME);
hotlist = new_hotlist ();
hotlist->type = HL_TYPE_GROUP;
diff --git a/src/main.c b/src/main.c
index f323905..f1a78b0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,11 +29,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <mhl/string.h>
+
#include "global.h"
#include "tty.h"
#include "dir.h"
@@ -1137,7 +1138,7 @@ copy_readlink (WPanel *panel)
if (S_ISLNK (selection (panel)->st.st_mode)) {
char buffer[MC_MAXPATHLEN];
char *p =
- concat_dir_and_file (panel->cwd, selection (panel)->fname);
+ mhl_str_dir_plus_file (panel->cwd, selection (panel)->fname);
int i;
i = mc_readlink (p, buffer, MC_MAXPATHLEN - 1);
diff --git a/src/screen.c b/src/screen.c
index d1121d8..6c3821b 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -25,9 +25,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
#include <unistd.h>
+#include <mhl/string.h>
+
#include "global.h"
#include "tty.h"
#include "dir.h"
@@ -709,7 +710,7 @@ display_mini_info (WPanel *panel)
char *link, link_target [MC_MAXPATHLEN];
int len;
- link = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
+ link = mhl_str_dir_plus_file (panel->cwd, panel->dir.list [panel->selected].fname);
len = mc_readlink (link, link_target, MC_MAXPATHLEN - 1);
g_free (link);
if (len > 0){
@@ -1974,7 +1975,7 @@ do_enter_on_file_entry (file_entry *fe)
return 1;
/* Check if the file is executable */
- full_name = concat_dir_and_file (current_panel->cwd, fe->fname);
+ full_name = mhl_str_dir_plus_file (current_panel->cwd, fe->fname);
if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe)) {
g_free (full_name);
return 0;
@@ -1993,7 +1994,7 @@ do_enter_on_file_entry (file_entry *fe)
char *tmp;
int ret;
- tmp = concat_dir_and_file (vfs_get_current_dir (), fe->fname);
+ tmp = mhl_str_dir_plus_file (vfs_get_current_dir (), fe->fname);
ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL);
g_free (tmp);
/* We took action only if the dialog was shown or the execution
@@ -2030,10 +2031,10 @@ chdir_other_panel (WPanel *panel)
}
if (!S_ISDIR (panel->dir.list [panel->selected].st.st_mode)) {
- new_dir = concat_dir_and_file (panel->cwd, "..");
+ new_dir = mhl_str_dir_plus_file (panel->cwd, "..");
sel_entry = strrchr(panel->cwd, PATH_SEP);
} else
- new_dir = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
+ new_dir = mhl_str_dir_plus_file (panel->cwd, panel->dir.list [panel->selected].fname);
change_panel ();
do_cd (new_dir, cd_exact);
@@ -2099,7 +2100,7 @@ chdir_to_readlink (WPanel *panel)
if (*buffer == PATH_SEP)
new_dir = g_strdup (buffer);
else
- new_dir = concat_dir_and_file (panel->cwd, buffer);
+ new_dir = mhl_str_dir_plus_file (panel->cwd, buffer);
change_panel ();
do_cd (new_dir, cd_exact);
diff --git a/src/setup.c b/src/setup.c
index ef42496..67dec4a 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -20,10 +20,11 @@
#include <string.h>
#include <stdio.h>
-
#include <sys/types.h>
#include <sys/stat.h>
+#include <mhl/string.h>
+
#include "global.h"
#include "tty.h"
#include "dir.h"
@@ -281,7 +282,7 @@ save_layout (void)
int i;
char buffer [BUF_TINY];
- profile = concat_dir_and_file (home_dir, PROFILE_NAME);
+ profile = mhl_str_dir_plus_file (home_dir, PROFILE_NAME);
/* Save integer options */
for (i = 0; layout [i].opt_name; i++){
@@ -298,7 +299,7 @@ save_configure (void)
char *profile;
int i;
- profile = concat_dir_and_file (home_dir, PROFILE_NAME);
+ profile = mhl_str_dir_plus_file (home_dir, PROFILE_NAME);
/* Save integer options */
for (i = 0; int_options[i].opt_name; i++)
@@ -346,7 +347,7 @@ save_setup (void)
char *profile;
saving_setup = 1;
- profile = concat_dir_and_file (home_dir, PROFILE_NAME);
+ profile = mhl_str_dir_plus_file (home_dir, PROFILE_NAME);
save_configure ();
@@ -481,9 +482,9 @@ setup_init (void)
if (profile_name)
return profile_name;
- profile = concat_dir_and_file (home_dir, PROFILE_NAME);
+ profile = mhl_str_dir_plus_file (home_dir, PROFILE_NAME);
if (!exist_file (profile)){
- inifile = concat_dir_and_file (mc_home, "mc.ini");
+ inifile = mhl_str_dir_plus_file (mc_home, "mc.ini");
if (exist_file (inifile)){
g_free (profile);
profile = inifile;
@@ -506,7 +507,7 @@ load_setup (void)
/* mc.lib is common for all users, but has priority lower than
~/.mc/ini. FIXME: it's only used for keys and treestore now */
- global_profile_name = concat_dir_and_file (mc_home, "mc.lib");
+ global_profile_name = mhl_str_dir_plus_file (mc_home, "mc.lib");
/* Load integer boolean options */
for (i = 0; int_options[i].opt_name; i++)
diff --git a/src/treestore.c b/src/treestore.c
index 426b0c2..323b891 100644
--- a/src/treestore.c
+++ b/src/treestore.c
@@ -37,11 +37,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <mhl/string.h>
+
#include "global.h"
#include "treestore.h"
#include "profile.h"
@@ -265,7 +266,7 @@ tree_store_load(void)
char *name;
int retval;
- name = concat_dir_and_file(home_dir, MC_TREE);
+ name = mhl_str_dir_plus_file(home_dir, MC_TREE);
retval = tree_store_load_from(name);
g_free(name);
@@ -371,7 +372,7 @@ tree_store_save(void)
char *name;
int retval;
- tmp = concat_dir_and_file(home_dir, MC_TREE_TMP);
+ tmp = mhl_str_dir_plus_file(home_dir, MC_TREE_TMP);
retval = tree_store_save_to(tmp);
if (retval) {
@@ -379,7 +380,7 @@ tree_store_save(void)
return retval;
}
- name = concat_dir_and_file(home_dir, MC_TREE);
+ name = mhl_str_dir_plus_file(home_dir, MC_TREE);
retval = rename(tmp, name);
g_free(tmp);
@@ -605,7 +606,7 @@ tree_store_mark_checked(const char *subname)
if (ts.check_name[0] == PATH_SEP && ts.check_name[1] == 0)
name = g_strconcat(PATH_SEP_STR, subname, (char *) NULL);
else
- name = concat_dir_and_file(ts.check_name, subname);
+ name = mhl_str_dir_plus_file(ts.check_name, subname);
/* Search for the subdirectory */
current = ts.check_start;
@@ -795,7 +796,7 @@ tree_store_rescan(const char *dir)
continue;
}
- full_name = concat_dir_and_file(dir, dp->d_name);
+ full_name = mhl_str_dir_plus_file(dir, dp->d_name);
if (mc_lstat(full_name, &buf) != -1) {
if (S_ISDIR(buf.st_mode))
tree_store_mark_checked(dp->d_name);
diff --git a/src/user.c b/src/user.c
index 7cb617c..49e5d06 100644
--- a/src/user.c
+++ b/src/user.c
@@ -23,6 +23,8 @@
#include <stdio.h>
#include <string.h>
+#include <mhl/string.h>
+
#include "global.h"
#include "tty.h"
#include "color.h"
@@ -721,11 +723,11 @@ user_menu_cmd (struct WEdit *edit_widget)
menu = g_strdup (edit_widget ? CEDIT_LOCAL_MENU : MC_LOCAL_MENU);
if (!exist_file (menu) || !menu_file_own (menu)){
g_free (menu);
- menu = concat_dir_and_file \
+ menu = mhl_str_dir_plus_file \
(home_dir, edit_widget ? CEDIT_HOME_MENU : MC_HOME_MENU);
if (!exist_file (menu)){
g_free (menu);
- menu = concat_dir_and_file \
+ menu = mhl_str_dir_plus_file \
(mc_home, edit_widget ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
}
}
diff --git a/src/util.c b/src/util.c
index edc759a..0b4a7ef 100644
--- a/src/util.c
+++ b/src/util.c
@@ -35,6 +35,8 @@
#include <sys/stat.h>
#include <unistd.h>
+#include <mhl/string.h>
+
#include "global.h"
#include "profile.h"
#include "main.h" /* mc_home */
@@ -686,7 +688,7 @@ load_mc_home_file (const char *filename, char **allocated_filename)
char *lang;
char *data;
- hintfile_base = concat_dir_and_file (mc_home, filename);
+ hintfile_base = mhl_str_dir_plus_file (mc_home, filename);
lang = guess_message_value ();
hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL);
@@ -1245,18 +1247,6 @@ diff_two_paths (const char *first, const char *second)
return buf;
}
-/* If filename is NULL, then we just append PATH_SEP to the dir */
-char *
-concat_dir_and_file (const char *dir, const char *file)
-{
- int i = strlen (dir);
-
- if (dir [i-1] == PATH_SEP)
- return g_strconcat (dir, file, (char *) NULL);
- else
- return g_strconcat (dir, PATH_SEP_STR, file, (char *) NULL);
-}
-
/* Append text to GList, remove all entries with the same text */
GList *
list_append_unique (GList *list, char *text)
@@ -1317,7 +1307,7 @@ mc_mkstemps (char **pname, const char *prefix, const char *suffix)
if (strchr (prefix, PATH_SEP) == NULL) {
/* Add prefix first to find the position of XXXXXX */
- tmpbase = concat_dir_and_file (mc_tmpdir (), prefix);
+ tmpbase = mhl_str_dir_plus_file (mc_tmpdir (), prefix);
} else {
tmpbase = g_strdup (prefix);
}
@@ -1385,7 +1375,7 @@ load_file_position (const char *filename, long *line, long *column)
*column = 0;
/* open file with positions */
- fn = concat_dir_and_file (home_dir, MC_FILEPOS);
+ fn = mhl_str_dir_plus_file (home_dir, MC_FILEPOS);
f = fopen (fn, "r");
g_free (fn);
if (!f)
@@ -1432,8 +1422,8 @@ save_file_position (const char *filename, long line, long column)
len = strlen (filename);
- tmp = concat_dir_and_file (home_dir, MC_FILEPOS_TMP);
- fn = concat_dir_and_file (home_dir, MC_FILEPOS);
+ tmp = mhl_str_dir_plus_file (home_dir, MC_FILEPOS_TMP);
+ fn = mhl_str_dir_plus_file (home_dir, MC_FILEPOS);
/* open temporary file */
t = fopen (tmp, "w");
diff --git a/src/util.h b/src/util.h
index 4e9a113..0cf2099 100644
--- a/src/util.h
+++ b/src/util.h
@@ -66,7 +66,6 @@ char *strip_password (char *path, int has_prefix);
const char *strip_home_and_password (const char *dir);
const char *extension (const char *);
-char *concat_dir_and_file (const char *dir, const char *file);
const char *unix_error_string (int error_num);
const char *skip_separators (const char *s);
const char *skip_numbers (const char *s);
diff --git a/src/widget.c b/src/widget.c
index 83f3169..59392ea 100644
--- a/src/widget.c
+++ b/src/widget.c
@@ -32,9 +32,10 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
-
#include <sys/types.h>
+#include <mhl/string.h>
+
#include "global.h"
#include "tty.h"
#include "color.h"
@@ -866,7 +867,7 @@ history_get (const char *input_name)
return NULL;
if (!*input_name)
return NULL;
- profile = concat_dir_and_file (home_dir, HISTORY_FILE_NAME);
+ profile = mhl_str_dir_plus_file (home_dir, HISTORY_FILE_NAME);
for (i = 0;; i++) {
char key_name[BUF_TINY];
char this_entry[BUF_LARGE];
@@ -904,7 +905,7 @@ history_put (const char *input_name, GList *h)
if (!num_history_items_recorded) /* this is how to disable */
return;
- profile = concat_dir_and_file (home_dir, HISTORY_FILE_NAME);
+ profile = mhl_str_dir_plus_file (home_dir, HISTORY_FILE_NAME);
if ((i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) != -1)
close (i);
diff --git a/vfs/extfs.c b/vfs/extfs.c
index d634e33..03bbf25 100644
--- a/vfs/extfs.c
+++ b/vfs/extfs.c
@@ -35,6 +35,9 @@
#include <sys/wait.h>
#endif
#include <errno.h>
+
+#include <mhl/string.h>
+
#include "../src/global.h"
#include "../src/tty.h" /* enable/disable interrupt key */
#include "../src/wtools.h" /* message() */
@@ -246,7 +249,7 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc)
tmp = name_quote (name, 0);
}
- mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
+ mc_extfsdir = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR);
cmd =
g_strconcat (mc_extfsdir, extfs_prefixes[fstype], " list ",
local_name ? local_name : tmp, (char *) NULL);
@@ -621,7 +624,7 @@ extfs_cmd (const char *extfs_cmd, struct archive *archive,
archive_name = name_quote (extfs_get_archive_name (archive), 0);
quoted_localname = name_quote (localname, 0);
- mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
+ mc_extfsdir = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR);
cmd = g_strconcat (mc_extfsdir, extfs_prefixes[archive->fstype],
extfs_cmd, archive_name, " ", quoted_file, " ",
quoted_localname, (char *) NULL);
@@ -650,7 +653,7 @@ extfs_run (struct vfs_class *me, const char *file)
g_free (p);
archive_name = name_quote (extfs_get_archive_name (archive), 0);
- mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
+ mc_extfsdir = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR);
cmd = g_strconcat (mc_extfsdir, extfs_prefixes[archive->fstype],
" run ", archive_name, " ", q, (char *) NULL);
g_free (mc_extfsdir);
@@ -1295,7 +1298,7 @@ static int extfs_init (struct vfs_class *me)
(void) me;
- mc_extfsini = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR "extfs.ini");
+ mc_extfsini = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR "extfs.ini");
cfg = fopen (mc_extfsini, "r");
/* We may not use vfs_die() message or message or similar,
diff --git a/vfs/ftpfs.c b/vfs/ftpfs.c
index 5d8ac1f..68f6967 100644
--- a/vfs/ftpfs.c
+++ b/vfs/ftpfs.c
@@ -44,7 +44,7 @@ What to do with this?
int f = !strcmp( remote_path, "/~" );
if (f || !strncmp( remote_path, "/~/", 3 )) {
char *s;
- s = concat_dir_and_file( qhome (*bucket), remote_path +3-f );
+ s = mhl_str_dir_plus_file( qhome (*bucket), remote_path +3-f );
g_free (remote_path);
remote_path = s;
}
@@ -69,6 +69,8 @@ What to do with this?
#include <errno.h>
#include <ctype.h>
+#include <mhl/string.h>
+
#include "../src/global.h"
#include "../src/tty.h" /* enable/disable interrupt key */
#include "../src/wtools.h" /* message() */
@@ -555,7 +557,7 @@ ftpfs_load_no_proxy_list (void)
if (mc_file)
return;
- mc_file = concat_dir_and_file (mc_home, "mc.no_proxy");
+ mc_file = mhl_str_dir_plus_file (mc_home, "mc.no_proxy");
if (exist_file (mc_file) &&
(npf = fopen (mc_file, "r"))) {
while (fgets (s, sizeof (s), npf)) {
@@ -1230,7 +1232,7 @@ ftpfs_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path
ftpfs_open_data_connection (me, super, "LIST -la", 0, TYPE_ASCII, 0);
else {
/* Trailing "/." is necessary if remote_path is a symlink */
- char *path = concat_dir_and_file (remote_path, ".");
+ char *path = mhl_str_dir_plus_file (remote_path, ".");
sock =
ftpfs_open_data_connection (me, super, "LIST -la", path, TYPE_ASCII,
0);
@@ -1886,7 +1888,7 @@ static int ftpfs_netrc_lookup (const char *host, char **login, char **pass)
}
/* Load current .netrc */
- netrcname = concat_dir_and_file (home_dir, ".netrc");
+ netrcname = mhl_str_dir_plus_file (home_dir, ".netrc");
netrcp = netrc = load_file (netrcname);
if (netrc == NULL) {
g_free (netrcname);
diff --git a/vfs/gc.c b/vfs/gc.c
index a0376d8..8da8946 100644
--- a/vfs/gc.c
+++ b/vfs/gc.c
@@ -31,6 +31,8 @@
#include <signal.h>
#include <ctype.h> /* is_digit() */
+#include <mhl/string.h>
+
#include "../src/global.h"
#include "../src/tty.h" /* enable/disable interrupt key */
#include "../src/wtools.h" /* message() */
@@ -122,7 +124,7 @@ vfs_getid (struct vfs_class *vclass, const char *dir)
vfsid id = NULL;
/* append slash if needed */
- dir1 = concat_dir_and_file (dir, "");
+ dir1 = mhl_str_dir_plus_file (dir, "");
if (vclass->getid)
id = (*vclass->getid) (vclass, dir1);
diff --git a/vfs/mcfs.c b/vfs/mcfs.c
index 07de5a3..796db65 100644
--- a/vfs/mcfs.c
+++ b/vfs/mcfs.c
@@ -406,7 +406,7 @@ mcfs_get_path (mcfs_connection **mc, const char *path)
int f = !strcmp (remote_path, "/~");
if (f || !strncmp (remote_path, "/~/", 3)) {
char *s;
- s = concat_dir_and_file (mcfs_gethome (*mc),
+ s = mhl_str_dir_plus_file (mcfs_gethome (*mc),
remote_path + 3 - f);
g_free (remote_path);
remote_path = s;
diff --git a/vfs/sfs.c b/vfs/sfs.c
index f4989ca..42df544 100644
--- a/vfs/sfs.c
+++ b/vfs/sfs.c
@@ -34,6 +34,8 @@
#include <stdio.h>
#include <string.h>
+#include <mhl/string.h>
+
#include "../src/global.h"
#include "../src/tty.h" /* enable/disable interrupt key */
#include "../src/wtools.h" /* message() */
@@ -336,7 +338,7 @@ static int sfs_init (struct vfs_class *me)
(void) me;
- mc_sfsini = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR "sfs.ini");
+ mc_sfsini = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR "sfs.ini");
cfg = fopen (mc_sfsini, "r");
if (!cfg){
diff --git a/vfs/smbfs.c b/vfs/smbfs.c
index a133fa3..f4d2345 100644
--- a/vfs/smbfs.c
+++ b/vfs/smbfs.c
@@ -1211,7 +1211,7 @@ smbfs_get_path (smbfs_connection ** sc, const char *path)
int f = !strcmp (remote_path, "/~");
if (f || !strncmp (remote_path, "/~/", 3)) {
char *s;
- s = concat_dir_and_file ((*sc)->home, remote_path + 3 - f);
+ s = mhl_str_dir_plus_file ((*sc)->home, remote_path + 3 - f);
g_free (remote_path);
return s;
}
diff --git a/vfs/vfs.c b/vfs/vfs.c
index 21b5404..39fdc73 100644
--- a/vfs/vfs.c
+++ b/vfs/vfs.c
@@ -38,6 +38,8 @@
#include <signal.h>
#include <ctype.h> /* is_digit() */
+#include <mhl/string.h>
+
#include "../src/global.h"
#include "../src/tty.h" /* enable/disable interrupt key */
#include "../src/wtools.h" /* message() */
@@ -656,7 +658,7 @@ vfs_canon (const char *path)
if (*path != PATH_SEP){
char *local, *result;
- local = concat_dir_and_file (current_dir, path);
+ local = mhl_str_dir_plus_file (current_dir, path);
result = vfs_canon (local);
g_free (local);
--
Midnight Commander Development
More information about the mc-devel
mailing list