Debian Codegraph @

lib/strutil.h

raw
1 /* dctrl-tools - Debian control file inspection tools
2 Copyright © 1999, 2003 Antti-Juhani Kaijanaho
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19
20 #ifndef STRUTIL_H__
21 #define STRUTIL_H__
22
23 #include <stddef.h>
24 #include <string.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27
28 /* Parse an integer from the (possibly not null-terminated) string s
29 * of length len, and place the result in *rvp. If return value is
30 * false, *rvp is untouched. */
31 bool str2intmax(intmax_t * rvp, char const * s, size_t len);
32
33 /* Return a pointer to first nonblank character in s. */
34 const char * left_trimmed(const char * s);
35
36 /* Mutate s and trim whitespace off its right end. */
37 void trim_right(char * s);
38
39 /* Remove a trailing newline, if any. */
40 void chomp(char *);
41
42 /* Chop off everything after and including the first comchar in line.
43 This mutates line! */
44 static inline void chop_comment(char * line, char comchar)
45 {
46 char * comstart;
47
48 comstart = strchr (line, comchar);
49
50 if (comstart != 0)
51 *comstart = 0;
52 }
53
54 #endif /* STRUTIL_H__ */