![Timur Bakeyev](/assets/img/avatar_default.png)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru> * Converted memory managment to Glib. Now we use g_new()/g_malloc()/ g_strdup()/g_free() routings. Also, copy_strings() replaced by g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by g_snprintf(). * Some sequences of malloc()/sprintf() changed to g_strdup_printf(). * mad.[ch]: Modified, to work with new GLib's memory managment. Fixed a missing #undef for tempnam, which caused dead loop. Add several new functions to emulate GLib memory managment. *main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD messages to the file. * util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp() and strdup() - we have g_ equivalences. Remove get_full_name() - it is similar to concat_dir_and_file(). Some other tricks with g_* functions. * global.h: Modified, extended. Now it is main memory mangment include - i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h", "util.h" and "mad.h" done there. This elimanates problem with proper or- der of #include's. * All around the source - changed order of #include's, most of them gone to global.h (see above), minor changes, like "0" -> NULL in string func- tions.
108 строки
1.8 KiB
C
108 строки
1.8 KiB
C
/*
|
|
* filenot.c: wrapper for routines to notify the
|
|
* tree about the changes made to the directory
|
|
* structure.
|
|
*
|
|
* Author:
|
|
* Janne Kukonlehto
|
|
* Miguel de Icaza
|
|
*/
|
|
|
|
#include <config.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include "global.h"
|
|
#include "../vfs/vfs.h"
|
|
|
|
static char *get_absolute_name (char *file)
|
|
{
|
|
char dir [MC_MAXPATHLEN];
|
|
|
|
if (file [0] == PATH_SEP)
|
|
return g_strdup (file);
|
|
mc_get_current_wd (dir, MC_MAXPATHLEN);
|
|
return concat_dir_and_file (dir, file);
|
|
}
|
|
|
|
static int
|
|
my_mkdir_rec (char *s, mode_t mode)
|
|
{
|
|
char *p, *q;
|
|
int result;
|
|
|
|
if (!mc_mkdir (s, mode))
|
|
return 0;
|
|
else if (errno != ENOENT)
|
|
return -1;
|
|
|
|
/* FIXME: should check instead if s is at the root of that filesystem */
|
|
if (!vfs_file_is_local (s))
|
|
return -1;
|
|
|
|
if (!strcmp (s, PATH_SEP_STR)) {
|
|
errno = ENOTDIR;
|
|
return -1;
|
|
}
|
|
|
|
p = concat_dir_and_file (s, "..");
|
|
q = vfs_canon (p);
|
|
g_free (p);
|
|
|
|
if (!(result = my_mkdir_rec (q, mode)))
|
|
result = mc_mkdir (s, mode);
|
|
|
|
g_free (q);
|
|
return result;
|
|
}
|
|
|
|
int
|
|
my_mkdir (char *s, mode_t mode)
|
|
{
|
|
int result;
|
|
|
|
result = mc_mkdir (s, mode);
|
|
#ifdef OS2_NT
|
|
/* .ado: it will be disabled in OS/2 and NT */
|
|
/* otherwise crash if directory already exists. */
|
|
return result;
|
|
#endif
|
|
if (result) {
|
|
char *p = vfs_canon (s);
|
|
|
|
result = my_mkdir_rec (p, mode);
|
|
g_free (p);
|
|
}
|
|
if (result == 0){
|
|
s = get_absolute_name (s);
|
|
|
|
#if FIXME
|
|
tree_add_entry (tree, s);
|
|
#endif
|
|
|
|
g_free (s);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
int my_rmdir (char *s)
|
|
{
|
|
int result;
|
|
#if FIXME
|
|
WTree *tree = 0;
|
|
#endif
|
|
|
|
/* FIXME: Should receive a Wtree! */
|
|
result = mc_rmdir (s);
|
|
if (result == 0){
|
|
s = get_absolute_name (s);
|
|
|
|
#if FIXME
|
|
tree_remove_entry (tree, s);
|
|
#endif
|
|
|
|
g_free (s);
|
|
}
|
|
return result;
|
|
}
|
|
|