summaryrefslogtreecommitdiff
path: root/src/parser.c
blob: 49d4deb2a19f614695ed4d9c5f110137927ee43a (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
 /*
  * Copyright 2012  Samsung Electronics Co., Ltd
  *
  * Licensed under the Flora License, Version 1.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.tizenopensource.org/license
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */



#include <ctype.h>
#include <Elementary.h>
#include <fcntl.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>

#include "parser.h"
#include "util.h"



static inline char *_ltrim(char *str)
{
	retv_if(NULL == str, NULL);
	while (*str && (*str == ' ' || *str == '\t' || *str == '\n')) str ++;
	return str;
}



static inline int _rtrim(char *str)
{
	int len;

	retv_if(NULL == str, 0);

	len = strlen(str);
	while (--len >= 0 && (str[len] == ' ' || str[len] == '\n' || str[len] == '\t')) {
		str[len] = '\0';
	}

	return len;
}



int conf_search(struct inotify_path* paths, int number)
{
	char *line = NULL;
	FILE *fp;
	size_t size = 0;
	ssize_t read;
	int i = 0;

	fp = fopen(CONF_FILE, "r");
	if (NULL == fp) {
		_E(CONF_FILE);
		return -EFAULT;
	}

	while ((read = getline(&line, &size, fp)) != -1 && i < CONF_PATH_NUMBER - 1) {
		char *begin;

		if (size <= 0) break;

		begin = _ltrim(line);
		_rtrim(line);

		if (*begin == '#' || *begin == '\0') continue;

		paths[i].path = strdup(begin);
		i++;
	}

	if (line) free(line);
	paths[i].path = NULL;
	fclose(fp);

	return EXIT_SUCCESS;
}
// END