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_seqnum(void)
60 seqnum = getenv("SEQNUM");
65 char *get_subsystem(char *subsystem)
67 if (subsystem != NULL && strlen(subsystem) > SUBSYSTEM_SIZE)
68 subsystem[SUBSYSTEM_SIZE-1] = '\0';
73 int file_map(const char *filename, char **buf, size_t *bufsize)
78 fd = open(filename, O_RDONLY);
83 if (fstat(fd, &stats) < 0) {
87 *buf = mmap(NULL, stats.st_size, PROT_READ, MAP_SHARED, fd, 0);
88 if (*buf == MAP_FAILED) {
91 *bufsize = stats.st_size;
98 void file_unmap(char *buf, size_t bufsize)
100 munmap(buf, bufsize);
103 size_t buf_get_line(char *buf, size_t buflen, size_t cur)
107 for (count = cur; count < buflen && buf[count] != '\n'; count++);