Save function lists in smatch_data/
[smatch.git] / smatch_files.c
blobd26d316108fe60c3a21be5813a540d143fceb860
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 static int open_file(const char *filename)
18 int fd;
19 char *buf = malloc(256);
21 fd = open(filename, O_RDONLY);
22 if (fd >= 0)
23 goto exit;
24 strncpy(buf, bin_dir, 254);
25 buf[255] = '\0';
26 strncat(buf, "/smatch_data/", 254);
27 strncat(buf, filename, 254);
28 fd = open(buf, O_RDONLY);
29 if (fd >= 0)
30 goto exit;
32 exit:
33 free(buf);
34 return fd;
37 struct token *get_tokens_file(const char *filename)
39 int fd;
40 struct token *token;
42 fd = open_file(filename);
43 if (fd < 0)
44 return NULL;
45 token = tokenize(filename, fd, NULL, NULL);
46 close(fd);
47 return token;