Merge commit 'origin/revert_mhl_to_glib_mc-4.6' into mc-4.6

* commit 'origin/revert_mhl_to_glib_mc-4.6':
  fixed mismerge: completion stuff
  mismerge fix: g_concat -> g_strconcat
  header guard fix
  Remove some of the SHELL_ESCAPE_STR Stuff...
  Revert "introduced new type SHELL_ESCAPED_STR for more type safety"
  Last bunch of reverts and removal of mhl/*
  fixed canonicalize_pathname() breakage: fixed str_move() function (memmove semantics) again
  Revert some functions (mhl_mem_free to g_free, etc)
  Revert "replaced buggy concat_dir_and_file() by mhl_str_dir_plus_file()"
  Revert "mhl: mhl_shell_unescape_buf(): fixed memory array OOB."
  Revert "build fix: added missing declaration of mhl_dir_plus_file (reported by andrew_b)"
  Revert "cleanup: mhl_str_dir_plus_file(): int -> size_t (suggested by Andrew Borodin)"
  Revert "fixed #240"
  Revert "Fixing a theoretical buffer overflow which was reported by Roland Illig"
  Revert "Call va_end after the iteration as we need to free the list again."
  Revert "Added enhancements from Sergei which he attached to #241."
  Revert "Resolve some issues in mhl Rollang Illig pointed us to:"

Conflicts:
	ChangeLog
This commit is contained in:
Sergei Trofimovich 2009-02-20 12:22:56 +02:00
commit d93114604e
42 changed files with 399 additions and 788 deletions

View File

@ -1,4 +1,3 @@
2009-02-17 Mikhail Pobolovets <styx.mp@gmail.com> 2009-02-17 Mikhail Pobolovets <styx.mp@gmail.com>
* lt.po: update by stikonas (#274) * lt.po: update by stikonas (#274)
@ -33,6 +32,9 @@
* src/find.c, src/main.c, src/panelize.c, src/util.c, src/utilunix.c, * src/find.c, src/main.c, src/panelize.c, src/util.c, src/utilunix.c,
* src/widget.c, src/widget.h, src/wtools.c, vfs/fish.c: * src/widget.c, src/widget.h, src/wtools.c, vfs/fish.c:
fixed shell escaping issues in commandline completion engine fixed shell escaping issues in commandline completion engine
2009-01-31 Enrico Weigelt, metux ITS <weigelt@metux.de>
* replaced buggy concat_dir_and_file() by mhl_str_dir_plus_file() (in mhl/string.h) * replaced buggy concat_dir_and_file() by mhl_str_dir_plus_file() (in mhl/string.h)
2009-01-30 Enrico Weigelt, metux ITS <weigelt@metux.de> 2009-01-30 Enrico Weigelt, metux ITS <weigelt@metux.de>
@ -54,6 +56,9 @@
* mhl/escape.h, src/complete.c, vfs/fish.c: introduced new type * mhl/escape.h, src/complete.c, vfs/fish.c: introduced new type
SHELL_ESCAPED_STR for more type safety SHELL_ESCAPED_STR for more type safety
2009-01-27 Enrico Weigelt, metux IT service <weigelt@metux.de>
* mhl/escape.h, mhl/string.h: fixed comments to use /* ... */ * mhl/escape.h, mhl/string.h: fixed comments to use /* ... */
2009-01-27 Sergei Trofimovich <slyfox@inbox.ru> 2009-01-27 Sergei Trofimovich <slyfox@inbox.ru>

View File

@ -30,9 +30,8 @@
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <stdlib.h>
#include <mhl/string.h> #include <stdlib.h>
#include "../src/global.h" #include "../src/global.h"
@ -2666,7 +2665,7 @@ user_menu (WEdit * edit)
int nomark; int nomark;
struct stat status; struct stat status;
long start_mark, end_mark; long start_mark, end_mark;
char *block_file = mhl_str_dir_plus_file (home_dir, BLOCK_FILE); char *block_file = concat_dir_and_file (home_dir, BLOCK_FILE);
int rc = 0; int rc = 0;
nomark = eval_marks (edit, &start_mark, &end_mark); nomark = eval_marks (edit, &start_mark, &end_mark);

View File

@ -28,6 +28,7 @@
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <sys/types.h> #include <sys/types.h>
@ -35,9 +36,8 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <stdlib.h>
#include <mhl/string.h> #include <stdlib.h>
#include "../src/global.h" #include "../src/global.h"
#include "../src/history.h" #include "../src/history.h"
@ -235,7 +235,7 @@ edit_save_file (WEdit *edit, const char *filename)
return 0; return 0;
if (*filename != PATH_SEP && edit->dir) { if (*filename != PATH_SEP && edit->dir) {
savename = mhl_str_dir_plus_file (edit->dir, filename); savename = concat_dir_and_file (edit->dir, filename);
filename = catstrs (savename, (char *) NULL); filename = catstrs (savename, (char *) NULL);
g_free (savename); g_free (savename);
} }
@ -301,7 +301,7 @@ edit_save_file (WEdit *edit, const char *filename)
savedir[slashpos - filename + 1] = '\0'; savedir[slashpos - filename + 1] = '\0';
} else } else
savedir = g_strdup ("."); savedir = g_strdup (".");
saveprefix = mhl_str_dir_plus_file (savedir, "cooledit"); saveprefix = concat_dir_and_file (savedir, "cooledit");
g_free (savedir); g_free (savedir);
fd = mc_mkstemps (&savename, saveprefix, NULL); fd = mc_mkstemps (&savename, saveprefix, NULL);
g_free (saveprefix); g_free (saveprefix);

View File

@ -33,9 +33,8 @@
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <stdlib.h>
#include <mhl/string.h> #include <stdlib.h>
#include "../src/global.h" #include "../src/global.h"
@ -175,7 +174,7 @@ edit_file (const char *_file, int line)
WButtonBar *edit_bar; WButtonBar *edit_bar;
if (!made_directory) { if (!made_directory) {
char *dir = mhl_str_dir_plus_file (home_dir, EDIT_DIR); char *dir = concat_dir_and_file (home_dir, EDIT_DIR);
made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
g_free (dir); g_free (dir);
} }

View File

@ -30,9 +30,8 @@
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <stdlib.h>
#include <mhl/string.h> #include <stdlib.h>
#include "../src/global.h" #include "../src/global.h"
@ -1027,7 +1026,7 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
f = fopen (syntax_file, "r"); f = fopen (syntax_file, "r");
if (!f){ if (!f){
lib_file = mhl_str_dir_plus_file (mc_home, "syntax" PATH_SEP_STR "Syntax"); lib_file = concat_dir_and_file (mc_home, "syntax" PATH_SEP_STR "Syntax");
f = fopen (lib_file, "r"); f = fopen (lib_file, "r");
g_free (lib_file); g_free (lib_file);
if (!f) if (!f)
@ -1189,7 +1188,7 @@ edit_load_syntax (WEdit *edit, char ***pnames, const char *type)
if (!*edit->filename && !type) if (!*edit->filename && !type)
return; return;
} }
f = mhl_str_dir_plus_file (home_dir, SYNTAX_FILE); f = concat_dir_and_file (home_dir, SYNTAX_FILE);
r = edit_read_syntax_file (edit, pnames, f, edit ? edit->filename : 0, r = edit_read_syntax_file (edit, pnames, f, edit ? edit->filename : 0,
get_first_editor_line (edit), type); get_first_editor_line (edit), type);
if (r == -1) { if (r == -1) {

View File

@ -26,12 +26,11 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <mhl/string.h>
#include "../src/global.h" #include "../src/global.h"
#include "edit.h" #include "edit.h"
@ -597,7 +596,7 @@ edit_load_user_map(WEdit *edit)
if (edit_key_emulation != EDIT_KEY_EMULATION_USER) if (edit_key_emulation != EDIT_KEY_EMULATION_USER)
return TRUE; return TRUE;
file = mhl_str_dir_plus_file(home_dir, MC_USERMAP); file = concat_dir_and_file(home_dir, MC_USERMAP);
if (stat(file, &s) < 0) { if (stat(file, &s) < 0) {
char *msg = g_strdup_printf(_("%s not found!"), file); char *msg = g_strdup_printf(_("%s not found!"), file);

3
mhl/.gitignore vendored
View File

@ -1,3 +0,0 @@
.deps
Makefile
Makefile.in

View File

@ -1,103 +0,0 @@
Micro helper library.
--
This is a tiny library of helper functions/macros.
* MACRO-FUNC: macro w/ function syntax. (might become inline func)
* INLINE-FUNC: inline function (might become macro func)
* MACRO: strictly a macro (may never become a inline func)
--
mhl/memory.h: Memory management functions
* mhl_mem_alloc_u(sz) [MACRO-FUNC]
Allocate sz bytes on stack, unitialized
* mhl_mem_alloc_z(sz) [INLINE-FUNC]
Allocate sz bytes on stack, zero'ed
* mhl_mem_free(ptr) [INLINE-FUNC]
Free chunk @ptr (MUST be allocated w/ mhl_mem_alloc_*()),
passing NULL is graciously allowed
* mhl_mem_realloc(ptr,newsize) -> returns newptr
Re-allocates a heap chunk, just like realloc()
* MHL_PTR_FREE(ptr) [MACRO-ONLY]
like mhl_mem_free(), but with ptr as a variable that gets cleared
(use this as shortcut to "mhl_mem_free(foo); foo = NULL")
mhl/string.h: String helpers
* mhl_str_dup(const char*s) -> char*
[MACRO-FUNC] Safe version of strdup(), when NULL passed, returns strdup("")
* mhl_str_ndup(const char* s) -> char*
[MACRO-FUNC] Safe version of strndup(), when NULL passed, returns strdup("")
* mhl_str_trim(char* s) -> char*
[INLINE-FUNC] Trims the string (removing leading and trailing whitespacs),
WITHIN the passed buffer, returning the string s itself.
When NULL passed returns NULL.
* mhl_str_toupper(char* s) -> char*
[INLINE-FUNC] Converts the string in passed buffer to uppercase, returns that
buffer. When NULL passed returns NULL.
* mhl_str_concat_1(const char* base, const char* one) -> char*
[INLINE-FUNC] Concatenates the string one onto the string base and returns the
result in a newly allocated buffer (free it w/ mhl_mem_free()).
For NULL strings, "" is assumed.
* mhl_str_concat_2(const char* base,const char* one,const char* two) -> char*
mhl_str_concat_3(const char* base,const char* one,const char* two,const char* three) -> char*
mhl_str_concat_4(const char* base,const char* one,const char* two,const char* three,const char* four) -> char*
mhl_str_concat_5(const char* base,const char* one,const char* two,const char* three,const char* four,const char* five) -> char*
mhl_str_concat_6(const char* base,const char* one,const char* two,const char* three,const char* four,const char* five,const char* six) -> char*
mhl_str_concat_7(const char* base,const char* one,const char* two,const char* three,const char* four,const char* five,const char* six,const char* seven) -> char*
[INLINE-FUNC] Like str_concat_1() but adding more strings.
* mhl_str_reverse(char* str) -> char*
[INLINE-FUNC] Reverses the string in passed buffer and returns the buffer ptr itself.
If NULL is passed, returns NULL.
mhl/escape.h: Shell-style string escaping
* mhl_shell_escape_toesc(char c) -> bool
[MACRO-FUNC] returns true when given char has to be escaped
* mhl_shell_escape_nottoesc(char c) -> bool
[MACRO-FUNC] opposite of mhl_shell_escape_toesc()
* mhl_shell_escape_dup(const char* s) -> char*
[INLINE-FUNC] escapes an string and returns the result in a malloc()'ed chunk
Passing NULL returns an empty malloc()ed string.
* mhl_shell_unescape_buf(char* s) -> char*
[INLINE-FUNC] unescapes the string into given buffer (changes buffer!) and
returns ptr to the buffer itself. When NULL passed returns NULL.
mhl/env.h: Environment variable helpers
* mhl_getenv_dup(const char* n) -> char*
[MACRO-FUNC] like getenv() but returns an strdup()'ed copy. When NULL passed,
returns strdup("")

View File

@ -1,8 +0,0 @@
#ifndef MHL_ENV_H
#define MHL_ENV_H
#include <mhl/string.h>
#define mhl_getenv_dup(name) (mhl_str_dup(name ? getenv(name) : ""))
#endif

View File

@ -1,152 +0,0 @@
#ifndef MHL_ESCAPE_H
#define MHL_ESCAPE_H
/* Micro helper library: shell escaping functions */
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define mhl_shell_escape_toesc(x) \
(((x)==' ')||((x)=='!')||((x)=='#')||((x)=='$')||((x)=='%')|| \
((x)=='(')||((x)==')')||((x)=='\'')||((x)=='&')||((x)=='~')|| \
((x)=='{')||((x)=='}')||((x)=='[')||((x)==']')||((x)=='`')|| \
((x)=='?')||((x)=='|')||((x)=='<')||((x)=='>')||((x)==';')|| \
((x)=='*')||((x)=='\\')||((x)=='"'))
#define mhl_shell_escape_nottoesc(x) \
(((x)!=0) && (!mhl_shell_escape_toesc((x))))
/* type for escaped string - just for a bit more type safety ;-p */
typedef struct { char* s; } SHELL_ESCAPED_STR;
/** To be compatible with the general posix command lines we have to escape
strings for the command line
/params const char * in
string for escaping
/returns
return escaped string (later need to free)
*/
static inline SHELL_ESCAPED_STR mhl_shell_escape_dup(const char* src)
{
if ((src==NULL)||(!(*src)))
return (SHELL_ESCAPED_STR){ .s = strdup("") };
char* buffer = calloc(1, strlen(src)*2+2);
char* ptr = buffer;
/* look for the first char to escape */
while (1)
{
char c;
/* copy over all chars not to escape */
while ((c=(*src)) && mhl_shell_escape_nottoesc(c))
{
*ptr = c;
ptr++;
src++;
}
/* at this point we either have an \0 or an char to escape */
if (!c)
return (SHELL_ESCAPED_STR){ .s = buffer };
*ptr = '\\';
ptr++;
*ptr = c;
ptr++;
src++;
}
}
/** Unescape paths or other strings for e.g the internal cd
shell-unescape within a given buffer (writing to it!)
/params const char * src
string for unescaping
/returns
return unescaped string
*/
static inline char* mhl_shell_unescape_buf(char* text)
{
if (!text)
return NULL;
/* look for the first \ - that's quick skipover if there's nothing to escape */
char* readptr = text;
while ((*readptr) && ((*readptr)!='\\')) readptr++;
if (!(*readptr)) return text;
/* if we're here, we're standing on the first '\' */
char* writeptr = readptr;
char c;
while ((c = *readptr))
{
if (c=='\\')
{
readptr++;
switch ((c = *readptr))
{
case 'n': (*writeptr) = '\n'; writeptr++; break;
case 'r': (*writeptr) = '\r'; writeptr++; break;
case 't': (*writeptr) = '\t'; writeptr++; break;
case ' ':
case '\\':
case '#':
case '$':
case '%':
case '(':
case ')':
case '[':
case ']':
case '{':
case '}':
case '<':
case '>':
case '!':
case '*':
case '?':
case '~':
case '`':
case '"':
case ';':
case '\0': /* end of string! malformed escape string */
goto out;
default:
(*writeptr) = c; writeptr++; break;
}
}
else /* got a normal character */
{
(*writeptr) = *readptr;
writeptr++;
}
readptr++;
}
out:
*writeptr = 0;
return text;
}
/** Check if char in pointer contain escape'd chars
/params const char * in
string for checking
/returns
return TRUE if string contain escaped chars
otherwise return FALSE
*/
static inline bool
mhl_shell_is_char_escaped ( const char *in )
{
if (in == NULL || !*in || in[0] != '\\')
return false;
if (mhl_shell_escape_toesc(in[1]))
return true;
return false;
}
#endif

View File

@ -1,28 +0,0 @@
#ifndef MHL_MEMORY_H
#define MHL_MEMORY_H
#include <memory.h>
#include <stdlib.h>
/* allocate a chunk of stack memory, uninitialized */
#define mhl_mem_alloc_u(sz) (malloc(sz))
/* allocate a chunk of stack memory, zeroed */
#define mhl_mem_alloc_z(sz) (calloc(1,sz))
/* free a chunk of memory from stack, passing NULL does no harm */
static inline void mhl_mem_free(void* ptr)
{
if (ptr) free(ptr);
}
/* free an ptr and NULL it */
#define MHL_PTR_FREE(ptr) do { mhl_mem_free(ptr); (ptr) = NULL; } while (0)
/* allocate a chunk on stack - automatically free'd on function exit */
#define mhl_stack_alloc(sz) (alloca(sz))
/* re-alloc memory chunk */
#define mhl_mem_realloc(ptr,sz) (realloc(ptr,sz))
#endif

View File

@ -1,49 +0,0 @@
#ifndef MHL_STRHASH_H
#define MHL_STRHASH_H
#include <hash.h>
#include <mhl/memory.h>
static void __mhl_strhash_free_key(void* ptr)
{
mhl_mem_free(ptr);
}
static void __mhl_strhash_free_dummy(void* ptr)
{
}
typedef hash MHL_STRHASH;
#define MHL_STRHASH_DECLARE(n) MHL_STRHASH n;
#define MHL_STRHASH_INIT(h) \
hash_initialise(h, 997U, \
hash_hash_string, \
hash_compare_string, \
hash_copy_string, \
__mhl_strhash_free_key, \
__mhl_strhash_free_dummy)
#define MHL_STRHASH_DECLARE_INIT(n) \
MHL_STRHASH_DECLARE(n); \
MHL_STRHASH_INIT(&n);
#define MHL_STRHASH_DEINIT(ht) \
hash_deinitialise(ht)
static inline void mhl_strhash_addkey(MHL_STRHASH* ht, const char* key, void* value)
{
hash_insert(ht, (char*)key, value);
}
static inline void* mhl_strhash_lookup(MHL_STRHASH* ht, const char* key)
{
void* retptr;
if (hash_retrieve(ht, (char*)key, &retptr))
return retptr;
else
return NULL;
}
#endif

View File

@ -1,172 +0,0 @@
#ifndef MHL_STRING_H
#define MHL_STRING_H
#include <ctype.h>
#include <stdarg.h>
#include <assert.h>
#include <mhl/memory.h>
#define mhl_str_dup(str) ((str ? strdup(str) : strdup("")))
#define mhl_str_ndup(str,len) ((str ? strndup(str,len) : strdup("")))
#define mhl_str_len(str) ((str ? strlen(str) : 0))
#define ISSPACE(c) isspace((unsigned char)(c))
#define TOUPPER(c) toupper((unsigned char)(c))
static inline char * mhl_str_dup_range(const char * s_start, const char * s_bound)
{
return mhl_str_ndup(s_start, s_bound - s_start);
}
static inline char* mhl_str_trim(char* str)
{
if (!str) return NULL; /* NULL string ?! bail out. */
/* find the first non-space */
char* start; for (start=str; ((*str) && (!ISSPACE(*str))); str++);
/* only spaces ? */
if (!(*str)) { *str = 0; return str; }
/* get the size (cannot be empty - caught above) */
size_t _sz = strlen(str);
/* find the proper end */
char* end;
for (end=(str+_sz-1); ((end>str) && (ISSPACE(*end))); end--);
end[1] = 0; /* terminate, just to be sure */
/* if we have no leading spaces, just trucate */
if (start==str) { end++; *end = 0; return str; }
/* if it's only one char, dont need memmove for that */
if (start==end) { str[0]=*start; str[1]=0; return str; }
/* by here we have a (non-empty) region between start and end */
memmove(str,start,(end-start+1));
return str;
}
static inline void mhl_str_toupper(char* str)
{
if (str)
for (;*str;str++)
*str = TOUPPER(*str);
}
/* note: we use ((char*)(1)) as terminator - NULL is a valid argument ! */
static const char * mhl_s_c_sep__ = (const char *)1;
/* _NEVER_ call this function directly ! */
static inline char* mhl_str_concat_hlp__(const char* va_start_dummy, ...)
{
char * result;
size_t result_len = 0;
char * p;
const char * chunk;
va_list args;
va_start(args,va_start_dummy);
while ((chunk = va_arg(args, const char*)) != mhl_s_c_sep__)
{
if (chunk)
{
result_len += strlen (chunk);
}
}
va_end(args);
if (result_len == 0)
return mhl_str_dup("");
/* now as we know how much to copy, allocate the buffer + '\0'*/
result = (char*)mhl_mem_alloc_u (result_len + 1);
p = result;
va_start(args,va_start_dummy);
while ((chunk = va_arg(args, const char*)) != mhl_s_c_sep__)
{
if (chunk)
{
size_t chunk_len = strlen (chunk);
memcpy (p, chunk, chunk_len);
p += chunk_len;
}
}
va_end(args);
*p = '\0';
return result;
}
#define mhl_str_concat(...) (mhl_str_concat_hlp__(mhl_s_c_sep__, __VA_ARGS__, mhl_s_c_sep__))
static inline char* mhl_str_reverse(char* ptr)
{
if (!ptr) return NULL; /* missing string */
if (!(ptr[0] && ptr[1])) return ptr; /* empty or 1-ch string */
size_t _sz = strlen(ptr);
char* start = ptr;
char* end = ptr+_sz-1;
while (start<end)
{
char c = *start;
*start = *end;
*end = c;
start++;
end--;
}
return ptr;
}
/*
* strcpy is unsafe on overlapping memory areas, so define memmove-alike
* string function. Has sense only when dest <= src.
*/
static inline char * mhl_strmove(char * dest, const char * src)
{
size_t n = strlen (src) + 1; /* + '\0' */
/* strictly speaking, this invokes undefined behavior as soon as dest and src are pointers into different objects. */
assert (dest<=src);
return memmove(dest, src, n);
}
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 */
size_t dnlen = strlen(dirname);
while ((dnlen != 0) && (dirname[dnlen-1]=='/'))
dnlen--;
size_t 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 */

View File

@ -1,18 +0,0 @@
/*
Micro Helper Library: generic type declarations
*/
#ifndef MHL_TYPES_H
#define MHL_TYPES_H
#if !defined(__bool_true_false_are_defined) && !defined(false) && !defined(true) && !defined(bool)
typedef enum
{
false = 0,
true = 1
} bool;
#endif
#endif

View File

@ -27,8 +27,6 @@
#include <iconv.h> #include <iconv.h>
#include <mhl/string.h>
#include "global.h" #include "global.h"
#include "charsets.h" #include "charsets.h"
@ -50,7 +48,7 @@ load_codepages_list (void)
extern int display_codepage; extern int display_codepage;
char *default_codepage = NULL; char *default_codepage = NULL;
fname = mhl_str_dir_plus_file (mc_home, CHARSETS_INDEX); fname = concat_dir_and_file (mc_home, CHARSETS_INDEX);
if (!(f = fopen (fname, "r"))) { if (!(f = fopen (fname, "r"))) {
fprintf (stderr, _("Warning: file %s not found\n"), fname); fprintf (stderr, _("Warning: file %s not found\n"), fname);
g_free (fname); g_free (fname);

View File

@ -34,8 +34,6 @@
#endif #endif
#include <unistd.h> #include <unistd.h>
#include <mhl/string.h>
#include "global.h" #include "global.h"
#include "cmd.h" /* Our definitions */ #include "cmd.h" /* Our definitions */
#include "fileopctx.h" /* file_op_context_new() */ #include "fileopctx.h" /* file_op_context_new() */
@ -364,7 +362,7 @@ mkdir_cmd (void)
if (dir[0] == '/' || dir[0] == '~') if (dir[0] == '/' || dir[0] == '~')
absdir = g_strdup (dir); absdir = g_strdup (dir);
else else
absdir = mhl_str_dir_plus_file (current_panel->cwd, dir); absdir = concat_dir_and_file (current_panel->cwd, dir);
save_cwds_stat (); save_cwds_stat ();
if (my_mkdir (absdir, 0777) == 0) { if (my_mkdir (absdir, 0777) == 0) {
@ -570,10 +568,10 @@ void ext_cmd (void)
_(" Which extension file you want to edit? "), 0, 2, _(" Which extension file you want to edit? "), 0, 2,
_("&User"), _("&System Wide")); _("&User"), _("&System Wide"));
} }
extdir = mhl_str_dir_plus_file (mc_home, MC_LIB_EXT); extdir = concat_dir_and_file (mc_home, MC_LIB_EXT);
if (dir == 0){ if (dir == 0){
buffer = mhl_str_dir_plus_file (home_dir, MC_USER_EXT); buffer = concat_dir_and_file (home_dir, MC_USER_EXT);
check_for_default (extdir, buffer); check_for_default (extdir, buffer);
do_edit (buffer); do_edit (buffer);
g_free (buffer); g_free (buffer);
@ -600,7 +598,7 @@ menu_edit_cmd (int where)
_("&Local"), _("&User"), _("&System Wide") _("&Local"), _("&User"), _("&System Wide")
); );
menufile = mhl_str_dir_plus_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); menufile = concat_dir_and_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
switch (dir) { switch (dir) {
case 0: case 0:
@ -609,12 +607,12 @@ menu_edit_cmd (int where)
break; break;
case 1: case 1:
buffer = mhl_str_dir_plus_file (home_dir, where ? CEDIT_HOME_MENU : MC_HOME_MENU); buffer = concat_dir_and_file (home_dir, where ? CEDIT_HOME_MENU : MC_HOME_MENU);
check_for_default (menufile, buffer); check_for_default (menufile, buffer);
break; break;
case 2: case 2:
buffer = mhl_str_dir_plus_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); buffer = concat_dir_and_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
break; break;
default: default:
@ -673,10 +671,10 @@ edit_syntax_cmd (void)
_(" Which syntax file you want to edit? "), 0, 2, _(" Which syntax file you want to edit? "), 0, 2,
_("&User"), _("&System Wide")); _("&User"), _("&System Wide"));
} }
extdir = mhl_str_dir_plus_file (mc_home, "syntax" PATH_SEP_STR "Syntax"); extdir = concat_dir_and_file (mc_home, "syntax" PATH_SEP_STR "Syntax");
if (dir == 0) { if (dir == 0) {
buffer = mhl_str_dir_plus_file (home_dir, SYNTAX_FILE); buffer = concat_dir_and_file (home_dir, SYNTAX_FILE);
check_for_default (extdir, buffer); check_for_default (extdir, buffer);
do_edit (buffer); do_edit (buffer);
g_free (buffer); g_free (buffer);
@ -807,8 +805,8 @@ compare_dir (WPanel *panel, WPanel *other, enum CompareMode mode)
} }
/* Thorough compare on, do byte-by-byte comparison */ /* Thorough compare on, do byte-by-byte comparison */
src_name = mhl_str_dir_plus_file (panel->cwd, source->fname); src_name = concat_dir_and_file (panel->cwd, source->fname);
dst_name = mhl_str_dir_plus_file (other->cwd, target->fname); dst_name = concat_dir_and_file (other->cwd, target->fname);
if (compare_files (src_name, dst_name, source->st.st_size)) if (compare_files (src_name, dst_name, source->st.st_size))
do_file_mark (panel, i, 1); do_file_mark (panel, i, 1);
g_free (src_name); g_free (src_name);
@ -922,10 +920,10 @@ do_link (int symbolic_link, const char *fname)
char *d; char *d;
/* suggest the full path for symlink */ /* suggest the full path for symlink */
s = mhl_str_dir_plus_file (current_panel->cwd, fname); s = concat_dir_and_file (current_panel->cwd, fname);
if (get_other_type () == view_listing) { if (get_other_type () == view_listing) {
d = mhl_str_dir_plus_file (other_panel->cwd, fname); d = concat_dir_and_file (other_panel->cwd, fname);
} else { } else {
d = g_strdup (fname); d = g_strdup (fname);
} }

View File

@ -27,10 +27,6 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <mhl/memory.h>
#include <mhl/escape.h>
#include <mhl/string.h>
#include "global.h" /* home_dir */ #include "global.h" /* home_dir */
#include "tty.h" #include "tty.h"
#include "widget.h" /* WInput */ #include "widget.h" /* WInput */
@ -67,7 +63,7 @@ examine_cd (char *path)
const char *t; const char *t;
/* Tilde expansion */ /* Tilde expansion */
path = mhl_shell_unescape_buf(path); path = shell_unescape(path);
path_tilde = tilde_expand (path); path_tilde = tilde_expand (path);
/* Leave space for further expansion */ /* Leave space for further expansion */
@ -128,7 +124,7 @@ examine_cd (char *path)
c = *s; c = *s;
*s = 0; *s = 0;
if (*p) { if (*p) {
r = mhl_str_dir_plus_file (p, q); r = concat_dir_and_file (p, q);
result = do_cd (r, cd_parse_command); result = do_cd (r, cd_parse_command);
g_free (r); g_free (r);
} }
@ -139,7 +135,7 @@ examine_cd (char *path)
} }
g_free (q); g_free (q);
g_free (path_tilde); g_free (path_tilde);
// mhl_mem_free(path); // g_free(path);
return result; return result;
} }
@ -181,7 +177,7 @@ void do_cd_command (char *cmd)
} else { } else {
char *old = current_panel->cwd; char *old = current_panel->cwd;
char *new; char *new;
new = mhl_str_dir_plus_file (old, cmd+3); new = concat_dir_and_file (old, cmd+3);
sync_tree (new); sync_tree (new);
g_free (new); g_free (new);
} }

View File

@ -26,14 +26,11 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <mhl/memory.h>
#include <mhl/escape.h>
#include <mhl/string.h>
#include "global.h" #include "global.h"
#include "tty.h" #include "tty.h"
#include "win.h" #include "win.h"
@ -42,7 +39,6 @@
#include "widget.h" #include "widget.h"
#include "wtools.h" #include "wtools.h"
#include "main.h" #include "main.h"
#include "util.h"
#include "key.h" /* XCTRL and ALT macros */ #include "key.h" /* XCTRL and ALT macros */
typedef char *CompletionFunction (char * text, int state, INPUT_COMPLETE_FLAGS flags); typedef char *CompletionFunction (char * text, int state, INPUT_COMPLETE_FLAGS flags);
@ -86,7 +82,7 @@ filename_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags)
SHOW_C_CTX("filename_completion_function"); SHOW_C_CTX("filename_completion_function");
if (text && (flags & INPUT_COMPLETE_SHELL_ESC)) if (text && (flags & INPUT_COMPLETE_SHELL_ESC))
text = mhl_shell_unescape_buf (text); text = shell_unescape (text);
/* If we're starting the match process, initialize us a bit. */ /* If we're starting the match process, initialize us a bit. */
if (!state){ if (!state){
@ -206,9 +202,7 @@ filename_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags)
if (temp && (flags & INPUT_COMPLETE_SHELL_ESC)) if (temp && (flags & INPUT_COMPLETE_SHELL_ESC))
{ {
SHELL_ESCAPED_STR e_temp = mhl_shell_escape_dup(temp); temp = shell_escape(temp);
mhl_mem_free (temp);
temp = e_temp.s;
} }
return temp; return temp;
} }
@ -463,7 +457,7 @@ command_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags)
if (!(flags & INPUT_COMPLETE_COMMANDS)) if (!(flags & INPUT_COMPLETE_COMMANDS))
return 0; return 0;
text = mhl_shell_unescape_buf(text); text = shell_unescape(text);
flags &= ~INPUT_COMPLETE_SHELL_ESC; flags &= ~INPUT_COMPLETE_SHELL_ESC;
if (!state) { /* Initialize us a little bit */ if (!state) { /* Initialize us a little bit */
@ -486,9 +480,8 @@ command_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags)
p = filename_completion_function (text, state, flags); p = filename_completion_function (text, state, flags);
if (!p) if (!p)
return 0; return 0;
SHELL_ESCAPED_STR e_p = mhl_shell_escape_dup(p); p = shell_escape(p);
mhl_mem_free(p); return p;
return e_p.s;
} }
found = NULL; found = NULL;
@ -520,7 +513,7 @@ command_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags)
if (cur_path >= path_end) if (cur_path >= path_end)
break; break;
expanded = tilde_expand (*cur_path ? cur_path : "."); expanded = tilde_expand (*cur_path ? cur_path : ".");
cur_word = mhl_str_dir_plus_file (expanded, text); cur_word = concat_dir_and_file (expanded, text);
g_free (expanded); g_free (expanded);
canonicalize_pathname (cur_word); canonicalize_pathname (cur_word);
cur_path = strchr (cur_path, 0) + 1; cur_path = strchr (cur_path, 0) + 1;
@ -544,9 +537,9 @@ command_completion_function (char *text, int state, INPUT_COMPLETE_FLAGS flags)
if ((p = strrchr (found, PATH_SEP)) != NULL) { if ((p = strrchr (found, PATH_SEP)) != NULL) {
p++; p++;
SHELL_ESCAPED_STR e_p = mhl_shell_escape_dup(p); p = shell_escape(p);
mhl_mem_free(found); g_free(found);
return e_p.s; return p;
} }
return found; return found;
@ -815,7 +808,7 @@ try_complete (char *text, int *start, int *end, INPUT_COMPLETE_FLAGS flags)
c = *s; c = *s;
*s = 0; *s = 0;
if (*cdpath){ if (*cdpath){
r = mhl_str_dir_plus_file (cdpath, word); r = concat_dir_and_file (cdpath, word);
SHOW_C_CTX("try_complete:filename_subst_2"); SHOW_C_CTX("try_complete:filename_subst_2");
matches = completion_matches (r, filename_completion_function, flags); matches = completion_matches (r, filename_completion_function, flags);
g_free (r); g_free (r);
@ -1000,10 +993,9 @@ complete_engine (WInput *in, int what_to_do)
start++; start++;
in->completions = try_complete (in->buffer, &start, &end, in->completion_flags); in->completions = try_complete (in->buffer, &start, &end, in->completion_flags);
} }
if (in->completions){ if (in->completions){
if (what_to_do & DO_INSERTION || ((what_to_do & DO_QUERY) && !in->completions[1])) { if (what_to_do & DO_INSERTION || ((what_to_do & DO_QUERY) && !in->completions[1])) {
char * complete = in->completions [0]; char * complete = g_strdup (in->completions [0]);
if (insert_text (in, complete, strlen (complete))){ if (insert_text (in, complete, strlen (complete))){
if (in->completions [1]) if (in->completions [1])
beep (); beep ();
@ -1011,6 +1003,7 @@ complete_engine (WInput *in, int what_to_do)
free_completions (in); free_completions (in);
} else } else
beep (); beep ();
g_free(complete);
} }
if ((what_to_do & DO_QUERY) && in->completions && in->completions [1]) { if ((what_to_do & DO_QUERY) && in->completions && in->completions [1]) {
int maxlen = 0, i, count = 0; int maxlen = 0, i, count = 0;

View File

@ -28,8 +28,6 @@
#endif #endif
#include <unistd.h> #include <unistd.h>
#include <mhl/string.h>
#include "global.h" #include "global.h"
#include "tty.h" #include "tty.h"
#include "cons.saver.h" #include "cons.saver.h"
@ -145,7 +143,7 @@ handle_console_linux (unsigned char action)
open ("/dev/null", O_WRONLY); open ("/dev/null", O_WRONLY);
if (tty_name) { if (tty_name) {
/* Exec the console save/restore handler */ /* Exec the console save/restore handler */
mc_conssaver = mhl_str_dir_plus_file (SAVERDIR, "cons.saver"); mc_conssaver = concat_dir_and_file (SAVERDIR, "cons.saver");
execl (mc_conssaver, "cons.saver", tty_name, (char *) NULL); execl (mc_conssaver, "cons.saver", tty_name, (char *) NULL);
} }
/* Console is not a tty or execl() failed */ /* Console is not a tty or execl() failed */

View File

@ -53,8 +53,6 @@
#endif #endif
#include <unistd.h> #include <unistd.h>
#include <mhl/string.h>
#define LINUX_CONS_SAVER_C #define LINUX_CONS_SAVER_C
#include "cons.saver.h" #include "cons.saver.h"

View File

@ -25,9 +25,8 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <mhl/string.h> #include <unistd.h>
#include "global.h" #include "global.h"
#include "tty.h" #include "tty.h"
@ -441,11 +440,11 @@ regex_command (const char *filename, const char *action, int *move_dir)
int mc_user_ext = 1; int mc_user_ext = 1;
int home_error = 0; int home_error = 0;
extension_file = mhl_str_dir_plus_file (home_dir, MC_USER_EXT); extension_file = concat_dir_and_file (home_dir, MC_USER_EXT);
if (!exist_file (extension_file)) { if (!exist_file (extension_file)) {
g_free (extension_file); g_free (extension_file);
check_stock_mc_ext: check_stock_mc_ext:
extension_file = mhl_str_dir_plus_file (mc_home, MC_LIB_EXT); extension_file = concat_dir_and_file (mc_home, MC_LIB_EXT);
mc_user_ext = 0; mc_user_ext = 0;
} }
data = load_file (extension_file); data = load_file (extension_file);

View File

@ -50,10 +50,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <mhl/memory.h>
#include <mhl/escape.h>
#include <mhl/string.h>
#include "global.h" #include "global.h"
#include "tty.h" #include "tty.h"
#include "eregex.h" #include "eregex.h"
@ -181,7 +177,7 @@ do_transform_source (FileOpContext *ctx, const char *source)
for (next_reg = 1, j = 0, k = 0; j < strlen (ctx->dest_mask); j++) { for (next_reg = 1, j = 0, k = 0; j < strlen (ctx->dest_mask); j++) {
switch (ctx->dest_mask[j]) { switch (ctx->dest_mask[j]) {
case '\\': case '\\':
if (mhl_shell_is_char_escaped (&ctx->dest_mask[j])){ if (shell_is_char_escaped (&ctx->dest_mask[j])){
fntarget[k++] = ctx->dest_mask[j++]; fntarget[k++] = ctx->dest_mask[j++];
fntarget[k++] = ctx->dest_mask[j]; fntarget[k++] = ctx->dest_mask[j];
break; break;
@ -922,7 +918,7 @@ copy_dir_dir (FileOpContext *ctx, const char *s, const char *d, int toplevel,
} }
/* Dive into subdir if exists */ /* Dive into subdir if exists */
if (toplevel && ctx->dive_into_subdirs) { if (toplevel && ctx->dive_into_subdirs) {
dest_dir = mhl_str_dir_plus_file (d, x_basename (s)); dest_dir = concat_dir_and_file (d, x_basename (s));
} else { } else {
dest_dir = g_strdup (d); dest_dir = g_strdup (d);
goto dont_mkdir; goto dont_mkdir;
@ -968,11 +964,11 @@ copy_dir_dir (FileOpContext *ctx, const char *s, const char *d, int toplevel,
continue; continue;
/* get the filename and add it to the src directory */ /* get the filename and add it to the src directory */
path = mhl_str_dir_plus_file (s, next->d_name); path = concat_dir_and_file (s, next->d_name);
(*ctx->stat_func) (path, &buf); (*ctx->stat_func) (path, &buf);
if (S_ISDIR (buf.st_mode)) { if (S_ISDIR (buf.st_mode)) {
mdpath = mhl_str_dir_plus_file (dest_dir, next->d_name); mdpath = concat_dir_and_file (dest_dir, next->d_name);
/* /*
* From here, we just intend to recursively copy subdirs, not * From here, we just intend to recursively copy subdirs, not
* the double functionality of copying different when the target * the double functionality of copying different when the target
@ -983,7 +979,7 @@ copy_dir_dir (FileOpContext *ctx, const char *s, const char *d, int toplevel,
parent_dirs, progress_count, progress_bytes); parent_dirs, progress_count, progress_bytes);
g_free (mdpath); g_free (mdpath);
} else { } else {
dest_file = mhl_str_dir_plus_file (dest_dir, x_basename (path)); dest_file = concat_dir_and_file (dest_dir, x_basename (path));
return_status = copy_file_file (ctx, path, dest_file, 1, return_status = copy_file_file (ctx, path, dest_file, 1,
progress_count, progress_bytes, 0); progress_count, progress_bytes, 0);
g_free (dest_file); g_free (dest_file);
@ -1173,7 +1169,7 @@ move_dir_dir (FileOpContext *ctx, const char *s, const char *d,
destdir = g_strdup (d); destdir = g_strdup (d);
move_over = 1; move_over = 1;
} else } else
destdir = mhl_str_dir_plus_file (d, x_basename (s)); destdir = concat_dir_and_file (d, x_basename (s));
if (sbuf.st_dev == dbuf.st_dev && sbuf.st_ino == dbuf.st_ino) { if (sbuf.st_dev == dbuf.st_dev && sbuf.st_ino == dbuf.st_ino) {
int msize = COLS - 36; int msize = COLS - 36;
@ -1330,7 +1326,7 @@ recursive_erase (FileOpContext *ctx, const char *s, off_t *progress_count,
continue; continue;
if (!strcmp (next->d_name, "..")) if (!strcmp (next->d_name, ".."))
continue; continue;
path = mhl_str_dir_plus_file (s, next->d_name); path = concat_dir_and_file (s, next->d_name);
if (mc_lstat (path, &buf)) { if (mc_lstat (path, &buf)) {
g_free (path); g_free (path);
mc_closedir (reading); mc_closedir (reading);
@ -1521,7 +1517,7 @@ compute_dir_size (const char *dirname, off_t *ret_marked, double *ret_total)
if (strcmp (dirent->d_name, "..") == 0) if (strcmp (dirent->d_name, "..") == 0)
continue; continue;
fullname = mhl_str_dir_plus_file (dirname, dirent->d_name); fullname = concat_dir_and_file (dirname, dirent->d_name);
res = mc_lstat (fullname, &s); res = mc_lstat (fullname, &s);
@ -1578,7 +1574,7 @@ panel_compute_totals (WPanel *panel, off_t *ret_marked, double *ret_total)
double subdir_bytes = 0; double subdir_bytes = 0;
dir_name = dir_name =
mhl_str_dir_plus_file (panel->cwd, panel->dir.list[i].fname); concat_dir_and_file (panel->cwd, panel->dir.list[i].fname);
compute_dir_size (dir_name, &subdir_count, &subdir_bytes); compute_dir_size (dir_name, &subdir_count, &subdir_bytes);
*ret_marked += subdir_count; *ret_marked += subdir_count;
@ -1805,13 +1801,13 @@ panel_operate (void *source_panel, FileOperation operation,
*/ */
if (force_single) if (force_single)
/* just copy */ /* just copy */
dest_dir_ = mhl_str_dup (dest_dir); dest_dir_ = g_strdup (dest_dir);
else else
/* add trailing separator */ /* add trailing separator */
if (*dest_dir && strcmp(&dest_dir[strlen(dest_dir)-1], PATH_SEP_STR)) { if (*dest_dir && strcmp(&dest_dir[strlen(dest_dir)-1], PATH_SEP_STR)) {
dest_dir_ = mhl_str_concat (dest_dir, PATH_SEP_STR); dest_dir_ = g_strconcat (dest_dir, PATH_SEP_STR, (char*)0);
} else { } else {
dest_dir_ = mhl_str_dup (dest_dir); dest_dir_ = g_strdup (dest_dir);
} }
if (!dest_dir_) { if (!dest_dir_) {
file_op_context_destroy (ctx); file_op_context_destroy (ctx);
@ -1821,7 +1817,7 @@ panel_operate (void *source_panel, FileOperation operation,
dest = dest =
file_mask_dialog (ctx, operation, cmd_buf, dest_dir_, file_mask_dialog (ctx, operation, cmd_buf, dest_dir_,
single_entry, &do_bg); single_entry, &do_bg);
mhl_mem_free(dest_dir_); g_free(dest_dir_);
if (!dest) { if (!dest) {
file_op_context_destroy (ctx); file_op_context_destroy (ctx);
@ -1886,7 +1882,7 @@ panel_operate (void *source_panel, FileOperation operation,
/* The source and src_stat variables have been initialized before */ /* The source and src_stat variables have been initialized before */
#ifdef WITH_FULL_PATHS #ifdef WITH_FULL_PATHS
source_with_path = mhl_str_dir_plus_file (panel->cwd, source); source_with_path = concat_dir_and_file (panel->cwd, source);
#endif /* WITH_FULL_PATHS */ #endif /* WITH_FULL_PATHS */
if (operation == OP_DELETE) { if (operation == OP_DELETE) {
@ -1901,7 +1897,7 @@ panel_operate (void *source_panel, FileOperation operation,
if (temp == NULL) { if (temp == NULL) {
value = transform_error; value = transform_error;
} else { } else {
char *temp2 = mhl_str_dir_plus_file (dest, temp); char *temp2 = concat_dir_and_file (dest, temp);
g_free (dest); g_free (dest);
dest = temp2; dest = temp2;
temp = NULL; temp = NULL;
@ -1979,7 +1975,7 @@ panel_operate (void *source_panel, FileOperation operation,
#ifdef WITH_FULL_PATHS #ifdef WITH_FULL_PATHS
g_free (source_with_path); g_free (source_with_path);
source_with_path = mhl_str_dir_plus_file (panel->cwd, source); source_with_path = concat_dir_and_file (panel->cwd, source);
#endif /* WITH_FULL_PATHS */ #endif /* WITH_FULL_PATHS */
if (operation == OP_DELETE) { if (operation == OP_DELETE) {
@ -1995,10 +1991,10 @@ panel_operate (void *source_panel, FileOperation operation,
if (temp == NULL) if (temp == NULL)
value = transform_error; value = transform_error;
else { else {
char *temp2 = mhl_str_dir_plus_file (dest, temp); char *temp2 = concat_dir_and_file (dest, temp);
source_with_path = mhl_shell_unescape_buf(source_with_path); source_with_path = shell_unescape(source_with_path);
temp2 = mhl_shell_unescape_buf(temp2); temp2 = shell_unescape(temp2);
switch (operation) { switch (operation) {
case OP_COPY: case OP_COPY:

View File

@ -27,8 +27,6 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <mhl/string.h>
#include "global.h" #include "global.h"
static char * static char *
@ -39,7 +37,7 @@ get_absolute_name (const char *file)
if (file[0] == PATH_SEP) if (file[0] == PATH_SEP)
return g_strdup (file); return g_strdup (file);
mc_get_current_wd (dir, MC_MAXPATHLEN); mc_get_current_wd (dir, MC_MAXPATHLEN);
return mhl_str_dir_plus_file (dir, file); return concat_dir_and_file (dir, file);
} }
static int static int
@ -62,7 +60,7 @@ my_mkdir_rec (char *s, mode_t mode)
return -1; return -1;
} }
p = mhl_str_dir_plus_file (s, ".."); p = concat_dir_and_file (s, "..");
q = vfs_canon (p); q = vfs_canon (p);
g_free (p); g_free (p);

View File

@ -25,9 +25,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include <mhl/string.h> #include <sys/stat.h>
#include "global.h" #include "global.h"
#include "tty.h" #include "tty.h"
@ -355,7 +354,7 @@ push_directory (const char *dir)
dir_stack *new; dir_stack *new;
new = g_new (dir_stack, 1); new = g_new (dir_stack, 1);
new->name = mhl_str_dir_plus_file (dir, NULL); new->name = concat_dir_and_file (dir, "");
new->prev = dir_stack_base; new->prev = dir_stack_base;
dir_stack_base = new; dir_stack_base = new;
} }
@ -517,7 +516,7 @@ search_content (Dlg_head *h, const char *directory, const char *filename)
int file_fd; int file_fd;
int ret_val = 0; int ret_val = 0;
fname = mhl_str_dir_plus_file (directory, filename); fname = concat_dir_and_file (directory, filename);
if (mc_stat (fname, &s) != 0 || !S_ISREG (s.st_mode)){ if (mc_stat (fname, &s) != 0 || !S_ISREG (s.st_mode)){
g_free (fname); g_free (fname);
@ -693,7 +692,7 @@ do_search (struct Dlg_head *h)
} }
if (subdirs_left && find_recursively && directory) { /* Can directory be NULL ? */ if (subdirs_left && find_recursively && directory) { /* Can directory be NULL ? */
char *tmp_name = mhl_str_dir_plus_file (directory, dp->d_name); char *tmp_name = concat_dir_and_file (directory, dp->d_name);
if (!mc_lstat (tmp_name, &tmp_stat) if (!mc_lstat (tmp_name, &tmp_stat)
&& S_ISDIR (tmp_stat.st_mode)) { && S_ISDIR (tmp_stat.st_mode)) {
push_directory (tmp_name); push_directory (tmp_name);
@ -753,8 +752,8 @@ make_fullname (const char *dirname, const char *filename)
if (strcmp(dirname, ".") == 0 || strcmp(dirname, "."PATH_SEP_STR) == 0) if (strcmp(dirname, ".") == 0 || strcmp(dirname, "."PATH_SEP_STR) == 0)
return g_strdup (filename); return g_strdup (filename);
if (strncmp(dirname, "."PATH_SEP_STR, 2) == 0) if (strncmp(dirname, "."PATH_SEP_STR, 2) == 0)
return mhl_str_dir_plus_file (dirname + 2, filename); return concat_dir_and_file (dirname + 2, filename);
return mhl_str_dir_plus_file (dirname, filename); return concat_dir_and_file (dirname, filename);
} }
static void static void

View File

@ -32,12 +32,11 @@
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <mhl/string.h>
#include "global.h" #include "global.h"
#include "tty.h" /* COLS */ #include "tty.h" /* COLS */
#include "color.h" /* dialog_colors */ #include "color.h" /* dialog_colors */
@ -1448,7 +1447,7 @@ load_hotlist (void)
} }
if (!hotlist_file_name) if (!hotlist_file_name)
hotlist_file_name = mhl_str_dir_plus_file (home_dir, HOTLIST_FILENAME); hotlist_file_name = concat_dir_and_file (home_dir, HOTLIST_FILENAME);
hotlist = new_hotlist (); hotlist = new_hotlist ();
hotlist->type = HL_TYPE_GROUP; hotlist->type = HL_TYPE_GROUP;

View File

@ -29,12 +29,11 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <mhl/string.h>
#include "global.h" #include "global.h"
#include "tty.h" #include "tty.h"
#include "dir.h" #include "dir.h"
@ -1137,7 +1136,7 @@ copy_readlink (WPanel *panel)
if (S_ISLNK (selection (panel)->st.st_mode)) { if (S_ISLNK (selection (panel)->st.st_mode)) {
char buffer[MC_MAXPATHLEN]; char buffer[MC_MAXPATHLEN];
char *p = char *p =
mhl_str_dir_plus_file (panel->cwd, selection (panel)->fname); concat_dir_and_file (panel->cwd, selection (panel)->fname);
int i; int i;
i = mc_readlink (p, buffer, MC_MAXPATHLEN - 1); i = mc_readlink (p, buffer, MC_MAXPATHLEN - 1);

View File

@ -25,9 +25,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <mhl/string.h> #include <unistd.h>
#include "global.h" #include "global.h"
#include "tty.h" #include "tty.h"
@ -710,7 +709,7 @@ display_mini_info (WPanel *panel)
char *link, link_target [MC_MAXPATHLEN]; char *link, link_target [MC_MAXPATHLEN];
int len; int len;
link = mhl_str_dir_plus_file (panel->cwd, panel->dir.list [panel->selected].fname); link = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
len = mc_readlink (link, link_target, MC_MAXPATHLEN - 1); len = mc_readlink (link, link_target, MC_MAXPATHLEN - 1);
g_free (link); g_free (link);
if (len > 0){ if (len > 0){
@ -1975,7 +1974,7 @@ do_enter_on_file_entry (file_entry *fe)
return 1; return 1;
/* Check if the file is executable */ /* Check if the file is executable */
full_name = mhl_str_dir_plus_file (current_panel->cwd, fe->fname); full_name = concat_dir_and_file (current_panel->cwd, fe->fname);
if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe)) { if (!is_exe (fe->st.st_mode) || !if_link_is_exe (full_name, fe)) {
g_free (full_name); g_free (full_name);
return 0; return 0;
@ -1994,7 +1993,7 @@ do_enter_on_file_entry (file_entry *fe)
char *tmp; char *tmp;
int ret; int ret;
tmp = mhl_str_dir_plus_file (vfs_get_current_dir (), fe->fname); tmp = concat_dir_and_file (vfs_get_current_dir (), fe->fname);
ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL); ret = mc_setctl (tmp, VFS_SETCTL_RUN, NULL);
g_free (tmp); g_free (tmp);
/* We took action only if the dialog was shown or the execution /* We took action only if the dialog was shown or the execution
@ -2031,10 +2030,10 @@ chdir_other_panel (WPanel *panel)
} }
if (!S_ISDIR (panel->dir.list [panel->selected].st.st_mode)) { if (!S_ISDIR (panel->dir.list [panel->selected].st.st_mode)) {
new_dir = mhl_str_dir_plus_file (panel->cwd, ".."); new_dir = concat_dir_and_file (panel->cwd, "..");
sel_entry = strrchr(panel->cwd, PATH_SEP); sel_entry = strrchr(panel->cwd, PATH_SEP);
} else } else
new_dir = mhl_str_dir_plus_file (panel->cwd, panel->dir.list [panel->selected].fname); new_dir = concat_dir_and_file (panel->cwd, panel->dir.list [panel->selected].fname);
change_panel (); change_panel ();
do_cd (new_dir, cd_exact); do_cd (new_dir, cd_exact);
@ -2100,7 +2099,7 @@ chdir_to_readlink (WPanel *panel)
if (*buffer == PATH_SEP) if (*buffer == PATH_SEP)
new_dir = g_strdup (buffer); new_dir = g_strdup (buffer);
else else
new_dir = mhl_str_dir_plus_file (panel->cwd, buffer); new_dir = concat_dir_and_file (panel->cwd, buffer);
change_panel (); change_panel ();
do_cd (new_dir, cd_exact); do_cd (new_dir, cd_exact);

View File

@ -20,11 +20,10 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <mhl/string.h>
#include "global.h" #include "global.h"
#include "tty.h" #include "tty.h"
#include "dir.h" #include "dir.h"
@ -282,7 +281,7 @@ save_layout (void)
int i; int i;
char buffer [BUF_TINY]; char buffer [BUF_TINY];
profile = mhl_str_dir_plus_file (home_dir, PROFILE_NAME); profile = concat_dir_and_file (home_dir, PROFILE_NAME);
/* Save integer options */ /* Save integer options */
for (i = 0; layout [i].opt_name; i++){ for (i = 0; layout [i].opt_name; i++){
@ -299,7 +298,7 @@ save_configure (void)
char *profile; char *profile;
int i; int i;
profile = mhl_str_dir_plus_file (home_dir, PROFILE_NAME); profile = concat_dir_and_file (home_dir, PROFILE_NAME);
/* Save integer options */ /* Save integer options */
for (i = 0; int_options[i].opt_name; i++) for (i = 0; int_options[i].opt_name; i++)
@ -347,7 +346,7 @@ save_setup (void)
char *profile; char *profile;
saving_setup = 1; saving_setup = 1;
profile = mhl_str_dir_plus_file (home_dir, PROFILE_NAME); profile = concat_dir_and_file (home_dir, PROFILE_NAME);
save_configure (); save_configure ();
@ -482,9 +481,9 @@ setup_init (void)
if (profile_name) if (profile_name)
return profile_name; return profile_name;
profile = mhl_str_dir_plus_file (home_dir, PROFILE_NAME); profile = concat_dir_and_file (home_dir, PROFILE_NAME);
if (!exist_file (profile)){ if (!exist_file (profile)){
inifile = mhl_str_dir_plus_file (mc_home, "mc.ini"); inifile = concat_dir_and_file (mc_home, "mc.ini");
if (exist_file (inifile)){ if (exist_file (inifile)){
g_free (profile); g_free (profile);
profile = inifile; profile = inifile;
@ -507,7 +506,7 @@ load_setup (void)
/* mc.lib is common for all users, but has priority lower than /* mc.lib is common for all users, but has priority lower than
~/.mc/ini. FIXME: it's only used for keys and treestore now */ ~/.mc/ini. FIXME: it's only used for keys and treestore now */
global_profile_name = mhl_str_dir_plus_file (mc_home, "mc.lib"); global_profile_name = concat_dir_and_file (mc_home, "mc.lib");
/* Load integer boolean options */ /* Load integer boolean options */
for (i = 0; int_options[i].opt_name; i++) for (i = 0; int_options[i].opt_name; i++)

View File

@ -37,12 +37,11 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <mhl/string.h>
#include "global.h" #include "global.h"
#include "treestore.h" #include "treestore.h"
#include "profile.h" #include "profile.h"
@ -266,7 +265,7 @@ tree_store_load(void)
char *name; char *name;
int retval; int retval;
name = mhl_str_dir_plus_file(home_dir, MC_TREE); name = concat_dir_and_file(home_dir, MC_TREE);
retval = tree_store_load_from(name); retval = tree_store_load_from(name);
g_free(name); g_free(name);
@ -372,7 +371,7 @@ tree_store_save(void)
char *name; char *name;
int retval; int retval;
tmp = mhl_str_dir_plus_file(home_dir, MC_TREE_TMP); tmp = concat_dir_and_file(home_dir, MC_TREE_TMP);
retval = tree_store_save_to(tmp); retval = tree_store_save_to(tmp);
if (retval) { if (retval) {
@ -380,7 +379,7 @@ tree_store_save(void)
return retval; return retval;
} }
name = mhl_str_dir_plus_file(home_dir, MC_TREE); name = concat_dir_and_file(home_dir, MC_TREE);
retval = rename(tmp, name); retval = rename(tmp, name);
g_free(tmp); g_free(tmp);
@ -606,7 +605,7 @@ tree_store_mark_checked(const char *subname)
if (ts.check_name[0] == PATH_SEP && ts.check_name[1] == 0) if (ts.check_name[0] == PATH_SEP && ts.check_name[1] == 0)
name = g_strconcat(PATH_SEP_STR, subname, (char *) NULL); name = g_strconcat(PATH_SEP_STR, subname, (char *) NULL);
else else
name = mhl_str_dir_plus_file(ts.check_name, subname); name = concat_dir_and_file(ts.check_name, subname);
/* Search for the subdirectory */ /* Search for the subdirectory */
current = ts.check_start; current = ts.check_start;
@ -796,7 +795,7 @@ tree_store_rescan(const char *dir)
continue; continue;
} }
full_name = mhl_str_dir_plus_file(dir, dp->d_name); full_name = concat_dir_and_file(dir, dp->d_name);
if (mc_lstat(full_name, &buf) != -1) { if (mc_lstat(full_name, &buf) != -1) {
if (S_ISDIR(buf.st_mode)) if (S_ISDIR(buf.st_mode))
tree_store_mark_checked(dp->d_name); tree_store_mark_checked(dp->d_name);

View File

@ -23,8 +23,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <mhl/string.h>
#include "global.h" #include "global.h"
#include "tty.h" #include "tty.h"
#include "color.h" #include "color.h"
@ -723,11 +721,11 @@ user_menu_cmd (struct WEdit *edit_widget)
menu = g_strdup (edit_widget ? CEDIT_LOCAL_MENU : MC_LOCAL_MENU); menu = g_strdup (edit_widget ? CEDIT_LOCAL_MENU : MC_LOCAL_MENU);
if (!exist_file (menu) || !menu_file_own (menu)){ if (!exist_file (menu) || !menu_file_own (menu)){
g_free (menu); g_free (menu);
menu = mhl_str_dir_plus_file \ menu = concat_dir_and_file \
(home_dir, edit_widget ? CEDIT_HOME_MENU : MC_HOME_MENU); (home_dir, edit_widget ? CEDIT_HOME_MENU : MC_HOME_MENU);
if (!exist_file (menu)){ if (!exist_file (menu)){
g_free (menu); g_free (menu);
menu = mhl_str_dir_plus_file \ menu = concat_dir_and_file \
(mc_home, edit_widget ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); (mc_home, edit_widget ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU);
} }
} }

View File

@ -35,9 +35,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <mhl/escape.h>
#include <mhl/string.h>
#include "global.h" #include "global.h"
#include "profile.h" #include "profile.h"
#include "main.h" /* mc_home */ #include "main.h" /* mc_home */
@ -694,7 +691,7 @@ load_mc_home_file (const char *filename, char **allocated_filename)
char *lang; char *lang;
char *data; char *data;
hintfile_base = mhl_str_dir_plus_file (mc_home, filename); hintfile_base = concat_dir_and_file (mc_home, filename);
lang = guess_message_value (); lang = guess_message_value ();
hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL); hintfile = g_strconcat (hintfile_base, ".", lang, (char *) NULL);
@ -1253,6 +1250,18 @@ diff_two_paths (const char *first, const char *second)
return buf; 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 */ /* Append text to GList, remove all entries with the same text */
GList * GList *
list_append_unique (GList *list, char *text) list_append_unique (GList *list, char *text)
@ -1313,7 +1322,7 @@ mc_mkstemps (char **pname, const char *prefix, const char *suffix)
if (strchr (prefix, PATH_SEP) == NULL) { if (strchr (prefix, PATH_SEP) == NULL) {
/* Add prefix first to find the position of XXXXXX */ /* Add prefix first to find the position of XXXXXX */
tmpbase = mhl_str_dir_plus_file (mc_tmpdir (), prefix); tmpbase = concat_dir_and_file (mc_tmpdir (), prefix);
} else { } else {
tmpbase = g_strdup (prefix); tmpbase = g_strdup (prefix);
} }
@ -1381,7 +1390,7 @@ load_file_position (const char *filename, long *line, long *column)
*column = 0; *column = 0;
/* open file with positions */ /* open file with positions */
fn = mhl_str_dir_plus_file (home_dir, MC_FILEPOS); fn = concat_dir_and_file (home_dir, MC_FILEPOS);
f = fopen (fn, "r"); f = fopen (fn, "r");
g_free (fn); g_free (fn);
if (!f) if (!f)
@ -1428,8 +1437,8 @@ save_file_position (const char *filename, long line, long column)
len = strlen (filename); len = strlen (filename);
tmp = mhl_str_dir_plus_file (home_dir, MC_FILEPOS_TMP); tmp = concat_dir_and_file (home_dir, MC_FILEPOS_TMP);
fn = mhl_str_dir_plus_file (home_dir, MC_FILEPOS); fn = concat_dir_and_file (home_dir, MC_FILEPOS);
/* open temporary file */ /* open temporary file */
t = fopen (tmp, "w"); t = fopen (tmp, "w");
@ -1522,3 +1531,157 @@ Q_ (const char *s)
sep = strchr(result, '|'); sep = strchr(result, '|');
return (sep != NULL) ? sep + 1 : result; return (sep != NULL) ? sep + 1 : result;
} }
#define shell_escape_toesc(x) \
(((x)==' ')||((x)=='!')||((x)=='#')||((x)=='$')||((x)=='%')|| \
((x)=='(')||((x)==')')||((x)=='\'')||((x)=='&')||((x)=='~')|| \
((x)=='{')||((x)=='}')||((x)=='[')||((x)==']')||((x)=='`')|| \
((x)=='?')||((x)=='|')||((x)=='<')||((x)=='>')||((x)==';')|| \
((x)=='*')||((x)=='\\')||((x)=='"'))
#define shell_escape_nottoesc(x) \
(((x)!=0) && (!shell_escape_toesc((x))))
/** To be compatible with the general posix command lines we have to escape
strings for the command line
\params in
string for escaping
\returns
return escaped string (which needs to be freed later)
*/
char*
shell_escape(const char* src)
{
GString *str;
char *result = NULL;
if ((src==NULL)||(!(*src)))
return strdup("");
str = g_string_new("");
/* look for the first char to escape */
while (1)
{
char c;
/* copy over all chars not to escape */
while ((c=(*src)) && shell_escape_nottoesc(c))
{
g_string_append_c(str,c);
src++;
}
/* at this point we either have an \0 or an char to escape */
if (!c) {
result = str->str;
g_string_free(str,FALSE);
return result;
}
g_string_append_c(str,'\\');
g_string_append_c(str,c);
src++;
}
}
/** Unescape paths or other strings for e.g the internal cd
shell-unescape within a given buffer (writing to it!)
\params src
string for unescaping
\returns
return unescaped string (which needs to be freed)
*/
char*
shell_unescape(const char* text)
{
GString *str;
char *result = NULL;
if (!text)
return NULL;
/* look for the first \ - that's quick skipover if there's nothing to escape */
const char* readptr = text;
while ((*readptr) && ((*readptr)!='\\')) readptr++;
if (!(*readptr)) {
result = g_strdup(text);
return result;
}
str = g_string_new_len(text, readptr - text);
/* if we're here, we're standing on the first '\' */
char c;
while ((c = *readptr))
{
if (c=='\\')
{
readptr++;
switch ((c = *readptr))
{
case '\0': /* end of string! malformed escape string */
goto out;
case 'n': g_string_append_c(str,'\n'); break;
case 'r': g_string_append_c(str,'\r'); break;
case 't': g_string_append_c(str,'\t'); break;
case ' ':
case '\\':
case '#':
case '$':
case '%':
case '(':
case ')':
case '[':
case ']':
case '{':
case '}':
case '<':
case '>':
case '!':
case '*':
case '?':
case '~':
case '`':
case '"':
case ';':
default:
g_string_append_c(str,c); break;
}
}
else /* got a normal character */
{
g_string_append_c(str,c);
}
readptr++;
}
out:
result = str->str;
g_string_free(str,FALSE);
return result;
}
/** Check if char in pointer contain escape'd chars
\params in
string for checking
\returns
return TRUE if string contain escaped chars
otherwise return FALSE
*/
gboolean
shell_is_char_escaped ( const char *in )
{
if (in == NULL || !*in || in[0] != '\\')
return FALSE;
if (shell_escape_toesc(in[1]))
return TRUE;
return FALSE;
}

View File

@ -2,6 +2,8 @@
#define MC_UTIL_H #define MC_UTIL_H
#include <sys/types.h> #include <sys/types.h>
#include <assert.h>
#include <string.h>
/* Returns its argument as a "modifiable" string. This function is /* Returns its argument as a "modifiable" string. This function is
* intended to pass strings to legacy libraries that don't know yet * intended to pass strings to legacy libraries that don't know yet
@ -66,6 +68,7 @@ char *strip_password (char *path, int has_prefix);
const char *strip_home_and_password (const char *dir); const char *strip_home_and_password (const char *dir);
const char *extension (const char *); 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 *unix_error_string (int error_num);
const char *skip_separators (const char *s); const char *skip_separators (const char *s);
const char *skip_numbers (const char *s); const char *skip_numbers (const char *s);
@ -255,4 +258,35 @@ extern int ascii_alpha_to_cntrl (int ch);
#undef Q_ #undef Q_
const char *Q_ (const char *s); const char *Q_ (const char *s);
gboolean shell_is_char_escaped ( const char * );
char *shell_unescape( const char * );
char *shell_escape( const char * );
#define str_dup_range(s_start, s_bound) (g_strndup(s_start, s_bound - s_start))
/*
* strcpy is unsafe on overlapping memory areas, so define memmove-alike
* string function.
* Have sense only when:
* * dest <= src
* AND
* * dest and str are pointers to one object (as Roland Illig pointed).
*
* We can't use str*cpy funs here:
* http://kerneltrap.org/mailarchive/openbsd-misc/2008/5/27/1951294
*/
static inline char * str_move(char * dest, const char * src)
{
size_t n;
assert (dest<=src);
n = strlen (src) + 1; /* + '\0' */
return memmove (dest, src, n);
}
#define MC_PTR_FREE(ptr) do { g_free(ptr); (ptr) = NULL; } while (0)
#endif #endif

View File

@ -41,8 +41,6 @@
#endif #endif
#include <unistd.h> #include <unistd.h>
#include <mhl/string.h>
#include "global.h" #include "global.h"
#include "execute.h" #include "execute.h"
#include "wtools.h" /* message() */ #include "wtools.h" /* message() */
@ -428,7 +426,7 @@ canonicalize_pathname (char *path)
if (p[0] == PATH_SEP && p[1] == PATH_SEP) { if (p[0] == PATH_SEP && p[1] == PATH_SEP) {
s = p + 1; s = p + 1;
while (*(++s) == PATH_SEP); while (*(++s) == PATH_SEP);
mhl_strmove (p + 1, s); str_move (p + 1, s);
} }
p++; p++;
} }
@ -437,7 +435,7 @@ canonicalize_pathname (char *path)
p = lpath; p = lpath;
while (*p) { while (*p) {
if (p[0] == PATH_SEP && p[1] == '.' && p[2] == PATH_SEP) if (p[0] == PATH_SEP && p[1] == '.' && p[2] == PATH_SEP)
mhl_strmove (p, p + 2); str_move (p, p + 2);
else else
p++; p++;
} }
@ -453,7 +451,7 @@ canonicalize_pathname (char *path)
lpath[1] = 0; lpath[1] = 0;
return; return;
} else { } else {
mhl_strmove (lpath, lpath + 2); str_move (lpath, lpath + 2);
} }
} }
@ -499,10 +497,10 @@ canonicalize_pathname (char *path)
if (p[3] != 0) { if (p[3] != 0) {
if (s == lpath && *s == PATH_SEP) { if (s == lpath && *s == PATH_SEP) {
/* "/../foo" -> "/foo" */ /* "/../foo" -> "/foo" */
mhl_strmove (s + 1, p + 4); str_move (s + 1, p + 4);
} else { } else {
/* "token/../foo" -> "foo" */ /* "token/../foo" -> "foo" */
mhl_strmove (s, p + 4); str_move (s, p + 4);
} }
p = (s > lpath) ? s - 1 : s; p = (s > lpath) ? s - 1 : s;
continue; continue;

View File

@ -32,9 +32,8 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
#include <mhl/string.h> #include <sys/types.h>
#include "global.h" #include "global.h"
#include "tty.h" #include "tty.h"
@ -866,7 +865,7 @@ history_get (const char *input_name)
return NULL; return NULL;
if (!*input_name) if (!*input_name)
return NULL; return NULL;
profile = mhl_str_dir_plus_file (home_dir, HISTORY_FILE_NAME); profile = concat_dir_and_file (home_dir, HISTORY_FILE_NAME);
for (i = 0;; i++) { for (i = 0;; i++) {
char key_name[BUF_TINY]; char key_name[BUF_TINY];
char this_entry[BUF_LARGE]; char this_entry[BUF_LARGE];
@ -904,7 +903,7 @@ history_put (const char *input_name, GList *h)
if (!num_history_items_recorded) /* this is how to disable */ if (!num_history_items_recorded) /* this is how to disable */
return; return;
profile = mhl_str_dir_plus_file (home_dir, HISTORY_FILE_NAME); profile = concat_dir_and_file (home_dir, HISTORY_FILE_NAME);
if ((i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) != -1) if ((i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) != -1)
close (i); close (i);

View File

@ -35,9 +35,6 @@
#include <sys/wait.h> #include <sys/wait.h>
#endif #endif
#include <errno.h> #include <errno.h>
#include <mhl/string.h>
#include "../src/global.h" #include "../src/global.h"
#include "../src/tty.h" /* enable/disable interrupt key */ #include "../src/tty.h" /* enable/disable interrupt key */
#include "../src/wtools.h" /* message() */ #include "../src/wtools.h" /* message() */
@ -249,7 +246,7 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc)
tmp = name_quote (name, 0); tmp = name_quote (name, 0);
} }
mc_extfsdir = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR); mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
cmd = cmd =
g_strconcat (mc_extfsdir, extfs_prefixes[fstype], " list ", g_strconcat (mc_extfsdir, extfs_prefixes[fstype], " list ",
local_name ? local_name : tmp, (char *) NULL); local_name ? local_name : tmp, (char *) NULL);
@ -624,7 +621,7 @@ extfs_cmd (const char *extfs_cmd, struct archive *archive,
archive_name = name_quote (extfs_get_archive_name (archive), 0); archive_name = name_quote (extfs_get_archive_name (archive), 0);
quoted_localname = name_quote (localname, 0); quoted_localname = name_quote (localname, 0);
mc_extfsdir = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR); mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
cmd = g_strconcat (mc_extfsdir, extfs_prefixes[archive->fstype], cmd = g_strconcat (mc_extfsdir, extfs_prefixes[archive->fstype],
extfs_cmd, archive_name, " ", quoted_file, " ", extfs_cmd, archive_name, " ", quoted_file, " ",
quoted_localname, (char *) NULL); quoted_localname, (char *) NULL);
@ -653,7 +650,7 @@ extfs_run (struct vfs_class *me, const char *file)
g_free (p); g_free (p);
archive_name = name_quote (extfs_get_archive_name (archive), 0); archive_name = name_quote (extfs_get_archive_name (archive), 0);
mc_extfsdir = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR); mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
cmd = g_strconcat (mc_extfsdir, extfs_prefixes[archive->fstype], cmd = g_strconcat (mc_extfsdir, extfs_prefixes[archive->fstype],
" run ", archive_name, " ", q, (char *) NULL); " run ", archive_name, " ", q, (char *) NULL);
g_free (mc_extfsdir); g_free (mc_extfsdir);
@ -1298,7 +1295,7 @@ static int extfs_init (struct vfs_class *me)
(void) me; (void) me;
mc_extfsini = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR "extfs.ini"); mc_extfsini = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR "extfs.ini");
cfg = fopen (mc_extfsini, "r"); cfg = fopen (mc_extfsini, "r");
/* We may not use vfs_die() message or message or similar, /* We may not use vfs_die() message or message or similar,

View File

@ -50,9 +50,6 @@
#include "tcputil.h" #include "tcputil.h"
#include "../src/unixcompat.h" #include "../src/unixcompat.h"
#include "fish.h" #include "fish.h"
#include "../mhl/memory.h"
#include "../mhl/string.h"
#include "../mhl/escape.h"
int fish_directory_timeout = 900; int fish_directory_timeout = 900;
@ -144,7 +141,7 @@ fish_command (struct vfs_class *me, struct vfs_s_super *super,
enable_interrupt_key (); enable_interrupt_key ();
status = write (SUP.sockw, str, strlen (str)); status = write (SUP.sockw, str, strlen (str));
mhl_mem_free (str); g_free (str);
disable_interrupt_key (); disable_interrupt_key ();
if (status < 0) if (status < 0)
@ -168,10 +165,10 @@ fish_free_archive (struct vfs_class *me, struct vfs_s_super *super)
close (SUP.sockr); close (SUP.sockr);
SUP.sockw = SUP.sockr = -1; SUP.sockw = SUP.sockr = -1;
} }
mhl_mem_free (SUP.host); g_free (SUP.host);
mhl_mem_free (SUP.user); g_free (SUP.user);
mhl_mem_free (SUP.cwdir); g_free (SUP.cwdir);
mhl_mem_free (SUP.password); g_free (SUP.password);
} }
static void static void
@ -251,7 +248,7 @@ fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
p = g_strconcat (_(" fish: Password required for "), p = g_strconcat (_(" fish: Password required for "),
SUP.user, " ", (char *) NULL); SUP.user, " ", (char *) NULL);
op = vfs_get_password (p); op = vfs_get_password (p);
mhl_mem_free (p); g_free (p);
if (op == NULL) if (op == NULL)
ERRNOR (EPERM, -1); ERRNOR (EPERM, -1);
SUP.password = op; SUP.password = op;
@ -314,7 +311,7 @@ fish_open_archive (struct vfs_class *me, struct vfs_s_super *super,
p = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags, p = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags,
&password, 0, URL_NOSLASH); &password, 0, URL_NOSLASH);
mhl_mem_free (p); g_free (p);
SUP.host = host; SUP.host = host;
SUP.user = user; SUP.user = user;
@ -341,12 +338,12 @@ fish_archive_same (struct vfs_class *me, struct vfs_s_super *super,
op = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags, 0, 0, op = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags, 0, 0,
URL_NOSLASH); URL_NOSLASH);
mhl_mem_free (op); g_free (op);
flags = ((strcmp (host, SUP.host) == 0) flags = ((strcmp (host, SUP.host) == 0)
&& (strcmp (user, SUP.user) == 0) && (flags == SUP.flags)); && (strcmp (user, SUP.user) == 0) && (flags == SUP.flags));
mhl_mem_free (host); g_free (host);
mhl_mem_free (user); g_free (user);
return flags; return flags;
} }
@ -358,7 +355,7 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
char buffer[8192]; char buffer[8192];
struct vfs_s_entry *ent = NULL; struct vfs_s_entry *ent = NULL;
FILE *logfile; FILE *logfile;
SHELL_ESCAPED_STR quoted_path; char *quoted_path;
int reply_code; int reply_code;
#if 0 #if 0
@ -377,7 +374,7 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
gettimeofday(&dir->timestamp, NULL); gettimeofday(&dir->timestamp, NULL);
dir->timestamp.tv_sec += fish_directory_timeout; dir->timestamp.tv_sec += fish_directory_timeout;
quoted_path = mhl_shell_escape_dup (remote_path); quoted_path = shell_escape (remote_path);
fish_command (me, super, NONE, fish_command (me, super, NONE,
"#LIST /%s\n" "#LIST /%s\n"
"if `perl -v > /dev/null 2>&1` ; then\n" "if `perl -v > /dev/null 2>&1` ; then\n"
@ -453,8 +450,8 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
"else\n" "else\n"
"echo '### 500'\n" "echo '### 500'\n"
"fi\n", "fi\n",
quoted_path.s, quoted_path.s, quoted_path.s, quoted_path.s, quoted_path.s, quoted_path.s); quoted_path, quoted_path, quoted_path, quoted_path, quoted_path, quoted_path);
mhl_mem_free (quoted_path.s); g_free (quoted_path);
ent = vfs_s_generate_entry(me, NULL, dir, 0); ent = vfs_s_generate_entry(me, NULL, dir, 0);
while (1) { while (1) {
int res = vfs_s_get_line_interruptible (me, buffer, sizeof (buffer), SUP.sockr); int res = vfs_s_get_line_interruptible (me, buffer, sizeof (buffer), SUP.sockr);
@ -515,11 +512,11 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
--linkname_bound; // skip trailing " --linkname_bound; // skip trailing "
} }
ent->name = mhl_str_dup_range(filename, filename_bound); ent->name = str_dup_range(filename, filename_bound);
mhl_shell_unescape_buf(ent->name); shell_unescape(ent->name);
ent->ino->linkname = mhl_str_dup_range(linkname, linkname_bound); ent->ino->linkname = str_dup_range(linkname, linkname_bound);
mhl_shell_unescape_buf(ent->ino->linkname); shell_unescape(ent->ino->linkname);
} else { } else {
// we expect: "escaped-name" // we expect: "escaped-name"
if (filename_bound - filename > 2) if (filename_bound - filename > 2)
@ -532,8 +529,8 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
--filename_bound; --filename_bound;
} }
ent->name = mhl_str_dup_range(filename, filename_bound); ent->name = str_dup_range(filename, filename_bound);
mhl_shell_unescape_buf(ent->name); shell_unescape(ent->name);
} }
break; break;
} }
@ -585,7 +582,7 @@ fish_dir_load(struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
vfs_s_free_entry (me, ent); vfs_s_free_entry (me, ent);
reply_code = fish_decode_reply(buffer + 4, 0); reply_code = fish_decode_reply(buffer + 4, 0);
if (reply_code == COMPLETE) { if (reply_code == COMPLETE) {
mhl_mem_free (SUP.cwdir); g_free (SUP.cwdir);
SUP.cwdir = g_strdup (remote_path); SUP.cwdir = g_strdup (remote_path);
print_vfs_message (_("%s: done."), me->name); print_vfs_message (_("%s: done."), me->name);
return 0; return 0;
@ -609,7 +606,7 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc
struct stat s; struct stat s;
int was_error = 0; int was_error = 0;
int h; int h;
SHELL_ESCAPED_STR quoted_name; char *quoted_name;
h = open (localname, O_RDONLY); h = open (localname, O_RDONLY);
@ -649,8 +646,8 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc
* algorithm for file appending case, therefore just "dd" is used for it. * algorithm for file appending case, therefore just "dd" is used for it.
*/ */
quoted_name = mhl_shell_escape_dup(name); quoted_name = shell_escape(name);
print_vfs_message(_("fish: store %s: sending command..."), quoted_name.s ); print_vfs_message(_("fish: store %s: sending command..."), quoted_name );
/* FIXME: File size is limited to ULONG_MAX */ /* FIXME: File size is limited to ULONG_MAX */
if (!fh->u.fish.append) if (!fh->u.fish.append)
@ -674,8 +671,8 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc
" rest=`expr $rest - $n`\n" " rest=`expr $rest - $n`\n"
"done\n" "done\n"
"}; echo '### 200'\n", "}; echo '### 200'\n",
(unsigned long) s.st_size, quoted_name.s, (unsigned long) s.st_size, quoted_name,
quoted_name.s, (unsigned long) s.st_size, quoted_name, (unsigned long) s.st_size,
(unsigned long) s.st_size); (unsigned long) s.st_size);
else else
n = fish_command (me, super, WAIT_REPLY, n = fish_command (me, super, WAIT_REPLY,
@ -691,8 +688,8 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc
" rest=`expr $rest - $n`\n" " rest=`expr $rest - $n`\n"
"done\n" "done\n"
"}; echo '### 200'\n", "}; echo '### 200'\n",
(unsigned long) s.st_size, quoted_name.s, (unsigned long) s.st_size, quoted_name,
quoted_name.s, (unsigned long) s.st_size); quoted_name, (unsigned long) s.st_size);
if (n != PRELIM) { if (n != PRELIM) {
close (h); close (h);
@ -726,14 +723,14 @@ fish_file_store(struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *loc
(unsigned long) s.st_size); (unsigned long) s.st_size);
} }
close(h); close(h);
mhl_mem_free(quoted_name.s); g_free(quoted_name);
if ((fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE) || was_error) if ((fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE) || was_error)
ERRNOR (E_REMOTE, -1); ERRNOR (E_REMOTE, -1);
return 0; return 0;
error_return: error_return:
close(h); close(h);
fish_get_reply(me, SUP.sockr, NULL, 0); fish_get_reply(me, SUP.sockr, NULL, 0);
mhl_mem_free(quoted_name.s); g_free(quoted_name);
return -1; return -1;
} }
@ -741,13 +738,13 @@ static int
fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset) fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset)
{ {
char *name; char *name;
SHELL_ESCAPED_STR quoted_name; char *quoted_name;
if (offset) if (offset)
ERRNOR (E_NOTSUPP, 0); ERRNOR (E_NOTSUPP, 0);
name = vfs_s_fullpath (me, fh->ino); name = vfs_s_fullpath (me, fh->ino);
if (!name) if (!name)
return 0; return 0;
quoted_name = mhl_shell_escape_dup(name); quoted_name = shell_escape(name);
fh->u.fish.append = 0; fh->u.fish.append = 0;
/* /*
@ -770,8 +767,8 @@ fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset)
"else\n" "else\n"
"echo '### 500'\n" "echo '### 500'\n"
"fi\n", "fi\n",
quoted_name.s, quoted_name.s, quoted_name.s, quoted_name.s ); quoted_name, quoted_name, quoted_name, quoted_name );
mhl_mem_free (quoted_name.s); g_free (quoted_name);
if (offset != PRELIM) ERRNOR (E_REMOTE, 0); if (offset != PRELIM) ERRNOR (E_REMOTE, 0);
fh->linear = LS_LINEAR_OPEN; fh->linear = LS_LINEAR_OPEN;
fh->u.fish.got = 0; fh->u.fish.got = 0;
@ -880,18 +877,17 @@ fish_send_command(struct vfs_class *me, struct vfs_s_super *super, const char *c
#define PREFIX \ #define PREFIX \
char buf[BUF_LARGE]; \ char buf[BUF_LARGE]; \
const char *crpath; \ const char *crpath; \
char *mpath = mhl_str_dup (path); \ char *rpath, *mpath = g_strdup (path); \
SHELL_ESCAPED_STR rpath; \
struct vfs_s_super *super; \ struct vfs_s_super *super; \
if (!(crpath = vfs_s_get_path_mangle (me, mpath, &super, 0))) { \ if (!(crpath = vfs_s_get_path_mangle (me, mpath, &super, 0))) { \
mhl_mem_free (mpath); \ g_free (mpath); \
return -1; \ return -1; \
} \ } \
rpath = mhl_shell_escape_dup(crpath); \ rpath = shell_escape(crpath); \
mhl_mem_free (mpath); g_free (mpath);
#define POSTFIX(flags) \ #define POSTFIX(flags) \
mhl_mem_free (rpath.s); \ g_free (rpath); \
return fish_send_command(me, super, buf, flags); return fish_send_command(me, super, buf, flags);
static int static int
@ -901,8 +897,8 @@ fish_chmod (struct vfs_class *me, const char *path, int mode)
g_snprintf(buf, sizeof(buf), "#CHMOD %4.4o /%s\n" g_snprintf(buf, sizeof(buf), "#CHMOD %4.4o /%s\n"
"chmod %4.4o /%s 2>/dev/null\n" "chmod %4.4o /%s 2>/dev/null\n"
"echo '### 000'\n", "echo '### 000'\n",
mode & 07777, rpath.s, mode & 07777, rpath,
mode & 07777, rpath.s); mode & 07777, rpath);
POSTFIX(OPT_FLUSH); POSTFIX(OPT_FLUSH);
} }
@ -911,24 +907,24 @@ static int fish_##name (struct vfs_class *me, const char *path1, const char *pat
{ \ { \
char buf[BUF_LARGE]; \ char buf[BUF_LARGE]; \
const char *crpath1, *crpath2; \ const char *crpath1, *crpath2; \
char *mpath1, *mpath2; \ char *rpath1, *rpath2, *mpath1, *mpath2; \
struct vfs_s_super *super1, *super2; \ struct vfs_s_super *super1, *super2; \
if (!(crpath1 = vfs_s_get_path_mangle (me, mpath1 = g_strdup(path1), &super1, 0))) { \ if (!(crpath1 = vfs_s_get_path_mangle (me, mpath1 = g_strdup(path1), &super1, 0))) { \
mhl_mem_free (mpath1); \ g_free (mpath1); \
return -1; \ return -1; \
} \ } \
if (!(crpath2 = vfs_s_get_path_mangle (me, mpath2 = g_strdup(path2), &super2, 0))) { \ if (!(crpath2 = vfs_s_get_path_mangle (me, mpath2 = g_strdup(path2), &super2, 0))) { \
mhl_mem_free (mpath1); \ g_free (mpath1); \
mhl_mem_free (mpath2); \ g_free (mpath2); \
return -1; \ return -1; \
} \ } \
SHELL_ESCAPED_STR rpath1 = mhl_shell_escape_dup (crpath1); \ rpath1 = shell_escape (crpath1); \
mhl_mem_free (mpath1); \ g_free (mpath1); \
SHELL_ESCAPED_STR rpath2 = mhl_shell_escape_dup (crpath2); \ rpath2 = shell_escape (crpath2); \
mhl_mem_free (mpath2); \ g_free (mpath2); \
g_snprintf(buf, sizeof(buf), string "\n", rpath1.s, rpath2.s, rpath1.s, rpath2.s); \ g_snprintf(buf, sizeof(buf), string "\n", rpath1, rpath2, rpath1, rpath2); \
mhl_mem_free (rpath1.s); \ g_free (rpath1); \
mhl_mem_free (rpath2.s); \ g_free (rpath2); \
return fish_send_command(me, super2, buf, OPT_FLUSH); \ return fish_send_command(me, super2, buf, OPT_FLUSH); \
} }
@ -941,15 +937,15 @@ FISH_OP(link, "#LINK /%s /%s\n"
static int fish_symlink (struct vfs_class *me, const char *setto, const char *path) static int fish_symlink (struct vfs_class *me, const char *setto, const char *path)
{ {
SHELL_ESCAPED_STR qsetto; char *qsetto;
PREFIX PREFIX
qsetto = mhl_shell_escape_dup (setto); qsetto = shell_escape (setto);
g_snprintf(buf, sizeof(buf), g_snprintf(buf, sizeof(buf),
"#SYMLINK %s /%s\n" "#SYMLINK %s /%s\n"
"ln -s %s /%s 2>/dev/null\n" "ln -s %s /%s 2>/dev/null\n"
"echo '### 000'\n", "echo '### 000'\n",
qsetto.s, rpath.s, qsetto.s, rpath.s); qsetto, rpath, qsetto, rpath);
mhl_mem_free (qsetto.s); g_free (qsetto);
POSTFIX(OPT_FLUSH); POSTFIX(OPT_FLUSH);
} }
@ -974,16 +970,16 @@ fish_chown (struct vfs_class *me, const char *path, int owner, int group)
"#CHOWN %s /%s\n" "#CHOWN %s /%s\n"
"chown %s /%s 2>/dev/null\n" "chown %s /%s 2>/dev/null\n"
"echo '### 000'\n", "echo '### 000'\n",
sowner, rpath.s, sowner, rpath,
sowner, rpath.s); sowner, rpath);
fish_send_command (me, super, buf, OPT_FLUSH); fish_send_command (me, super, buf, OPT_FLUSH);
/* FIXME: what should we report if chgrp succeeds but chown fails? */ /* FIXME: what should we report if chgrp succeeds but chown fails? */
g_snprintf (buf, sizeof(buf), g_snprintf (buf, sizeof(buf),
"#CHGRP /%s \"/%s\"\n" "#CHGRP /%s \"/%s\"\n"
"chgrp %s \"/%s\" 2>/dev/null\n" "chgrp %s \"/%s\" 2>/dev/null\n"
"echo '### 000'\n", "echo '### 000'\n",
sgroup, rpath.s, sgroup, rpath,
sgroup, rpath.s); sgroup, rpath);
/* fish_send_command(me, super, buf, OPT_FLUSH); */ /* fish_send_command(me, super, buf, OPT_FLUSH); */
POSTFIX (OPT_FLUSH) POSTFIX (OPT_FLUSH)
} }
@ -996,7 +992,7 @@ static int fish_unlink (struct vfs_class *me, const char *path)
"#DELE /%s\n" "#DELE /%s\n"
"rm -f /%s 2>/dev/null\n" "rm -f /%s 2>/dev/null\n"
"echo '### 000'\n", "echo '### 000'\n",
rpath.s, rpath.s); rpath, rpath);
POSTFIX(OPT_FLUSH); POSTFIX(OPT_FLUSH);
} }
@ -1010,7 +1006,7 @@ static int fish_mkdir (struct vfs_class *me, const char *path, mode_t mode)
"#MKD /%s\n" "#MKD /%s\n"
"mkdir /%s 2>/dev/null\n" "mkdir /%s 2>/dev/null\n"
"echo '### 000'\n", "echo '### 000'\n",
rpath.s, rpath.s); rpath, rpath);
POSTFIX(OPT_FLUSH); POSTFIX(OPT_FLUSH);
} }
@ -1021,7 +1017,7 @@ static int fish_rmdir (struct vfs_class *me, const char *path)
"#RMD /%s\n" "#RMD /%s\n"
"rmdir /%s 2>/dev/null\n" "rmdir /%s 2>/dev/null\n"
"echo '### 000'\n", "echo '### 000'\n",
rpath.s, rpath.s); rpath, rpath);
POSTFIX(OPT_FLUSH); POSTFIX(OPT_FLUSH);
} }
@ -1079,7 +1075,7 @@ fish_fill_names (struct vfs_class *me, fill_names_f func)
name = g_strconcat ("/#sh:", SUP.user, "@", SUP.host, flags, name = g_strconcat ("/#sh:", SUP.user, "@", SUP.host, flags,
"/", SUP.cwdir, (char *) NULL); "/", SUP.cwdir, (char *) NULL);
(*func)(name); (*func)(name);
mhl_mem_free (name); g_free (name);
super = super->next; super = super->next;
} }
} }

View File

@ -44,7 +44,7 @@ What to do with this?
int f = !strcmp( remote_path, "/~" ); int f = !strcmp( remote_path, "/~" );
if (f || !strncmp( remote_path, "/~/", 3 )) { if (f || !strncmp( remote_path, "/~/", 3 )) {
char *s; char *s;
s = mhl_str_dir_plus_file( qhome (*bucket), remote_path +3-f ); s = concat_dir_and_file( qhome (*bucket), remote_path +3-f );
g_free (remote_path); g_free (remote_path);
remote_path = s; remote_path = s;
} }
@ -69,8 +69,6 @@ What to do with this?
#include <errno.h> #include <errno.h>
#include <ctype.h> #include <ctype.h>
#include <mhl/string.h>
#include "../src/global.h" #include "../src/global.h"
#include "../src/tty.h" /* enable/disable interrupt key */ #include "../src/tty.h" /* enable/disable interrupt key */
#include "../src/wtools.h" /* message() */ #include "../src/wtools.h" /* message() */
@ -557,7 +555,7 @@ ftpfs_load_no_proxy_list (void)
if (mc_file) if (mc_file)
return; return;
mc_file = mhl_str_dir_plus_file (mc_home, "mc.no_proxy"); mc_file = concat_dir_and_file (mc_home, "mc.no_proxy");
if (exist_file (mc_file) && if (exist_file (mc_file) &&
(npf = fopen (mc_file, "r"))) { (npf = fopen (mc_file, "r"))) {
while (fgets (s, sizeof (s), npf)) { while (fgets (s, sizeof (s), npf)) {
@ -1232,7 +1230,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); ftpfs_open_data_connection (me, super, "LIST -la", 0, TYPE_ASCII, 0);
else { else {
/* Trailing "/." is necessary if remote_path is a symlink */ /* Trailing "/." is necessary if remote_path is a symlink */
char *path = mhl_str_dir_plus_file (remote_path, "."); char *path = concat_dir_and_file (remote_path, ".");
sock = sock =
ftpfs_open_data_connection (me, super, "LIST -la", path, TYPE_ASCII, ftpfs_open_data_connection (me, super, "LIST -la", path, TYPE_ASCII,
0); 0);
@ -1888,7 +1886,7 @@ static int ftpfs_netrc_lookup (const char *host, char **login, char **pass)
} }
/* Load current .netrc */ /* Load current .netrc */
netrcname = mhl_str_dir_plus_file (home_dir, ".netrc"); netrcname = concat_dir_and_file (home_dir, ".netrc");
netrcp = netrc = load_file (netrcname); netrcp = netrc = load_file (netrcname);
if (netrc == NULL) { if (netrc == NULL) {
g_free (netrcname); g_free (netrcname);

View File

@ -31,8 +31,6 @@
#include <signal.h> #include <signal.h>
#include <ctype.h> /* is_digit() */ #include <ctype.h> /* is_digit() */
#include <mhl/string.h>
#include "../src/global.h" #include "../src/global.h"
#include "../src/tty.h" /* enable/disable interrupt key */ #include "../src/tty.h" /* enable/disable interrupt key */
#include "../src/wtools.h" /* message() */ #include "../src/wtools.h" /* message() */
@ -124,7 +122,7 @@ vfs_getid (struct vfs_class *vclass, const char *dir)
vfsid id = NULL; vfsid id = NULL;
/* append slash if needed */ /* append slash if needed */
dir1 = mhl_str_dir_plus_file (dir, ""); dir1 = concat_dir_and_file (dir, "");
if (vclass->getid) if (vclass->getid)
id = (*vclass->getid) (vclass, dir1); id = (*vclass->getid) (vclass, dir1);

View File

@ -406,7 +406,7 @@ mcfs_get_path (mcfs_connection **mc, const char *path)
int f = !strcmp (remote_path, "/~"); int f = !strcmp (remote_path, "/~");
if (f || !strncmp (remote_path, "/~/", 3)) { if (f || !strncmp (remote_path, "/~/", 3)) {
char *s; char *s;
s = mhl_str_dir_plus_file (mcfs_gethome (*mc), s = concat_dir_and_file (mcfs_gethome (*mc),
remote_path + 3 - f); remote_path + 3 - f);
g_free (remote_path); g_free (remote_path);
remote_path = s; remote_path = s;

View File

@ -34,8 +34,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <mhl/string.h>
#include "../src/global.h" #include "../src/global.h"
#include "../src/tty.h" /* enable/disable interrupt key */ #include "../src/tty.h" /* enable/disable interrupt key */
#include "../src/wtools.h" /* message() */ #include "../src/wtools.h" /* message() */
@ -338,7 +336,7 @@ static int sfs_init (struct vfs_class *me)
(void) me; (void) me;
mc_sfsini = mhl_str_dir_plus_file (mc_home, "extfs" PATH_SEP_STR "sfs.ini"); mc_sfsini = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR "sfs.ini");
cfg = fopen (mc_sfsini, "r"); cfg = fopen (mc_sfsini, "r");
if (!cfg){ if (!cfg){

View File

@ -49,8 +49,6 @@
#include <string.h> #include <string.h>
#include <mhl/string.h>
#include "vfs.h" #include "vfs.h"
#include "vfs-impl.h" #include "vfs-impl.h"
#include "smbfs.h" #include "smbfs.h"
@ -1213,7 +1211,7 @@ smbfs_get_path (smbfs_connection ** sc, const char *path)
int f = !strcmp (remote_path, "/~"); int f = !strcmp (remote_path, "/~");
if (f || !strncmp (remote_path, "/~/", 3)) { if (f || !strncmp (remote_path, "/~/", 3)) {
char *s; char *s;
s = mhl_str_dir_plus_file ((*sc)->home, remote_path + 3 - f); s = concat_dir_and_file ((*sc)->home, remote_path + 3 - f);
g_free (remote_path); g_free (remote_path);
return s; return s;
} }

View File

@ -38,8 +38,6 @@
#include <signal.h> #include <signal.h>
#include <ctype.h> /* is_digit() */ #include <ctype.h> /* is_digit() */
#include <mhl/string.h>
#include "../src/global.h" #include "../src/global.h"
#include "../src/tty.h" /* enable/disable interrupt key */ #include "../src/tty.h" /* enable/disable interrupt key */
#include "../src/wtools.h" /* message() */ #include "../src/wtools.h" /* message() */
@ -658,7 +656,7 @@ vfs_canon (const char *path)
if (*path != PATH_SEP){ if (*path != PATH_SEP){
char *local, *result; char *local, *result;
local = mhl_str_dir_plus_file (current_dir, path); local = concat_dir_and_file (current_dir, path);
result = vfs_canon (local); result = vfs_canon (local);
g_free (local); g_free (local);