2 * udev_lib - generic stuff used by udev
4 * Copyright (C) 2004 Kay Sievers <kay@vrfy.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include "libsysfs/sysfs/libsysfs.h"
34 char *get_action(void)
38 action = getenv("ACTION");
39 if (action != NULL && strlen(action) > ACTION_SIZE)
40 action[ACTION_SIZE-1] = '\0';
45 char *get_devpath(void)
49 devpath = getenv("DEVPATH");
50 if (devpath != NULL && strlen(devpath) > DEVPATH_SIZE)
51 devpath[DEVPATH_SIZE-1] = '\0';
56 char *get_devnode(void)
60 devnode = getenv("DEVNODE");
61 if (devnode != NULL && strlen(devnode) > NAME_SIZE)
62 devnode[NAME_SIZE-1] = '\0';
67 char *get_seqnum(void)
71 seqnum = getenv("SEQNUM");
76 char *get_subsystem(char *subsystem)
78 if (subsystem != NULL && strlen(subsystem) > SUBSYSTEM_SIZE)
79 subsystem[SUBSYSTEM_SIZE-1] = '\0';
84 int file_map(const char *filename, char **buf, size_t *bufsize)
89 fd = open(filename, O_RDONLY);
94 if (fstat(fd, &stats) < 0) {
98 *buf = mmap(NULL, stats.st_size, PROT_READ, MAP_SHARED, fd, 0);
99 if (*buf == MAP_FAILED) {
102 *bufsize = stats.st_size;
109 void file_unmap(char *buf, size_t bufsize)
111 munmap(buf, bufsize);
114 size_t buf_get_line(char *buf, size_t buflen, size_t cur)
118 for (count = cur; count < buflen && buf[count] != '\n'; count++);