summaryrefslogtreecommitdiffstats
path: root/isys
diff options
context:
space:
mode:
authorDavid Cantrell <dcantrell@redhat.com>2006-06-27 15:54:17 +0000
committerDavid Cantrell <dcantrell@redhat.com>2006-06-27 15:54:17 +0000
commit98ac162e07712108b59f7432466af6d9b18cc70a (patch)
tree558d786bef5d1277c2eba39b676d10a9e75a93f3 /isys
parent375d544fbcc7ff98ed4d44c30ddb79abf9858c5a (diff)
downloadanaconda-98ac162e07712108b59f7432466af6d9b18cc70a.tar.gz
anaconda-98ac162e07712108b59f7432466af6d9b18cc70a.tar.xz
anaconda-98ac162e07712108b59f7432466af6d9b18cc70a.zip
Hooray for 4th grade C programming class!
I had an idea that we could make loader smaller if we didn't call toupper() or string functions. Well, we use string functions all over the place, but I did remove the toupper() calls I used. Yeah, not exciting. Believe it or not, this was involved in a large tracking-down of double free()'s yesterday.
Diffstat (limited to 'isys')
-rw-r--r--isys/Makefile2
-rw-r--r--isys/nl.c11
-rw-r--r--isys/str.c49
-rw-r--r--isys/str.h19
4 files changed, 71 insertions, 10 deletions
diff --git a/isys/Makefile b/isys/Makefile
index 04b833c72..ed3be03af 100644
--- a/isys/Makefile
+++ b/isys/Makefile
@@ -5,7 +5,7 @@ CFLAGS += -I$(PYTHONINCLUDE) -I.. -DHAVE_NFS
OBJECTS = nfsmount.o nfsmount_clnt.o nfsmount_xdr.o imount.o \
smp.o devnodes.o cpio.o uncpio.o dasd.o \
lang.o isofs.o dns.o linkdetect.o vio.o \
- ethtool.o wireless.o eddsupport.o nl.o
+ ethtool.o wireless.o eddsupport.o nl.o str.o
SOBJECTS = $(patsubst %.o,%.lo,$(OBJECTS))
SOURCES = $(patsubst %.o,%.c,$(OBJECTS)) isys.c
LOADLIBES = -lresolv -lpci -lpopt -lext2fs -lz -lkudzu -lpci -ldevmapper
diff --git a/isys/nl.c b/isys/nl.c
index 68ce642fd..aacea534b 100644
--- a/isys/nl.c
+++ b/isys/nl.c
@@ -18,7 +18,6 @@
#include <errno.h>
#include <string.h>
#include <unistd.h>
-#include <ctype.h>
#include <sys/socket.h>
#include <sys/types.h>
@@ -30,6 +29,7 @@
#include <glib.h>
#include "nl.h"
+#include "str.h"
/* A linked list of interface_info_t structures (see nl.h) */
static GSList *interfaces = NULL;
@@ -43,8 +43,6 @@ static GSList *interfaces = NULL;
* @return Pointer to buf.
*/
char *netlink_format_mac_addr(char *buf, unsigned char *mac) {
- int i;
-
if (buf == NULL) {
if ((buf = malloc(20)) == NULL) {
perror("malloc in netlink_format_mac_addr");
@@ -55,12 +53,7 @@ char *netlink_format_mac_addr(char *buf, unsigned char *mac) {
sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
- for (i=0; i<18; i++) {
- if (buf[i] >= 'a' && buf[i] <= 'f')
- buf[i] = toupper(buf[i]);
- }
-
- return buf;
+ return str2upper(buf);
}
/**
diff --git a/isys/str.c b/isys/str.c
new file mode 100644
index 000000000..87f9d3c47
--- /dev/null
+++ b/isys/str.c
@@ -0,0 +1,49 @@
+/*
+ * str.c - String helper functions that don't need string.h or ctype.h
+ *
+ * Copyright 2006 Red Hat, Inc.
+ *
+ * David Cantrell <dcantrell@redhat.com>
+ *
+ * This software may be freely redistributed under the terms of the GNU
+ * general public license.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "str.h"
+
+/**
+ * Convert given string to uppercase. Modifies the argument in the caller's
+ * stack. If you must ask simply "why?" for this function, it's so we don't
+ * need toupper() and the same for loop all over the place.
+ *
+ * LIMITATIONS: Only deals with ASCII character set.
+ *
+ * @param str String to convert to uppercase.
+ * @return Pointer to str.
+ */
+char *str2upper(char *str) {
+ char *tmp;
+
+ if (str == NULL)
+ return NULL;
+
+ /* man ascii(7) */
+ tmp = str;
+ while (*tmp != '\0') {
+ if (*tmp >= 'a' && *tmp <= 'z')
+ *tmp -= 32;
+
+ tmp++;
+ }
+
+ return str;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4: */
diff --git a/isys/str.h b/isys/str.h
new file mode 100644
index 000000000..b5429a6a3
--- /dev/null
+++ b/isys/str.h
@@ -0,0 +1,19 @@
+/*
+ * str.c - String helper functions, the header file
+ *
+ * Copyright 2006 Red Hat, Inc.
+ *
+ * David Cantrell <dcantrell@redhat.com>
+ *
+ * This software may be freely redistributed under the terms of the GNU
+ * general public license.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/* Function prototypes */
+char *str2upper(char *str);
+
+/* vim:set shiftwidth=4 softtabstop=4: */