2005-10-25 [colin] 1.9.15cvs107
[claws.git] / src / addrbook.c
index b7ced22f79988d72dbd31f01d8f4d51b35bef3cb..e0f8861d0ff1678e401b04d831e5c7d7948f9d89 100644 (file)
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 /* General functions for accessing address book files */
@@ -22,7 +22,6 @@
 #include <glib.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <dirent.h>
 #include <sys/stat.h>
 #include <math.h>
 #include <setjmp.h>
@@ -509,6 +508,7 @@ static void addrbook_parse_attribute(XMLFile *file, ItemPerson *person)
 
        element = xml_get_element(file);
        addritem_attrib_set_value(uAttr, element);
+       g_free(element);
 
        if (uAttr) {
                if (person) {
@@ -1259,7 +1259,7 @@ gint addrbook_write_to(AddressBookFile *book, gchar *newFile)
 
        book->retVal = MGU_OPEN_FILE;
 #ifdef DEV_STANDALONE
-       fp = fopen(fileSpec, "wb");
+       fp = g_fopen(fileSpec, "wb");
        g_free(fileSpec);
        if (fp) {
                fputs("<?xml version=\"1.0\" ?>\n", fp);
@@ -1268,8 +1268,7 @@ gint addrbook_write_to(AddressBookFile *book, gchar *newFile)
        g_free(fileSpec);
        if (pfile) {
                fp = pfile->fp;
-               fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
-                       conv_get_current_charset_str());
+               fprintf( fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL );
 #endif
                addrbook_write_elem_s(fp, 0, AB_ELTAG_ADDRESS_BOOK);
                addrbook_write_attr(fp, AB_ATTAG_NAME,
@@ -1888,8 +1887,8 @@ ItemFolder *addrbook_remove_folder_delete(AddressBookFile *book,
  */
 GList *addrbook_get_bookfile_list(AddressBookFile *book) {
        gchar *adbookdir;
-       DIR *dp;
-       struct dirent *entry;
+       GDir *dir;
+       const gchar *dir_name;
        struct stat statbuf;
        gchar buf[WORK_BUFLEN];
        gchar numbuf[WORK_BUFLEN];
@@ -1916,7 +1915,7 @@ GList *addrbook_get_bookfile_list(AddressBookFile *book) {
        adbookdir = g_strdup(buf);
        strcat(buf, ADDRBOOK_PREFIX);
 
-       if ((dp = opendir(adbookdir)) == NULL) {
+       if( ( dir = g_dir_open( adbookdir, 0, NULL ) ) == NULL ) {
                book->retVal = MGU_OPEN_DIRECTORY;
                g_free(adbookdir);
                return NULL;
@@ -1927,25 +1926,25 @@ GList *addrbook_get_bookfile_list(AddressBookFile *book) {
        lennum = FILE_NUMDIGITS + lenpre;
        maxval = -1;
 
-       while ((entry = readdir(dp)) != NULL) {
+       while( ( dir_name = g_dir_read_name( dir ) ) != NULL ) {
                gchar *endptr = NULL;
                gint i;
                gboolean flg;
 
                strcpy(buf, adbookdir);
-               strcat(buf, entry->d_name);
+               strcat( buf, dir_name );
                stat(buf, &statbuf);
-               if (S_IFREG & statbuf.st_mode) {
+               if (S_ISREG(statbuf.st_mode)) {
                        if (strncmp(
-                               entry->d_name,
+                               dir_name,
                                ADDRBOOK_PREFIX, lenpre) == 0)
                        {
                                if (strncmp(
-                                       (entry->d_name) + lennum,
+                                       (dir_name) + lennum,
                                        ADDRBOOK_SUFFIX, lensuf) == 0)
                                {
                                        strncpy(numbuf,
-                                               (entry->d_name) + lenpre,
+                                               (dir_name) + lenpre,
                                                FILE_NUMDIGITS);
                                        numbuf[FILE_NUMDIGITS] = '\0';
                                        flg = TRUE;
@@ -1962,14 +1961,14 @@ GList *addrbook_get_bookfile_list(AddressBookFile *book) {
                                                        if (val > maxval) maxval = val;
                                                        fileList = g_list_append(
                                                                fileList,
-                                                               g_strdup(entry->d_name));
+                                                               g_strdup(dir_name));
                                                }
                                        }
                                }
                        }
                }
        }
-       closedir(dp);
+       g_dir_close( dir );
        g_free(adbookdir);
 
        book->maxValue = maxval;