summaryrefslogtreecommitdiff
path: root/namedev_parse.c
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2004-03-22 22:22:20 -0800
committerGreg KH <gregkh@suse.de>2005-04-26 21:35:10 -0700
commitc81b35c08bbd7789883993ea280e0d3772cce440 (patch)
tree7be4ba86d74284bc49f7317f75a23d59db0e45cd /namedev_parse.c
parentc58286656e8bd4285e35a1cf12906416dd259aab (diff)
[PATCH] replace fgets() with mmap() and introduce udev_lib.[hc]
Here we replace the various fgets() with a mmap() call for the config file reading, due to the reported performance problems with klibc. Thanks to Patrick's testing, it makes a very small, close to nothing speed gain for libc users, but a 6 times speed increase for klibc users with a 1000 line config file. I've created a udev_lib.[hc] for this and also moved all the generic stuff from udev.h in there and uninlined the functions.
Diffstat (limited to 'namedev_parse.c')
-rw-r--r--namedev_parse.c56
1 files changed, 37 insertions, 19 deletions
diff --git a/namedev_parse.c b/namedev_parse.c
index 8198f7e684..f4ffdb21d6 100644
--- a/namedev_parse.c
+++ b/namedev_parse.c
@@ -30,7 +30,6 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include <fcntl.h>
#include <ctype.h>
#include <unistd.h>
#include <sys/stat.h>
@@ -38,6 +37,7 @@
#include <errno.h>
#include "udev.h"
+#include "udev_lib.h"
#include "logging.h"
#include "namedev.h"
@@ -153,27 +153,36 @@ static int namedev_parse_rules(char *filename)
char *temp2;
char *temp3;
char *attr;
- FILE *fd;
+ char *buf;
+ size_t bufsize;
+ size_t cur;
+ size_t count;
int program_given = 0;
int retval = 0;
struct config_device dev;
- fd = fopen(filename, "r");
- if (fd != NULL) {
+ if (file_map(filename, &buf, &bufsize) == 0) {
dbg("reading '%s' as rules file", filename);
} else {
- dbg("can't open '%s' as a rules file", filename);
- return -ENODEV;
+ dbg("can't open '%s' as rules file", filename);
+ return -1;
}
/* loop through the whole file */
+ cur = 0;
lineno = 0;
while (1) {
- /* get a line */
- temp = fgets(line, sizeof(line), fd);
- if (temp == NULL)
- goto exit;
+ count = buf_get_line(buf, bufsize, cur);
+
+ strncpy(line, buf + cur, count);
+ line[count] = '\0';
+ temp = line;
lineno++;
+
+ cur += count+1;
+ if (cur > bufsize)
+ break;
+
dbg_parse("read '%s'", temp);
/* eat the whitespace */
@@ -311,8 +320,8 @@ error:
filename, lineno, temp - line);
}
}
-exit:
- fclose(fd);
+
+ file_unmap(buf, bufsize);
return retval;
}
@@ -321,22 +330,31 @@ static int namedev_parse_permissions(char *filename)
char line[255];
char *temp;
char *temp2;
- FILE *fd;
+ char *buf;
+ size_t bufsize;
+ size_t cur;
+ size_t count;
int retval = 0;
struct perm_device dev;
- fd = fopen(filename, "r");
- if (fd != NULL) {
+ if (file_map(filename, &buf, &bufsize) == 0) {
dbg("reading '%s' as permissions file", filename);
} else {
dbg("can't open '%s' as permissions file", filename);
- return -ENODEV;
+ return -1;
}
/* loop through the whole file */
+ cur = 0;
while (1) {
- temp = fgets(line, sizeof(line), fd);
- if (temp == NULL)
+ count = buf_get_line(buf, bufsize, cur);
+
+ strncpy(line, buf + cur, count);
+ line[count] = '\0';
+ temp = line;
+
+ cur += count+1;
+ if (cur > bufsize)
break;
dbg_parse("read '%s'", temp);
@@ -394,7 +412,7 @@ static int namedev_parse_permissions(char *filename)
}
exit:
- fclose(fd);
+ file_unmap(buf, bufsize);
return retval;
}