aboutsummaryrefslogtreecommitdiff
path: root/modutils/modprobe-small.c
diff options
context:
space:
mode:
Diffstat (limited to 'modutils/modprobe-small.c')
-rw-r--r--modutils/modprobe-small.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c
index ed177bb9b..9c941064b 100644
--- a/modutils/modprobe-small.c
+++ b/modutils/modprobe-small.c
@@ -116,21 +116,21 @@ static char* copy_stringbuf(void)
116 116
117static char* find_keyword(char *ptr, size_t len, const char *word) 117static char* find_keyword(char *ptr, size_t len, const char *word)
118{ 118{
119 int wlen;
120
121 if (!ptr) /* happens if xmalloc_open_zipped_read_close cannot read it */ 119 if (!ptr) /* happens if xmalloc_open_zipped_read_close cannot read it */
122 return NULL; 120 return NULL;
123 121
124 wlen = strlen(word); 122 len -= strlen(word) - 1;
125 len -= wlen - 1;
126 while ((ssize_t)len > 0) { 123 while ((ssize_t)len > 0) {
127 char *old = ptr; 124 char *old = ptr;
125 char *after_word;
126
128 /* search for the first char in word */ 127 /* search for the first char in word */
129 ptr = memchr(ptr, *word, len); 128 ptr = memchr(ptr, word[0], len);
130 if (ptr == NULL) /* no occurance left, done */ 129 if (ptr == NULL) /* no occurance left, done */
131 break; 130 break;
132 if (strncmp(ptr, word, wlen) == 0) 131 after_word = is_prefixed_with(ptr, word);
133 return ptr + wlen; /* found, return ptr past it */ 132 if (after_word)
133 return after_word; /* found, return ptr past it */
134 ++ptr; 134 ++ptr;
135 len -= (ptr - old); 135 len -= (ptr - old);
136 } 136 }
@@ -536,7 +536,7 @@ static module_info** find_alias(const char *alias)
536// TODO: open only once, invent config_rewind() 536// TODO: open only once, invent config_rewind()
537static int already_loaded(const char *name) 537static int already_loaded(const char *name)
538{ 538{
539 int ret, namelen; 539 int ret;
540 char *line; 540 char *line;
541 FILE *fp; 541 FILE *fp;
542 542
@@ -545,15 +545,16 @@ static int already_loaded(const char *name)
545 fp = fopen_for_read("/proc/modules"); 545 fp = fopen_for_read("/proc/modules");
546 if (!fp) 546 if (!fp)
547 return 0; 547 return 0;
548 namelen = strlen(name);
549 while ((line = xmalloc_fgetline(fp)) != NULL) { 548 while ((line = xmalloc_fgetline(fp)) != NULL) {
550 char *live; 549 char *live;
550 char *after_name;
551 551
552 // Examples from kernel 3.14.6: 552 // Examples from kernel 3.14.6:
553 //pcspkr 12718 0 - Live 0xffffffffa017e000 553 //pcspkr 12718 0 - Live 0xffffffffa017e000
554 //snd_timer 28690 2 snd_seq,snd_pcm, Live 0xffffffffa025e000 554 //snd_timer 28690 2 snd_seq,snd_pcm, Live 0xffffffffa025e000
555 //i915 801405 2 - Live 0xffffffffa0096000 555 //i915 801405 2 - Live 0xffffffffa0096000
556 if (strncmp(line, name, namelen) != 0 || line[namelen] != ' ') { 556 after_name = is_prefixed_with(line, name);
557 if (!after_name || *after_name != ' ') {
557 free(line); 558 free(line);
558 continue; 559 continue;
559 } 560 }