2005-07-04 [paul] 1.9.12cvs17

sync with main (forgotten in last commit)

	* src/common/utils.c
	* src/common/utils.h
		check_line_length(): new.
		is_dir_exist()
		is_file_entry_exist()
		dirent_is_regular_file()
		dirent_is_directory(): use g_file_test() instead of stat().
This commit is contained in:
Paul Mangan 2005-07-04 10:40:54 +00:00
parent 0fbe9ba4ce
commit 56df72ffe8
5 changed files with 61 additions and 27 deletions

View file

@ -1,3 +1,15 @@
2005-07-04 [paul] 1.9.12cvs17
sync with main (forgotten in last commit)
* src/common/utils.c
* src/common/utils.h
check_line_length(): new.
is_dir_exist()
is_file_entry_exist()
dirent_is_regular_file()
dirent_is_directory(): use g_file_test() instead of stat().
2005-07-04 [paul] 1.9.12cvs16
sync with main:

View file

@ -611,3 +611,4 @@
( cvs diff -u -r 1.179.2.44 -r 1.179.2.45 src/imap.c; ) > 1.9.12cvs14.patchset
( cvs diff -u -r 1.25.2.13 -r 1.25.2.14 src/stock_pixmap.c; ) > 1.9.12cvs15.patchset
( cvs diff -u -r 1.382.2.139 -r 1.382.2.140 src/compose.c; cvs diff -u -r 1.18.2.8 -r 1.18.2.9 src/jpilot.c; cvs diff -u -r 1.47.2.21 -r 1.47.2.22 src/procheader.c; cvs diff -u -r 1.14.2.2 -r 1.14.2.3 src/vcard.c; ) > 1.9.12cvs16.patchset
( cvs diff -u -r 1.36.2.35 -r 1.36.2.36 src/common/utils.c; cvs diff -u -r 1.20.2.18 -r 1.20.2.19 src/common/utils.h; ) > 1.9.12cvs17.patchset

View file

@ -11,7 +11,7 @@ MINOR_VERSION=9
MICRO_VERSION=12
INTERFACE_AGE=0
BINARY_AGE=0
EXTRA_VERSION=16
EXTRA_VERSION=17
EXTRA_RELEASE=
EXTRA_GTK2_VERSION=

View file

@ -1174,6 +1174,32 @@ gint get_quote_level(const gchar *str, const gchar *quote_chars)
return quote_level;
}
gint check_line_length(const gchar *str, gint max_chars, gint *line)
{
const gchar *p = str, *q;
gint cur_line = 0, len;
while ((q = strchr(p, '\n')) != NULL) {
len = q - p + 1;
if (len > max_chars) {
if (line)
*line = cur_line;
return -1;
}
p = q + 1;
++cur_line;
}
len = strlen(p);
if (len > max_chars) {
if (line)
*line = cur_line;
return -1;
}
return 0;
}
const gchar * line_has_quote_char(const gchar * str, const gchar *quote_chars)
{
gchar * position = NULL;
@ -1897,41 +1923,22 @@ gboolean file_exist(const gchar *file, gboolean allow_fifo)
gboolean is_dir_exist(const gchar *dir)
{
struct stat s;
if (dir == NULL)
return FALSE;
if (stat(dir, &s) < 0) {
if (ENOENT != errno) FILE_OP_ERROR(dir, "stat");
return FALSE;
}
if (S_ISDIR(s.st_mode))
return TRUE;
return FALSE;
return g_file_test(dir, G_FILE_TEST_IS_DIR);
}
gboolean is_file_entry_exist(const gchar *file)
{
struct stat s;
if (file == NULL)
return FALSE;
if (stat(file, &s) < 0) {
if (ENOENT != errno) FILE_OP_ERROR(file, "stat");
return FALSE;
}
return TRUE;
return g_file_test(file, G_FILE_TEST_EXISTS);
}
gboolean dirent_is_regular_file(struct dirent *d)
{
struct stat s;
#ifdef HAVE_DIRENT_D_TYPE
if (d->d_type == DT_REG)
return TRUE;
@ -1939,13 +1946,11 @@ gboolean dirent_is_regular_file(struct dirent *d)
return FALSE;
#endif
return (stat(d->d_name, &s) == 0 && S_ISREG(s.st_mode));
return g_file_test(d->d_name, G_FILE_TEST_IS_REGULAR);
}
gboolean dirent_is_directory(struct dirent *d)
{
struct stat s;
#ifdef HAVE_DIRENT_D_TYPE
if (d->d_type == DT_DIR)
return TRUE;
@ -1953,7 +1958,7 @@ gboolean dirent_is_directory(struct dirent *d)
return FALSE;
#endif
return (stat(d->d_name, &s) == 0 && S_ISDIR(s.st_mode));
return g_file_test(d->d_name, G_FILE_TEST_IS_DIR);
}
gint change_dir(const gchar *dir)
@ -3417,6 +3422,13 @@ void get_rfc822_date(gchar *buf, gint len)
day, dd, mon, yyyy, hh, mm, ss, tzoffset(&t));
}
/* just a wrapper to suppress the warning of gcc about %c */
size_t my_strftime(gchar *s, size_t max, const gchar *format,
const struct tm *tm)
{
return strftime(s, max, format, tm);
}
void debug_set_mode(gboolean mode)
{
debug_mode = mode;

View file

@ -1,6 +1,6 @@
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
* Copyright (C) 1999-2004 Hiroyuki Yamamoto
* Copyright (C) 1999-2005 Hiroyuki Yamamoto
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -320,6 +320,10 @@ gboolean is_header_line (const gchar *str);
gboolean is_ascii_str (const guchar *str);
gint get_quote_level (const gchar *str,
const gchar *quote_chars);
gint check_line_length (const gchar *str,
gint max_chars,
gint *line);
gchar *strstr_with_skip_quote (const gchar *haystack,
const gchar *needle);
gchar *strchr_parenthesis_close (const gchar *str,
@ -451,6 +455,11 @@ gchar *tzoffset (time_t *now);
void get_rfc822_date (gchar *buf,
gint len);
size_t my_strftime (gchar *s,
size_t max,
const gchar *format,
const struct tm *tm);
/* debugging */
void debug_print_real (const gchar *format, ...) G_GNUC_PRINTF(1, 2);