]> git.ipfire.org Git - thirdparty/systemd.git/blame - udev_lib.h
[PATCH] add a "first" list to udevstart and make it contain the class/mem/ devices
[thirdparty/systemd.git] / udev_lib.h
CommitLineData
c81b35c0
KS
1/*
2 * udev_lib - generic stuff used by udev
3 *
4 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 */
21
22#ifndef _UDEV_LIB_H_
23#define _UDEV_LIB_H_
24
25
26#define strfieldcpy(to, from) \
27do { \
28 to[sizeof(to)-1] = '\0'; \
29 strncpy(to, from, sizeof(to)-1); \
30} while (0)
31
32#define strfieldcat(to, from) \
33do { \
34 to[sizeof(to)-1] = '\0'; \
35 strncat(to, from, sizeof(to) - strlen(to)-1); \
36} while (0)
37
38#define strfieldcpymax(to, from, maxsize) \
39do { \
40 to[maxsize-1] = '\0'; \
41 strncpy(to, from, maxsize-1); \
42} while (0)
43
44#define strfieldcatmax(to, from, maxsize) \
45do { \
46 to[maxsize-1] = '\0'; \
47 strncat(to, from, maxsize - strlen(to)-1); \
48} while (0)
49
50#define strintcat(to, i) \
51do { \
52 to[sizeof(to)-1] = '\0'; \
53 snprintf((to) + strlen(to), sizeof(to) - strlen(to)-1, "%u", i); \
54} while (0)
55
56#define strintcatmax(to, i, maxsize) \
57do { \
58 to[maxsize-1] = '\0'; \
59 snprintf((to) + strlen(to), maxsize - strlen(to)-1, "%u", i); \
60} while (0)
61
3169e8d1
KS
62#define strlongcat(to, i) \
63do { \
64 to[sizeof(to)-1] = '\0'; \
65 snprintf((to) + strlen(to), sizeof(to) - strlen(to)-1, "%li", i); \
66} while (0)
67
c81b35c0
KS
68#define foreach_strpart(str, separator, pos, len) \
69 for(pos = str, len = 0; \
70 (pos) < ((str) + strlen(str)); \
71 pos = pos + len + strspn(pos, separator), len = strcspn(pos, separator)) \
72 if (len > 0)
73
74
75extern char *get_action(void);
76extern char *get_devpath(void);
4b06c852 77extern char *get_devname(void);
c81b35c0
KS
78extern char *get_seqnum(void);
79extern char *get_subsystem(char *subsystem);
f61d732a 80extern char get_device_type(const char *path, const char *subsystem);
c81b35c0
KS
81extern int file_map(const char *filename, char **buf, size_t *bufsize);
82extern void file_unmap(char *buf, size_t bufsize);
83extern size_t buf_get_line(char *buf, size_t buflen, size_t cur);
aef6bb13
KS
84extern void leading_slash(char *path);
85extern void no_leading_slash(char *path);
4a539daf 86extern int call_foreach_file(int fnct(char *f) , char *filename, char *extension);
c81b35c0
KS
87
88
89#endif