Commit 97472f2 1 parent f2c3c50 commit 97472f2 Copy full SHA for 97472f2
File tree 3 files changed +27
-28
lines changed
3 files changed +27
-28
lines changed Original file line number Diff line number Diff line change @@ -176,35 +176,27 @@ xkb_compose_table_new_from_locale(struct xkb_context *ctx,
176
176
return NULL ;
177
177
178
178
path = get_xcomposefile_path (ctx );
179
- if (path && is_regular_file (path )) {
180
- file = fopen (path , "rb" );
181
- if (file )
182
- goto found_path ;
183
- }
179
+ file = open_regular_file (path );
180
+ if (file )
181
+ goto found_path ;
184
182
free (path );
185
183
186
184
path = get_xdg_xcompose_file_path (ctx );
187
- if (path && is_regular_file (path )) {
188
- file = fopen (path , "rb" );
189
- if (file )
190
- goto found_path ;
191
- }
185
+ file = open_regular_file (path );
186
+ if (file )
187
+ goto found_path ;
192
188
free (path );
193
189
194
190
path = get_home_xcompose_file_path (ctx );
195
- if (path && is_regular_file (path )) {
196
- file = fopen (path , "rb" );
197
- if (file )
198
- goto found_path ;
199
- }
191
+ file = open_regular_file (path );
192
+ if (file )
193
+ goto found_path ;
200
194
free (path );
201
195
202
196
path = get_locale_compose_file_path (ctx , table -> locale );
203
- if (path && is_regular_file (path )) {
204
- file = fopen (path , "rb" );
205
- if (file )
206
- goto found_path ;
207
- }
197
+ file = open_regular_file (path );
198
+ if (file )
199
+ goto found_path ;
208
200
free (path );
209
201
210
202
log_err (ctx , XKB_LOG_MESSAGE_NO_ID ,
Original file line number Diff line number Diff line change 24
24
#include "config.h"
25
25
26
26
#include <sys/stat.h>
27
+ #include <fcntl.h>
27
28
#include "utils.h"
28
29
29
30
#ifdef HAVE_MMAP
30
31
31
- #include <fcntl.h>
32
32
#include <unistd.h>
33
33
#include <sys/mman.h>
34
34
#include <sys/types.h>
@@ -111,14 +111,21 @@ unmap_file(char *str, size_t size)
111
111
112
112
#endif
113
113
114
- bool
115
- is_regular_file (const char * path )
114
+ FILE *
115
+ open_regular_file (const char * path )
116
116
{
117
+ if (!path ) return NULL ;
118
+
119
+ int fd = open (path , O_RDONLY );
117
120
struct stat stat_buf ;
118
- int err = stat (path , & stat_buf );
119
- if (err != 0 ) return false;
121
+ int err = fstat (fd , & stat_buf );
122
+
123
+ if (err != 0 || !S_ISREG (stat_buf .st_mode )) {
124
+ close (fd );
125
+ return NULL ;
126
+ }
120
127
121
- return S_ISREG ( stat_buf . st_mode );
128
+ return fdopen ( fd , "rb" );
122
129
}
123
130
124
131
// ASCII lower-case map.
Original file line number Diff line number Diff line change @@ -266,8 +266,8 @@ check_eaccess(const char *path, int mode)
266
266
return true;
267
267
}
268
268
269
- bool
270
- is_regular_file (const char * path );
269
+ FILE *
270
+ open_regular_file (const char * path );
271
271
272
272
#if defined(HAVE_SECURE_GETENV )
273
273
# define secure_getenv secure_getenv
You can’t perform that action at this time.
0 commit comments