aboutsummaryrefslogtreecommitdiff
path: root/mail/vpopmail/files/patch-vutil.c
blob: be3ad66faaf3f5616f98aedfcca887ba01e1a2f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Description: Sanity and safety.
 Optimize a lot of calls by just using access(2).
 Fix a file descriptor and FILE structure leak.
Forwarded: no
Author: Peter Pentchev <roam@FreeBSD.org>
Last-Update: 2009-11-26

--- a/vutil.c
+++ b/vutil.c
@@ -76,13 +76,7 @@
   */
 
 int file_exists (char *filename) {
-    FILE *fs;
-    if( (fs=fopen(filename, "r")) !=NULL ) {
-        fclose(fs);
-        return 1;
-    } else {
-        return 0;
-    }
+    return(access(filename, R_OK) == 0);
 }
 
 //////////////////////////////////////////////////////////////////////
@@ -100,24 +94,15 @@
 {
     FILE *fs = NULL;
     char FileName[MAX_BUFF];
-    int result = 0;
     char TmpBuf2[MAX_BUFF];
 
     snprintf( FileName, MAX_BUFF, "%s/.qmail-%s", path, Name );
-    if ( (fs=fopen(FileName,"r"))==NULL) {
-//        printf( "   Unable to open list file: %s\n", Name );
-    }
-
-    else {
-        fgets( TmpBuf2, sizeof(TmpBuf2), fs);
-        if ( strstr( TmpBuf2, "ezmlm-reject") != 0 ||
-             strstr( TmpBuf2, "ezmlm-send")   != 0 ) {
-            result = 1;
-        }
-        fclose(fs);
-    }
-
-    return result;
+    if ( (fs=fopen(FileName,"r"))==NULL)
+        return(0);
+    fgets( TmpBuf2, sizeof(TmpBuf2), fs);
+    fclose(fs);
+    return ( strstr( TmpBuf2, "ezmlm-reject") != 0 ||
+        strstr( TmpBuf2, "ezmlm-send")   != 0 );
 }