helper: taking the address is not a complicated variable
[smatch.git] / smatch_files.c
blob234f3a1694bf4191e9b44462733500baef686ae7
1 /*
2 * sparse/smatch_files.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include <string.h>
11 #include <fcntl.h>
12 #include <unistd.h>
13 #include "parse.h"
14 #include "smatch.h"
16 int open_data_file(const char *filename)
18 int fd;
19 char buf[256];
21 fd = open(filename, O_RDONLY);
22 if (fd >= 0)
23 goto exit;
24 if (!data_dir)
25 goto exit;
26 snprintf(buf, 256, "%s/%s", data_dir, filename);
27 fd = open(buf, O_RDONLY);
28 exit:
29 return fd;
32 struct token *get_tokens_file(const char *filename)
34 int fd;
35 struct token *token;
37 if (option_no_data)
38 return NULL;
39 fd = open_data_file(filename);
40 if (fd < 0)
41 return NULL;
42 token = tokenize(filename, fd, NULL, NULL);
43 close(fd);
44 return token;