Debian Codegraph @

runtime/srUtils.h

raw
1 /*! \file srUtils.h
2 * \brief General, small utilities that fit nowhere else.
3 *
4 * \author Rainer Gerhards <[email protected]>
5 * \date 2003-09-09
6 * Coding begun.
7 *
8 * Copyright 2003-2018 Rainer Gerhards and Adiscon GmbH.
9 *
10 * This file is part of the rsyslog runtime library.
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 * -or-
18 * see COPYING.ASL20 in the source distribution
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS,
22 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
25 */
26 #ifndef __SRUTILS_H_INCLUDED__
27 #define __SRUTILS_H_INCLUDED__ 1
28
29 #include <stdlib.h>
30 #include <stdint.h>
31
32 /* syslog names */
33 #ifndef LOG_MAKEPRI
34 #define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
35 #endif
36 #define INTERNAL_NOPRI 0x10 /* the "no priority" priority */
37 #define TABLE_NOPRI 0 /* Value to indicate no priority in f_pmask */
38 #define TABLE_ALLPRI 0xFF /* Value to indicate all priorities in f_pmask */
39 #define LOG_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) /* mark "facility" */
40
41 typedef struct syslogName_s {
42 const char *c_name;
43 int c_val;
44 } syslogName_t;
45
46 extern syslogName_t syslogPriNames[];
47 extern syslogName_t syslogFacNames[];
48
49 /**
50 * A reimplementation of itoa(), as this is not available
51 * on all platforms. We used the chance to make an interface
52 * that fits us well, so it is no longer plain itoa().
53 *
54 * This method works with the US-ASCII alphabet. If you port this
55 * to e.g. EBCDIC, you need to make a small adjustment. Keep in mind,
56 * that on the wire it MUST be US-ASCII, so basically all you need
57 * to do is replace the constant '0' with 0x30 ;).
58 *
59 * \param pBuf Caller-provided buffer that will receive the
60 * generated ASCII string.
61 *
62 * \param iLenBuf Length of the caller-provided buffer.
63 *
64 * \param iToConv The integer to be converted.
65 */
66 rsRetVal srUtilItoA(char *pBuf, int iLenBuf, number_t iToConv);
67
68 /**
69 * A method to duplicate a string for which the length is known.
70 * Len must be the length in characters WITHOUT the trailing
71 * '\0' byte.
72 * rgerhards, 2007-07-10
73 */
74 unsigned char *srUtilStrDup(unsigned char *pOld, size_t len);
75 /**
76 * A method to create a directory and all its missing parents for
77 * a given file name. Please not that the rightmost element is
78 * considered to be a file name and thus NO directory is being created
79 * for it.
80 * added 2007-07-17 by rgerhards
81 */
82 int makeFileParentDirs(const uchar *const szFile,
83 const size_t lenFile,
84 const mode_t mode,
85 const uid_t uid,
86 const gid_t gid,
87 const int bFailOnChown);
88 int execProg(uchar *program, int bWait, uchar *arg1, uchar *arg2);
89 void skipWhiteSpace(uchar **pp);
90 rsRetVal genFileName(
91 uchar **ppName, uchar *pDirName, size_t lenDirName, uchar *pFName, size_t lenFName, int64_t lNum, int lNumDigits);
92 int getNumberDigits(long lNum);
93 rsRetVal timeoutComp(struct timespec *pt, long iTimeout);
94 long timeoutVal(struct timespec *pt);
95 void mutexCancelCleanup(void *arg);
96 void srSleep(int iSeconds, int iuSeconds);
97 char *rs_strerror_r(int errnum, char *buf, size_t buflen);
98 int decodeSyslogName(uchar *name, syslogName_t *codetab);
99 int getSubString(uchar **ppSrc, char *pDst, size_t DstSize, char cSep);
100 rsRetVal getFileSize(uchar *pszName, off_t *pSize);
101 int containsGlobWildcard(char *str);
102 void seedRandomNumber(void);
103 void seedRandomNumberForChild(void);
104 #define MAX_RANDOM_NUMBER RAND_MAX
105 long int randomNumber(void);
106 long long currentTimeMills(void);
107 rsRetVal ATTR_NONNULL() split_binary_parameters(uchar **const szBinary,
108 char ***const aParams,
109 int *const iParams,
110 es_str_t *const param_binary);
111
112 #endif /* #ifndef __SRUTILS_H_INCLUDED__ */