Add unit(in variable) & fix bugs
[platform/core/system/resourced.git] / src / common / file-helper.h
1 /*
2  * resourced
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20
21 /*
22  * @file file-helper.h
23  * @desc Helper functions for working with files
24  */
25
26 #ifndef _RESOURCED_FILE_HELPER_H_
27 #define _RESOURCED_FILE_HELPER_H_
28
29 #include "resourced.h"
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif /* __cplusplus */
34
35 /**
36  * @desc write string to the file
37  * @param path - path to the file, str - string is written to the file
38  * @return negative value if error
39  */
40 int fwrite_str(const char *path, const char *str);
41
42 int fwrite_int(const char *path, const int number);
43
44 int fwrite_uint(const char *path, const u_int32_t number);
45
46 int fwrite_ulong(const char *path, const unsigned long number);
47 int fwrite_ulonglong(const char *path, const unsigned long long number);
48
49 int fread_str(const char *path, char **str);
50
51 int fread_nth_int(const char *path, size_t n, int32_t *number);
52
53 inline int fread_int(const char *path, int32_t *number)
54 {
55         return fread_nth_int(path, 0, number);
56 }
57
58 int fread_nth_uint(const char *path, size_t n, u_int32_t *number);
59
60 inline int fread_uint(const char *path, u_int32_t *number)
61 {
62         return fread_nth_uint(path, 0, number);
63 }
64
65 int fread_nth_ulong(const char *path, size_t n, unsigned long *number);
66 int fread_nth_ulonglong(const char *path, size_t n, unsigned long long *number);
67
68 inline int fread_ulong(const char *path, unsigned long *number)
69 {
70         return fread_nth_ulong(path, 0, number);
71 }
72
73 inline int fread_ulonglong(const char *path, unsigned long long *number)
74 {
75         return fread_nth_ulonglong(path, 0, number);
76 }
77
78 #ifdef __cplusplus
79 }
80 #endif /* __cplusplus */
81
82 #endif  /*_RESOURCED_FILE_HELPER_H_*/