Kaydet (Commit) c4145b7f authored tarafından Enrico Tröger's avatar Enrico Tröger

Add get_path_max() to get a sane value if PATH_MAX is not defined.

Change code where PATH_MAX was used unnecessarily.
Use GSlice API when building against GLib >= 2.10 (patch by Colomban Wendling, thanks).

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3142 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst 95d1cd2c
......@@ -3,6 +3,13 @@
* src/highlighting.c, data/filetypes.css:
Change style for 'identifier3' to bold to be in sync with the
other identifier styles.
* tagmanager/general.h, tagmanager/tm_file_entry.c,
tagmanager/tm_project.c, tagmanager/tm_symbol.c, tagmanager/tm_tag.c,
tagmanager/tm_work_object.c:
Add get_path_max() to get a sane value if PATH_MAX is not defined.
Change code where PATH_MAX was used unnecessarily.
Use GSlice API when building against GLib >= 2.10
(patch by Colomban Wendling, thanks).
2008-10-20 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
......
......@@ -39,7 +39,6 @@
#endif
/* MS-DOS doesn't allow manipulation of standard error, so we send it to
* stdout instead.
*/
......
......@@ -27,6 +27,15 @@
#include "tm_work_object.h"
#include "tm_file_entry.h"
#if GLIB_CHECK_VERSION (2, 10, 0)
/* Use GSlices if present */
#define FILE_NEW(T) ((T) = g_slice_new0(TMFileEntry))
#define FILE_FREE(T) g_slice_free(TMFileEntry, (T))
#else /* GLib < 2.10 */
static GMemChunk *file_mem_chunk = NULL;
#define FILE_NEW(T) {\
......@@ -37,6 +46,9 @@ static GMemChunk *file_mem_chunk = NULL;
#define FILE_FREE(T) g_mem_chunk_free(file_mem_chunk, (T))
#endif /* GLib version check */
void tm_file_entry_print(TMFileEntry *entry, gpointer __unused__ user_data
, guint level)
{
......@@ -120,7 +132,7 @@ TMFileEntry *tm_file_entry_new(const char *path, TMFileEntry *parent
DIR *dir;
struct dirent *dir_entry;
TMFileEntry *new_entry;
char file_name[PATH_MAX];
char *file_name;
struct stat s;
char *entries = NULL;
......@@ -163,7 +175,7 @@ TMFileEntry *tm_file_entry_new(const char *path, TMFileEntry *parent
tm_file_entry_free(entry);
return NULL;
}
g_snprintf(file_name, PATH_MAX, "%s/CVS/Entries", entry->path);
file_name = g_strdup_printf("%s/CVS/Entries", entry->path);
if (0 == g_stat(file_name, &s))
{
if (S_ISREG(s.st_mode))
......@@ -188,6 +200,7 @@ TMFileEntry *tm_file_entry_new(const char *path, TMFileEntry *parent
}
}
}
g_free(file_name);
if (NULL != (dir = opendir(entry->path)))
{
while (NULL != (dir_entry = readdir(dir)))
......@@ -195,11 +208,11 @@ TMFileEntry *tm_file_entry_new(const char *path, TMFileEntry *parent
if ((0 == strcmp(dir_entry->d_name, "."))
|| (0 == strcmp(dir_entry->d_name, "..")))
continue;
g_snprintf(file_name, PATH_MAX, "%s/%s", entry->path
, dir_entry->d_name);
file_name = g_strdup_printf("%s/%s", entry->path, dir_entry->d_name);
new_entry = tm_file_entry_new(file_name, entry, recurse
, file_match, file_unmatch, dir_match, dir_unmatch
, ignore_hidden_files, ignore_hidden_dirs);
g_free(file_name);
if (new_entry)
{
if (entries)
......
......@@ -61,7 +61,7 @@ gboolean tm_project_init(TMProject *project, const char *dir
, const char **sources, const char **ignore, gboolean force)
{
struct stat s;
char path[PATH_MAX];
char *path;
g_return_val_if_fail((project && dir), FALSE);
#ifdef TM_DEBUG
......@@ -88,7 +88,7 @@ gboolean tm_project_init(TMProject *project, const char *dir
else
project->ignore = s_ignore;
project->file_list = NULL;
g_snprintf(path, PATH_MAX, "%s/%s", project->dir, TM_FILE_NAME);
path = g_strdup_printf("%s/%s", project->dir, TM_FILE_NAME);
if ((0 != g_stat(path, &s)) || (0 == s.st_size))
force = TRUE;
if (FALSE == tm_work_object_init(&(project->work_object),
......@@ -96,14 +96,18 @@ gboolean tm_project_init(TMProject *project, const char *dir
{
g_warning("Unable to init project file %s", path);
g_free(project->dir);
g_free(path);
g_free(path);
return FALSE;
}
if (! tm_workspace_add_object(TM_WORK_OBJECT(project)))
{
g_warning("Unable to init project file %s", path);
g_free(project->dir);
g_free(path);
return FALSE;
}
g_free(path);
tm_project_open(project, force);
if (!project->file_list || (0 == project->file_list->len))
tm_project_autoscan(project);
......
......@@ -12,6 +12,15 @@
#include <string.h>
#include "tm_symbol.h"
#if GLIB_CHECK_VERSION (2, 10, 0)
/* Use GSlices if present */
#define SYM_NEW(T) ((T) = g_slice_new0(TMSymbol))
#define SYM_FREE(T) g_slice_free(TMSymbol, (T))
#else /* GLib < 2.10 */
static GMemChunk *sym_mem_chunk = NULL;
#define SYM_NEW(T) {\
......@@ -22,6 +31,9 @@ static GMemChunk *sym_mem_chunk = NULL;
#define SYM_FREE(T) g_mem_chunk_free(sym_mem_chunk, (T))
#endif /* GLib version check */
void tm_symbol_print(TMSymbol *sym, guint level)
{
guint i;
......
......@@ -17,6 +17,15 @@
#define LIBCTAGS_DEFINED
#include "tm_tag.h"
#if GLIB_CHECK_VERSION (2, 10, 0)
/* Use GSlices if present */
#define TAG_NEW(T) ((T) = g_slice_new0(TMTag))
#define TAG_FREE(T) g_slice_free(TMTag, (T))
#else /* GLib < 2.10 */
static GMemChunk *s_tag_mem_chunk = NULL;
#define TAG_NEW(T) {\
......@@ -27,6 +36,9 @@ static GMemChunk *s_tag_mem_chunk = NULL;
#define TAG_FREE(T) g_mem_chunk_free(s_tag_mem_chunk, (T))
#endif /* GLib version check */
/* Note: To preserve binary compatibility, it is very important
that you only *append* to this list ! */
enum
......
......@@ -26,18 +26,33 @@
static GPtrArray *s_work_object_subclasses = NULL;
static int get_path_max(const char *path)
{
#ifdef PATH_MAX
return PATH_MAX;
#else
int path_max = pathconf(path, _PC_PATH_MAX);
if (path_max <= 0)
path_max = 4096;
return path_max;
#endif
}
#ifdef G_OS_WIN32
/* realpath implementation for Windows found at http://bugzilla.gnome.org/show_bug.cgi?id=342926
* this one is better than e.g. liberty's lrealpath because this one uses Win32 API and works
* with special chars within the filename */
static char *realpath (const char *pathname, char resolved_path[PATH_MAX])
static char *realpath (const char *pathname, char *resolved_path)
{
int size;
if (resolved_path != NULL)
{
size = GetFullPathNameA (pathname, PATH_MAX, resolved_path, NULL);
if (size > PATH_MAX)
int path_max = get_path_max(pathname);
size = GetFullPathNameA (pathname, path_max, resolved_path, NULL);
if (size > path_max)
return NULL;
else
return resolved_path;
......@@ -56,10 +71,11 @@ gchar *tm_get_real_path(const gchar *file_name)
{
if (file_name)
{
gchar path[PATH_MAX+1];
memset(path, '\0', PATH_MAX+1);
gsize len = get_path_max(file_name) + 1;
gchar *path = g_malloc0(len);
realpath(file_name, path);
return g_strdup(path);
return path;
}
else
return NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment