( cvs diff -u -r 1.1.4.50 -r 1.1.4.51 src/prefs_filtering_action.c; cvs diff -u -r 1.43.2.72 -r 1.43.2.73 src/prefs_matcher.c; cvs diff -u -r 1.1.2.6 -r 1.1.2.7 src/common/tags.c; cvs diff -u -r 1.1.2.3 -r 1.1.2.4 src/common/tags.h; cvs diff -u -r 1.1.2.12 -r 1.1.2.13 src/gtk/combobox.c; cvs diff -u -r 1.1.2.10 -r 1.1.2.11 src/gtk/combobox.h; ) > 3.4.0cvs54.patchset
( cvs diff -u -r 1.1.2.50 -r 1.1.2.51 src/plugins/pgpcore/sgpgme.c; ) > 3.4.0cvs55.patchset
( cvs diff -u -r 1.179.2.220 -r 1.179.2.221 src/imap.c; ) > 3.4.0cvs56.patchset
+( cvs diff -u -r 1.36.2.139 -r 1.36.2.140 src/common/utils.c; ) > 3.4.0cvs57.patchset
#include <sys/utsname.h>
#endif
+#include <fcntl.h>
+
#ifdef G_OS_WIN32
# include <direct.h>
# include <io.h>
-# include <fcntl.h>
# include <w32lib.h>
#endif
{
FILE *fp;
gchar *str;
+ struct stat s;
+ gint fd, err;
+ struct timeval timeout = {1, 0};
+ fd_set fds;
+ int fflags = 0;
g_return_val_if_fail(file != NULL, NULL);
- if ((fp = g_fopen(file, "rb")) == NULL) {
- FILE_OP_ERROR(file, "fopen");
+ if (g_stat(file, &s) != 0) {
+ FILE_OP_ERROR(file, "stat");
+ return NULL;
+ }
+ if (S_ISDIR(s.st_mode)) {
+ g_warning("%s: is a directory\n", file);
+ return NULL;
+ }
+
+ /* test whether the file is readable without blocking */
+ fd = open(file, O_RDONLY | O_NONBLOCK);
+ if (fd == -1) {
+ FILE_OP_ERROR(file, "open");
+ return NULL;
+ }
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+
+ /* allow for one second */
+ err = select(fd+1, &fds, NULL, NULL, &timeout);
+ if (err <= 0 || !FD_ISSET(fd, &fds)) {
+ if (err < 0) {
+ FILE_OP_ERROR(file, "select");
+ } else {
+ g_warning("%s: doesn't seem readable\n", file);
+ }
+ close(fd);
+ return NULL;
+ }
+
+ /* Now clear O_NONBLOCK */
+ if ((fflags = fcntl(fd, F_GETFL)) < 0) {
+ FILE_OP_ERROR(file, "fcntl (F_GETFL)");
+ close(fd);
+ return NULL;
+ }
+ if (fcntl(fd, F_SETFL, (fflags & ~O_NONBLOCK)) < 0) {
+ FILE_OP_ERROR(file, "fcntl (F_SETFL)");
+ close(fd);
+ return NULL;
+ }
+
+ /* get the FILE pointer */
+ fp = fdopen(fd, "rb");
+
+ if (fp == NULL) {
+ FILE_OP_ERROR(file, "fdopen");
+ close(fd); /* if fp isn't NULL, we'll use fclose instead! */
return NULL;
}