static void set_resource_limits (const char *input) { struct rlimit limit; struct stat buf; rlim_t max; max = MAX_HELPER_MEMORY; /* Set the maximum virtual size depending on the size * of the file to process, as we wouldn't be able to * mmap it otherwise */ if (input == NULL) { max = MAX_HELPER_MEMORY; } else if (g_stat (input, &buf) == 0) { max = MAX_HELPER_MEMORY + buf.st_size; } else if (g_str_has_prefix (input, "file://") != FALSE) { char *file; file = g_filename_from_uri (input, NULL, NULL); if (file != NULL && g_stat (file, &buf) == 0) max = MAX_HELPER_MEMORY + buf.st_size; g_free (file); } limit.rlim_cur = max; limit.rlim_max = max; setrlimit (RLIMIT_DATA, &limit); limit.rlim_cur = MAX_HELPER_SECONDS; limit.rlim_max = MAX_HELPER_SECONDS; setrlimit (RLIMIT_CPU, &limit); }
void archive_scan_folder(const char* dir) { struct stat st; DIR* root; struct dirent* ent; gchar cwd[PATH_MAX]; gchar path[PATH_MAX]; getcwd(cwd, PATH_MAX); if (g_stat(dir, &st) == -1) return; if (! S_ISDIR(st.st_mode)) return; if (!(root = opendir(dir))) return; chdir(dir); while ((ent = readdir(root)) != NULL) { if (strcmp(".", ent->d_name) == 0 || strcmp("..", ent->d_name) == 0) continue; g_stat(ent->d_name, &st); sprintf(path, "%s/%s", dir, ent->d_name); if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { archive_add_file(path); } else if (S_ISDIR(st.st_mode)) { archive_scan_folder(path); } } chdir(cwd); closedir(root); }
void resize(gchar *orig, gchar *thumb, gchar *size) { GStatBuf oinfo, tinfo; int oval = g_stat(orig, &oinfo); int tval = g_stat(thumb, &tinfo); if (tval || (!oval && oinfo.st_mtime > tinfo.st_mtime)) { /* god damn glib */ gchar *argv[] = {"convert", "-resize", size, orig, thumb, NULL}; g_spawn_sync(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, NULL, NULL); } }
gboolean gs_auth_priv_init (void) { /* We have nothing to do at init-time. However, we might as well do some error checking. If "/etc/pam.d" exists and is a directory, but "/etc/pam.d/xlock" does not exist, warn that PAM probably isn't going to work. This is a priv-init instead of a non-priv init in case the directory is unreadable or something (don't know if that actually happens.) */ const char dir [] = "/etc/pam.d"; const char file [] = "/etc/pam.d/" PAM_SERVICE_NAME; const char file2 [] = "/etc/pam.conf"; struct stat st; if (g_stat (dir, &st) == 0 && st.st_mode & S_IFDIR) { if (g_stat (file, &st) != 0) { g_warning ("%s does not exist.\n" "Authentication via PAM is unlikely to work.", file); } } else if (g_stat (file2, &st) == 0) { FILE *f = g_fopen (file2, "r"); if (f) { gboolean ok = FALSE; char buf[255]; while (fgets (buf, sizeof(buf), f)) { if (strstr (buf, PAM_SERVICE_NAME)) { ok = TRUE; break; } } fclose (f); if (!ok) { g_warning ("%s does not list the `%s' service.\n" "Authentication via PAM is unlikely to work.", file2, PAM_SERVICE_NAME); } } /* else warn about file2 existing but being unreadable? */ } else { g_warning ("Neither %s nor %s exist.\n" "Authentication via PAM is unlikely to work.", file2, file); } /* Return true anyway, just in case. */ return TRUE; }
gboolean tm_work_object_init(TMWorkObject *work_object, guint type, const char *file_name , gboolean create) { struct stat s; int status; if (file_name != NULL) { if (0 != (status = g_stat(file_name, &s))) { if (create) { FILE *f; if (NULL == (f = g_fopen(file_name, "a+"))) { g_warning("Unable to create file %s", file_name); return FALSE; } fclose(f); status = g_stat(file_name, &s); } } if (0 != status) { /* g_warning("Unable to stat %s", file_name);*/ return FALSE; } if (!S_ISREG(s.st_mode)) { g_warning("%s: Not a regular file", file_name); return FALSE; } work_object->file_name = tm_get_real_path(file_name); work_object->short_name = strrchr(work_object->file_name, '/'); if (work_object->short_name) ++ work_object->short_name; else work_object->short_name = work_object->file_name; } else { work_object->file_name = NULL; work_object->short_name = NULL; } work_object->type = type; work_object->parent = NULL; work_object->analyze_time = 0; work_object->tags_array = NULL; return TRUE; }
static void magnatune_check_update(void) { gchar *db_path = NULL; gchar *new_db_path = NULL; gchar *new_crc_path = NULL; static gboolean already_checked = FALSE; struct stat file_st; GTimeVal tv; GrlNetWc *wc = NULL; GRL_DEBUG("magnatune_check_update"); if (already_checked == TRUE) return; already_checked = TRUE; g_get_current_time(&tv); new_db_path = g_build_filename(g_get_user_data_dir(), "grilo-plugins", GRL_SQL_NEW_DB, NULL); if (g_file_test(new_db_path, G_FILE_TEST_EXISTS) == FALSE) { db_path = g_build_filename(g_get_user_data_dir(), "grilo-plugins", GRL_SQL_DB, NULL); g_stat(db_path, &file_st); if (tv.tv_sec - file_st.st_mtime > DB_UPDATE_TIME_INTERVAL) { new_crc_path = g_build_filename(g_get_user_data_dir(), "grilo-plugins", GRL_SQL_NEW_CRC, NULL); g_stat(new_crc_path, &file_st); if ((g_file_test(new_crc_path, G_FILE_TEST_EXISTS) == FALSE) || (tv.tv_sec - file_st.st_mtime > CRC_UPDATE_TIME_INTERVAL)) { wc = grl_net_wc_new(); grl_net_wc_request_async(wc, URL_GET_CRC, NULL, magnatune_check_update_done, NULL); } g_free(new_crc_path); } g_free(db_path); } g_free(new_db_path); }
static gboolean check_file_size (GstValidateMediaInfo * mi) { GStatBuf statbuf; gchar *filepath; guint64 size = 0; gboolean ret = TRUE; GError *err = NULL; filepath = g_filename_from_uri (mi->uri, NULL, &err); if (!filepath) { g_error_free (err); return FALSE; } if (g_stat (filepath, &statbuf) == 0) { size = statbuf.st_size; } else { ret = FALSE; goto end; } mi->file_size = size; end: g_free (filepath); return ret; }
/** * gimp_thumb_file_test: * @filename: a filename in the encoding of the filesystem * @mtime: return location for modification time * @size: return location for file size * @err_no: return location for system "errno" * * This is a convenience and portability wrapper around stat(). It * checks if the given @filename exists and returns modification time * and file size in 64bit integer values. * * Return value: The type of the file, or #GIMP_THUMB_FILE_TYPE_NONE if * the file doesn't exist. **/ GimpThumbFileType gimp_thumb_file_test (const gchar *filename, gint64 *mtime, gint64 *size, gint *err_no) { struct stat s; g_return_val_if_fail (filename != NULL, FALSE); if (g_stat (filename, &s) == 0) { if (mtime) *mtime = s.st_mtime; if (size) *size = s.st_size; if (err_no) *err_no = 0; if (S_ISREG (s.st_mode)) { return GIMP_THUMB_FILE_TYPE_REGULAR; } else if (S_ISDIR (s.st_mode)) { return GIMP_THUMB_FILE_TYPE_FOLDER; } return GIMP_THUMB_FILE_TYPE_SPECIAL; } if (mtime) *mtime = 0; if (size) *size = 0; if (err_no) *err_no = errno; return GIMP_THUMB_FILE_TYPE_NONE; }
static gchar * gen_context(const char *file_name, const char *file_path) { struct stat st; gsize size = 0; MsnContextHeader header; gchar *u8 = NULL; guchar *base; guchar *n; gchar *ret; gunichar2 *uni = NULL; glong currentChar = 0; glong uni_len = 0; gsize len; if (g_stat(file_path, &st) == 0) size = st.st_size; if(!file_name) { u8 = purple_utf8_try_convert(g_basename(file_path)); file_name = u8; } uni = g_utf8_to_utf16(file_name, -1, NULL, &uni_len, NULL); if(u8) { g_free(u8); file_name = NULL; u8 = NULL; } len = sizeof(MsnContextHeader) + MAX_FILE_NAME_LEN + 4; header.length = GUINT32_TO_LE(len); header.unk1 = GUINT32_TO_LE(2); header.file_size = GUINT32_TO_LE(size); header.unk2 = GUINT32_TO_LE(0); header.unk3 = GUINT32_TO_LE(0); base = g_malloc(len + 1); n = base; memcpy(n, &header, sizeof(MsnContextHeader)); n += sizeof(MsnContextHeader); memset(n, 0x00, MAX_FILE_NAME_LEN); for(currentChar = 0; currentChar < uni_len; currentChar++) { *((gunichar2 *)n + currentChar) = GUINT16_TO_LE(uni[currentChar]); } n += MAX_FILE_NAME_LEN; memset(n, 0xFF, 4); n += 4; g_free(uni); ret = purple_base64_encode(base, len); g_free(base); return ret; }
static gboolean valid_file (const gchar *filename) { struct stat buf; return g_stat (filename, &buf) == 0 && buf.st_size > 0; }
/* Returns: TRUE if FileRow value has been changed */ static gboolean update_file_size (FileRow *row, const gchar *complete_filename) { struct stat filestat; gboolean changed = TRUE; if (! g_stat (complete_filename, &filestat)) { if (row->size_value && (G_VALUE_TYPE (row->size_value) == G_TYPE_UINT) && (g_value_get_uint (row->size_value) == (guint)filestat.st_size)) changed = FALSE; else { if (row->size_value) gda_value_free (row->size_value); g_value_set_uint (row->size_value = gda_value_new (G_TYPE_UINT), filestat.st_size); } } else { if (row->size_value && gda_value_is_null (row->size_value)) changed = FALSE; else { if (row->size_value) gda_value_free (row->size_value); row->size_value = gda_value_new_null (); } } return changed; }
static JingleFT* _new(const gchar *name) { struct stat fileinfo; GError *err = NULL; gchar *filename = expand_filename(name); // expand ~ to HOME JingleFT *jft = g_new0(JingleFT, 1); jft->desc = g_strdup(name); jft->type = JINGLE_FT_OFFER; jft->name = g_path_get_basename(filename); jft->transmit = 0; jft->hash = NULL; jft->md5 = NULL; jft->state = JINGLE_FT_PENDING; jft->dir = JINGLE_FT_OUTGOING; jft->date = 0; jft->size = 0; // Add the jft to the list JingleFTInfo *jftinf = g_new0(JingleFTInfo, 1); jftinf->index = _next_index(); jftinf->jft = jft; info_list = g_slist_append(info_list, jftinf); if (g_stat(filename, &fileinfo) != 0) { scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: unable to stat %s", filename); jft->state = JINGLE_FT_ERROR; return NULL; } if (!S_ISREG(fileinfo.st_mode) || S_ISLNK(fileinfo.st_mode)) { scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: File doesn't exist!"); jft->state = JINGLE_FT_ERROR; return NULL; } jft->date = fileinfo.st_mtime; jft->size = fileinfo.st_size; jft->outfile = g_io_channel_new_file(filename, "r", &err); if (jft->outfile == NULL || err != NULL) { scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: %s %s", err->message, name); g_error_free(err); jft->state = JINGLE_FT_ERROR; return NULL; } g_io_channel_set_encoding(jft->outfile, NULL, &err); if (jft->outfile == NULL || err != NULL) { scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: %s %s", err->message, name); g_error_free(err); jft->state = JINGLE_FT_ERROR; return NULL; } return jft; }
static void send_file_cb(MsnSlpSession *slpsession) { MsnSlpCall *slpcall; MsnSlpMessage *slpmsg; struct stat st; PurpleXfer *xfer; slpcall = slpsession->slpcall; slpmsg = msn_slpmsg_new(slpcall->slplink); slpmsg->slpcall = slpcall; slpmsg->flags = 0x1000030; slpmsg->slpsession = slpsession; #ifdef MSN_DEBUG_SLP slpmsg->info = "SLP FILE"; #endif xfer = (PurpleXfer *)slpcall->xfer; purple_xfer_start(slpcall->xfer, 0, NULL, 0); slpmsg->fp = xfer->dest_fp; if (g_stat(purple_xfer_get_local_filename(xfer), &st) == 0) slpmsg->size = st.st_size; xfer->dest_fp = NULL; /* Disable double fclose() */ msn_slplink_send_slpmsg(slpcall->slplink, slpmsg); }
/* Determine if /etc/localtime is a hard link to some file, by looking at * the inodes */ static gchar * system_timezone_read_etc_localtime_hardlink (GHashTable *ical_zones) { struct stat stat_localtime; gchar *retval, *fallback = NULL; if (g_stat (ETC_LOCALTIME, &stat_localtime) != 0) return NULL; if (!S_ISREG (stat_localtime.st_mode)) return NULL; retval = recursive_compare ( &stat_localtime, NULL, 0, SYSTEM_ZONEINFODIR, files_are_identical_inode, ical_zones, 0, &fallback); if (retval) g_free (fallback); else retval = fallback; return retval; }
/** * gva_audit_detect_changes: * * Attempts to detect ROM and sample file changes since the last program * execution by scanning the timestamps on the directories listed in the * "rompath" and "samplepath" configuration values. It returns %TRUE if * any of those timestamps are more recent than the game database. * * Returns: %TRUE if changes were detected **/ gboolean gva_audit_detect_changes (void) { gboolean changes = FALSE; gchar **directories; struct stat st; guint length, ii; GError *error = NULL; if (g_stat (gva_db_get_filename (), &st) < 0) return FALSE; directories = gva_mame_get_search_paths ("rompath", &error); length = (directories != NULL) ? g_strv_length (directories) : 0; gva_error_handle (&error); for (ii = 0; ii < length; ii++) changes |= gva_db_is_older_than (directories[ii]); g_strfreev (directories); directories = gva_mame_get_search_paths ("samplepath", &error); length = (directories != NULL) ? g_strv_length (directories) : 0; gva_error_handle (&error); for (ii = 0; ii < length; ii++) changes |= gva_db_is_older_than (directories[ii]); g_strfreev (directories); return changes; }
gchar* prefs_get_config_filename (gchar *config_filename, GUI *appGUI) { static gchar dirname[PATH_MAX], filename[PATH_MAX]; struct stat cfg; if (appGUI->config_path == NULL) { #if defined(CONFIG_PATH) && defined(CONFIG_DIR) g_snprintf(dirname, PATH_MAX, "%s%c%s", CONFIG_PATH, G_DIR_SEPARATOR, CONFIG_DIR); #elif defined(CONFIG_DIR) g_snprintf(dirname, PATH_MAX, "%s%c%s", g_get_home_dir(), G_DIR_SEPARATOR, CONFIG_DIR); #elif defined(CONFIG_PATH) g_snprintf(dirname, PATH_MAX, "%s%c%s", CONFIG_PATH, G_DIR_SEPARATOR, CONFIG_DIRNAME); #else g_snprintf(dirname, PATH_MAX, "%s%c%s", g_get_home_dir(), G_DIR_SEPARATOR, CONFIG_DIRNAME); #endif } else { g_strlcpy (dirname, appGUI->config_path, PATH_MAX); } if(g_stat (dirname, &cfg) < 0) g_mkdir (dirname, S_IRUSR | S_IWUSR | S_IXUSR); if (g_access (dirname, R_OK | W_OK) == -1) { return NULL; } g_snprintf(filename, PATH_MAX, "%s%c%s", dirname, G_DIR_SEPARATOR, config_filename); return filename; }
static gchar * p_load_lastval_desc_file(const gchar *fname) { FILE *fp; gint32 file_size; GStatBuf stat_buf; gchar *file_buff; file_size = 0; file_buff = NULL; /* get filelength */ if (0 == g_stat(fname, &stat_buf)) { file_size = stat_buf.st_size; /* load File into Buffer */ file_buff = g_malloc0(file_size+1); fp = g_fopen(fname, "rb"); /* open read */ if(fp == NULL) { printf ("open(read) error on '%s'\n", fname); g_free(file_buff); } fread(file_buff, 1, file_size, fp); fclose(fp); } return (file_buff); } /* end p_load_lsatval_desc_file */
void _load_lang() { gchar *filename; XMLNode *node; struct stat buf; __languages_dict = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); filename = g_build_filename (ISOCODES_PREFIX, "share/xml/iso-codes/iso_639.xml", NULL); if (g_stat (filename, &buf) != 0) { g_warning ("Can not get stat of file %s", filename); g_free (filename); return; } node = ibus_xml_parse_file (filename); g_free (filename); if (!node) { return; } _iso_codes_parse_xml_node (node); ibus_xml_free (node); }
static gchar * mail_tool_get_local_movemail_path (CamelStore *store, GError **error) { const gchar *uid; guchar *safe_uid, *c; const gchar *data_dir; gchar *path, *full; struct stat st; uid = camel_service_get_uid (CAMEL_SERVICE (store)); safe_uid = (guchar *) g_strdup ((const gchar *) uid); for (c = safe_uid; *c; c++) if (strchr ("/:;=|%&#!*^()\\, ", *c) || !isprint ((gint) *c)) *c = '_'; data_dir = mail_session_get_data_dir (); path = g_build_filename (data_dir, "spool", NULL); if (g_stat (path, &st) == -1 && g_mkdir_with_parents (path, 0700) == -1) { g_set_error ( error, G_FILE_ERROR, g_file_error_from_errno (errno), _("Could not create spool directory '%s': %s"), path, g_strerror (errno)); g_free (path); return NULL; } full = g_strdup_printf ("%s/movemail.%s", path, safe_uid); g_free (path); g_free (safe_uid); return full; }
static void gimp_image_prop_view_label_set_filesize (GtkWidget *label, GimpImage *image) { gchar *filename = gimp_image_get_filename (image); if (filename) { struct stat buf; if (g_stat (filename, &buf) == 0) { gchar *str = g_format_size (buf.st_size); gtk_label_set_text (GTK_LABEL (label), str); g_free (str); } else { gtk_label_set_text (GTK_LABEL (label), NULL); } g_free (filename); } else { gtk_label_set_text (GTK_LABEL (label), NULL); } }
static int select_dirs (const struct dirent *dirent) { int result = 0; if (strcmp (dirent->d_name, ".") != 0 && strcmp (dirent->d_name, "..") != 0) { mode_t mode = 0; #ifdef _DIRENT_HAVE_D_TYPE if (dirent->d_type != DT_UNKNOWN && dirent->d_type != DT_LNK) { mode = DTTOIF (dirent->d_type); } else #endif { struct stat st; g_autofree char *path = NULL; path = g_build_filename (LIBLOCALEDIR, dirent->d_name, NULL); if (g_stat (path, &st) == 0) { mode = st.st_mode; } } result = S_ISDIR (mode); } return result; }
MimeInfo *tnef_parse_vcard(TNEFStruct tnef) { MimeInfo *sub_info = NULL; gchar *tmpfilename = NULL; FILE *fp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmpfilename); struct stat statbuf; gboolean result = FALSE; if (!fp) { g_free(tmpfilename); return NULL; } sub_info = procmime_mimeinfo_new(); sub_info->content = MIMECONTENT_FILE; sub_info->data.filename = tmpfilename; sub_info->type = MIMETYPE_TEXT; sub_info->subtype = g_strdup("x-vcard"); g_hash_table_insert(sub_info->typeparameters, g_strdup("filename"), g_strdup("contact.vcf")); result = SaveVCard(fp, tnef); fclose(fp); g_stat(tmpfilename, &statbuf); sub_info->tmp = TRUE; sub_info->length = statbuf.st_size; sub_info->encoding_type = ENC_BINARY; if (!result) { claws_unlink(tmpfilename); procmime_mimeinfo_free_all(sub_info); return tnef_broken_mimeinfo(_("Failed to parse VCard data.")); } return sub_info; }
static MimeInfo *tnef_broken_mimeinfo(const gchar *reason) { MimeInfo *sub_info = NULL; gchar *tmpfilename = NULL; FILE *fp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmpfilename); struct stat statbuf; if (!fp) { g_free(tmpfilename); return NULL; } sub_info = procmime_mimeinfo_new(); sub_info->content = MIMECONTENT_FILE; sub_info->data.filename = tmpfilename; sub_info->type = MIMETYPE_TEXT; sub_info->subtype = g_strdup("plain"); fprintf(fp, _("\n" "Claws Mail TNEF parser:\n\n" "%s\n"), reason?reason:_("Unknown error")); fclose(fp); g_stat(tmpfilename, &statbuf); sub_info->tmp = TRUE; sub_info->length = statbuf.st_size; sub_info->encoding_type = ENC_BINARY; return sub_info; }
void enchant_pwl_add(EnchantPWL *pwl, const char *const word, size_t len) { enchant_pwl_refresh_from_file(pwl); enchant_pwl_add_to_trie(pwl, word, len); if (pwl->filename != NULL) { FILE *f; f = enchant_fopen(pwl->filename, "a"); if (f) { struct stat stats; enchant_lock_file (f); if(g_stat(pwl->filename, &stats)==0) pwl->file_changed = stats.st_mtime; /* we write the new line first since we can't guarantee that the file was terminated by a new line before and we are just appending to the end of the file */ fwrite ("\n", sizeof(char), 1, f); fwrite (word, sizeof(char), len, f); enchant_unlock_file (f); fclose (f); } } }
gboolean mh_scan_required(Folder *folder, FolderItem *item) { gchar *path; struct stat s; path = folder_item_get_path(item); cm_return_val_if_fail(path != NULL, FALSE); if (g_stat(path, &s) < 0) { FILE_OP_ERROR(path, "stat"); g_free(path); return FALSE; } if ((s.st_mtime > item->mtime) && (s.st_mtime - 3600 != item->mtime)) { debug_print("MH scan required, folder updated: %s (%ld > %ld)\n", path?path:"(null)", (long int) s.st_mtime, (long int) item->mtime); g_free(path); return TRUE; } debug_print("MH scan not required: %s (%ld <= %ld)\n", path?path:"(null)", (long int) s.st_mtime, (long int) item->mtime); g_free(path); return FALSE; }
/** * g_lstat: * @filename: (type filename): a pathname in the GLib file name encoding * (UTF-8 on Windows) * @buf: a pointer to a stat struct, which will be filled with the file * information * * A wrapper for the POSIX lstat() function. The lstat() function is * like stat() except that in the case of symbolic links, it returns * information about the symbolic link itself and not the file that it * refers to. If the system does not support symbolic links g_lstat() * is identical to g_stat(). * * See your C library manual for more details about lstat(). * * Returns: 0 if the information was successfully retrieved, * -1 if an error occurred * * Since: 2.6 */ int g_lstat (const gchar *filename, GStatBuf *buf) { #ifdef HAVE_LSTAT /* This can't be Win32, so don't do the widechar dance. */ return lstat (filename, buf); #elif defined (G_OS_WIN32) GWin32PrivateStat w32_buf; int retval = g_win32_lstat_utf8 (filename, &w32_buf); buf->st_dev = w32_buf.st_dev; buf->st_ino = w32_buf.st_ino; buf->st_mode = w32_buf.st_mode; buf->st_nlink = w32_buf.st_nlink; buf->st_uid = w32_buf.st_uid; buf->st_gid = w32_buf.st_gid; buf->st_rdev = w32_buf.st_dev; buf->st_size = w32_buf.st_size; buf->st_atime = w32_buf.st_atime; buf->st_mtime = w32_buf.st_mtime; buf->st_ctime = w32_buf.st_ctime; return retval; #else return g_stat (filename, buf); #endif }
static gint check_mail() { static off_t oldsize = 0; gchar *filename; off_t newsize; struct stat s; gint ret = 0; filename = g_strdup(g_getenv("MAIL")); if (!filename) filename = g_strconcat("/var/spool/mail/", g_get_user_name(), NULL); if (g_stat(filename, &s) < 0) { g_free(filename); return -1; } newsize = s.st_size; if (newsize) ret |= ANY_MAIL; if (s.st_mtime > s.st_atime && newsize) ret |= UNREAD_MAIL; if (newsize != oldsize && (ret & UNREAD_MAIL)) ret |= NEW_MAIL; oldsize = newsize; g_free(filename); return ret; }
static char * mail_tool_get_local_movemail_path (const unsigned char *uri, CamelException *ex) { unsigned char *safe_uri, *c; char *path, *full; struct stat st; safe_uri = (unsigned char *)g_strdup ((const gchar *)uri); for (c = safe_uri; *c; c++) if (strchr("/:;=|%&#!*^()\\, ", *c) || !isprint((int) *c)) *c = '_'; path = g_strdup_printf("%s/spool", mail_component_peek_base_directory(NULL)); if (g_stat(path, &st) == -1 && g_mkdir_with_parents(path, 0777) == -1) { camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Could not create spool directory `%s': %s"), path, g_strerror(errno)); g_free(path); return NULL; } full = g_strdup_printf("%s/movemail.%s", path, safe_uri); g_free(path); g_free(safe_uri); return full; }
static void rotate_log (Gstreamill *gstreamill, gchar *log_path, pid_t pid) { GStatBuf st; gchar *name; glob_t pglob; gint i; g_stat (log_path, &st); if (st.st_size > LOG_SIZE) { name = g_strdup_printf ("%s-%lu", log_path, gst_clock_get_time (gstreamill->system_clock)); g_rename (log_path, name); g_free (name); GST_INFO ("log rotate %s, process pid %d.", log_path, pid); kill (pid, SIGUSR1); /* reopen log file. */ name = g_strdup_printf ("%s-*", log_path); glob (name, 0, NULL, &pglob); if (pglob.gl_pathc > LOG_ROTATE) { for (i = 0; i < pglob.gl_pathc - LOG_ROTATE; i++) { g_remove (pglob.gl_pathv[i]); } } globfree (&pglob); g_free (name); } }
static void import_kmail_exec (struct _import_mbox_msg *m, GCancellable *cancellable, GError **error) { GSList *list, *l; gchar *folder; struct stat st; if (g_stat (m->path, &st) == -1) { g_warning ( "cannot find source file to import '%s': %s", m->path, g_strerror (errno)); return; } if (!S_ISDIR (st.st_mode)) { g_warning ( "the source path '%s' is not a directory.", m->path); return; } list = kmail_get_folders (m->path); for (l = list; l; l = l->next) { folder = (gchar *) l->data; import_kmail_folder (m, folder, cancellable, NULL); } if (list) g_slist_free_full (list, g_free); }